|
@@ -1,7 +1,12 @@
|
|
package org.jeecg.modules.adweb.dmp.vo.report;
|
|
package org.jeecg.modules.adweb.dmp.vo.report;
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.annotation.JsonIgnore;
|
|
|
|
+
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
|
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
+import org.jeecg.modules.adweb.common.util.NumberUtil;
|
|
|
|
+
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -12,22 +17,25 @@ import java.util.List;
|
|
@Data
|
|
@Data
|
|
public class SiteOverviewStatsVO {
|
|
public class SiteOverviewStatsVO {
|
|
|
|
|
|
- private int totalUsers;
|
|
|
|
|
|
+ // 加和数据
|
|
|
|
+ private int totalUsers; // 总访客数 UV
|
|
|
|
+
|
|
|
|
+ private int sessions; // 总会话数
|
|
|
|
|
|
- private int pageViews;
|
|
|
|
|
|
+ private int pageViews; // 总浏览量 PV
|
|
|
|
|
|
- private int enquires;
|
|
|
|
|
|
+ private int enquires; // 总询盘数
|
|
|
|
|
|
- // 计算统计数据
|
|
|
|
- private double dailyPageViews;
|
|
|
|
|
|
+ // 计算数据
|
|
|
|
+ private String dailyTotalUsers; // 日均访问量
|
|
|
|
|
|
- private int avgTimeOnPage;
|
|
|
|
|
|
+ private String avgTimeOnPage; // 平均访问时长
|
|
|
|
|
|
- private double pageViewsPerSession;
|
|
|
|
|
|
+ private String pageViewsPerSession; // 平均访问页面数
|
|
|
|
|
|
- private String bounceRate;
|
|
|
|
|
|
+ private String bounceRate; // 跳出率
|
|
|
|
|
|
- private String enquiryConversionRate;
|
|
|
|
|
|
+ private String enquiryConversionRate; // UV到询盘转化率
|
|
|
|
|
|
private List<DailyStatsVO> dailyStats;
|
|
private List<DailyStatsVO> dailyStats;
|
|
|
|
|
|
@@ -38,8 +46,74 @@ public class SiteOverviewStatsVO {
|
|
|
|
|
|
private int totalUsers;
|
|
private int totalUsers;
|
|
|
|
|
|
- private int pageViews;
|
|
|
|
|
|
+ @JsonIgnore private int sessions;
|
|
|
|
+
|
|
|
|
+ @JsonIgnore private double bounceRate;
|
|
|
|
+
|
|
|
|
+ @JsonIgnore private double avgSessionDuration;
|
|
|
|
+
|
|
|
|
+ @JsonIgnore private int pageViews;
|
|
|
|
+
|
|
|
|
+ @JsonIgnore private double pageViewsPerSession;
|
|
|
|
|
|
private int enquires;
|
|
private int enquires;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public static SiteOverviewStatsVO fromDailyStats(List<DailyStatsVO> dailyStatsVOs) {
|
|
|
|
+ if (CollectionUtils.isEmpty(dailyStatsVOs)) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ SiteOverviewStatsVO siteOverviewStatsVO = new SiteOverviewStatsVO();
|
|
|
|
+ // 1. 加和数据
|
|
|
|
+ int totalUsers = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getTotalUsers).sum();
|
|
|
|
+ int sessions = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getSessions).sum();
|
|
|
|
+ int pageViews = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getPageViews).sum();
|
|
|
|
+ int enquires = dailyStatsVOs.stream().mapToInt(DailyStatsVO::getEnquires).sum();
|
|
|
|
+
|
|
|
|
+ siteOverviewStatsVO.setTotalUsers(totalUsers);
|
|
|
|
+ siteOverviewStatsVO.setSessions(sessions);
|
|
|
|
+ siteOverviewStatsVO.setPageViews(pageViews);
|
|
|
|
+ siteOverviewStatsVO.setEnquires(enquires);
|
|
|
|
+
|
|
|
|
+ // 2. 计算数据
|
|
|
|
+ int numDays = dailyStatsVOs.size();
|
|
|
|
+
|
|
|
|
+ // 2.1 日均访问量
|
|
|
|
+ siteOverviewStatsVO.setDailyTotalUsers(
|
|
|
|
+ NumberUtil.formatDecimal(totalUsers / numDays, 2).toPlainString());
|
|
|
|
+
|
|
|
|
+ // 2.2 平均访问时长
|
|
|
|
+ // -- SUM (avgSessionDuration * sessions)
|
|
|
|
+ double durationSum =
|
|
|
|
+ dailyStatsVOs.stream()
|
|
|
|
+ .mapToDouble(
|
|
|
|
+ dailyStatsVO ->
|
|
|
|
+ dailyStatsVO.getAvgSessionDuration()
|
|
|
|
+ * dailyStatsVO.getSessions())
|
|
|
|
+ .sum();
|
|
|
|
+ siteOverviewStatsVO.setAvgTimeOnPage(
|
|
|
|
+ NumberUtil.formatDecimal(sessions == 0 ? 0 : durationSum / sessions, 2)
|
|
|
|
+ .toPlainString()
|
|
|
|
+ + "s"); // 后端返回秒单位
|
|
|
|
+
|
|
|
|
+ // 2.3 平均访问页面数
|
|
|
|
+ siteOverviewStatsVO.setPageViewsPerSession(
|
|
|
|
+ NumberUtil.formatDecimal(sessions == 0 ? 0 : pageViews / sessions, 2)
|
|
|
|
+ .toPlainString());
|
|
|
|
+
|
|
|
|
+ // 2.4 跳出率
|
|
|
|
+ // -- SUM (avgSessionDuration * sessions)
|
|
|
|
+ double bounceRateSum =
|
|
|
|
+ dailyStatsVOs.stream().mapToDouble(DailyStatsVO::getBounceRate).sum();
|
|
|
|
+ siteOverviewStatsVO.setBounceRate(NumberUtil.formatPercentage(bounceRateSum / numDays, 2));
|
|
|
|
+
|
|
|
|
+ // 2.5 UV到询盘转化率
|
|
|
|
+ siteOverviewStatsVO.setEnquiryConversionRate(
|
|
|
|
+ NumberUtil.formatPercentage(totalUsers == 0 ? 0 : enquires / totalUsers, 2));
|
|
|
|
+
|
|
|
|
+ siteOverviewStatsVO.setDailyStats(dailyStatsVOs);
|
|
|
|
+
|
|
|
|
+ return siteOverviewStatsVO;
|
|
|
|
+ }
|
|
}
|
|
}
|