|
@@ -3,13 +3,11 @@ package com.tzld.longarticle.recommend.server.service;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ctrip.framework.apollo.spring.annotation.ApolloJsonValue;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.tzld.longarticle.recommend.server.common.enums.AccountBusinessTypeEnum;
|
|
|
-import com.tzld.longarticle.recommend.server.model.MiniprogramTaskParam;
|
|
|
-import com.tzld.longarticle.recommend.server.model.NewSortStrategyExport;
|
|
|
-import com.tzld.longarticle.recommend.server.model.ProduceAuditLayoutContentObjVO;
|
|
|
-import com.tzld.longarticle.recommend.server.model.PublishContentParam;
|
|
|
+import com.tzld.longarticle.recommend.server.model.*;
|
|
|
import com.tzld.longarticle.recommend.server.repository.aigc.*;
|
|
|
import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
|
|
|
import com.tzld.longarticle.recommend.server.repository.crawler.ArticleDetailInfoRepository;
|
|
@@ -445,7 +443,7 @@ public class DataDashboardService {
|
|
|
HttpEntity<Object> queryEntity = new HttpEntity<>(httpHeaders);
|
|
|
ResponseEntity<String> queryResponseEntity = restTemplate.exchange(
|
|
|
String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values/%s!A"
|
|
|
- + startRowIndex + ":A" + (startRowIndex + (rowNum * 2)), sheetToken, sheetId),
|
|
|
+ + startRowIndex + ":A" + (startRowIndex + (rowNum * 2)), sheetToken, sheetId),
|
|
|
HttpMethod.GET, queryEntity, String.class);
|
|
|
JSONArray values = JSON.parseObject(queryResponseEntity.getBody())
|
|
|
.getJSONObject("data")
|
|
@@ -493,11 +491,11 @@ public class DataDashboardService {
|
|
|
.builder()
|
|
|
.put("valueRange", MapBuilder
|
|
|
.builder()
|
|
|
- .put("range", String.format("%s!A" + startRow + ":AZ", sheetId) + (partition.size() + startRow - 1))
|
|
|
+ .put("range", String.format("%s!A" + startRow + ":CH", sheetId) + (partition.size() + startRow - 1))
|
|
|
.put("values", partition)
|
|
|
.build())
|
|
|
.build(), httpHeaders);
|
|
|
- restTemplate.exchange(String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values_prepend",
|
|
|
+ ResponseEntity<String> response = restTemplate.exchange(String.format("https://open.feishu.cn/open-apis/sheets/v2/spreadsheets/%s/values_prepend",
|
|
|
sheetToken),
|
|
|
HttpMethod.POST, postEntity, String.class);
|
|
|
startRow += partition.size();
|
|
@@ -553,4 +551,447 @@ public class DataDashboardService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Scheduled(cron = "0 0 4 * * ?")
|
|
|
+ public void scheduleIntermediateIndicatorsExport() {
|
|
|
+ List<String> dateStrList = DateUtils.getBeforeDays(null, 3);
|
|
|
+ for (String date : dateStrList) {
|
|
|
+ exportFeishuIntermediateIndicators(date, sheetToken, "OuaLWV");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void intermediateIndicatorsExport(String dateStr) {
|
|
|
+ List<String> dateStrList = DateUtils.getBeforeDays(dateStr, 3);
|
|
|
+ for (String date : dateStrList) {
|
|
|
+ exportFeishuIntermediateIndicators(date, sheetToken, "OuaLWV");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void exportFeishuIntermediateIndicators(String dateStr, String sheetToken, String sheetId) {
|
|
|
+ List<IntermediateIndicatorsExport> newContentsYesData = intermediateIndicatorsData(dateStr);
|
|
|
+ if (CollectionUtil.isEmpty(newContentsYesData)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int rowNum = newContentsYesData.size();
|
|
|
+ List<List<Object>> rows = new ArrayList<>();
|
|
|
+ Field[] fields = IntermediateIndicatorsExport.class.getDeclaredFields();
|
|
|
+ for (IntermediateIndicatorsExport datum : newContentsYesData) {
|
|
|
+ List<Object> rowDatas = new ArrayList<>();
|
|
|
+ rows.add(rowDatas);
|
|
|
+
|
|
|
+ for (Field field : fields) {
|
|
|
+ field.setAccessible(true);
|
|
|
+ try {
|
|
|
+ rowDatas.add(field.get(datum));
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ log.error("获取值出错:{}", field.getName());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Pair<String, String>> styles = Arrays
|
|
|
+ .asList(
|
|
|
+ Pair.of("F", "0.00%"),
|
|
|
+ Pair.of("O", "0.00%"),
|
|
|
+ Pair.of("P", "0.00%"),
|
|
|
+ Pair.of("Q", "0.00%"),
|
|
|
+ Pair.of("R", "0.00%"),
|
|
|
+ Pair.of("W", "0.00%"),
|
|
|
+ Pair.of("X", "0.00%"),
|
|
|
+ Pair.of("Y", "0.00%"),
|
|
|
+ Pair.of("Z", "0.00%"),
|
|
|
+ Pair.of("AE", "0.00%"),
|
|
|
+ Pair.of("AF", "0.00%"),
|
|
|
+ Pair.of("AG", "0.00%"),
|
|
|
+ Pair.of("AN", "0.00%"),
|
|
|
+ Pair.of("AO", "0.00%"),
|
|
|
+ Pair.of("AP", "0.00%"),
|
|
|
+ Pair.of("AQ", "0.00%")
|
|
|
+ );
|
|
|
+
|
|
|
+ doSendFeishuSheet(Collections.singletonList(dateStr), sheetToken, sheetId, rowNum, rows, 3, styles);
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<IntermediateIndicatorsExport> intermediateIndicatorsData(String dateStr) {
|
|
|
+ List<IntermediateIndicatorsExport> result = buildIntermediateIndicatorsData(dateStr);
|
|
|
+ Map<String, IntermediateIndicatorsExport> resultMap = result.stream().collect(Collectors.toMap(
|
|
|
+ IntermediateIndicatorsExport::getType, o -> o));
|
|
|
+ List<String> small = Arrays.asList("gh_084a485e859a", "gh_183d80deffb8", "gh_1b27dd1beeca", "gh_29074b51f2b7",
|
|
|
+ "gh_4568b5a7e2fe", "gh_5ff48e9fb9ef", "gh_6d9f36e3a7be", "gh_72bace6b3059", "gh_7b4a5f86d68c",
|
|
|
+ "gh_9f8dc5b0c74e", "gh_b676b7ad9b74", "gh_ee78360d06f5", "gh_f25b5fb01977", "gh_f902cea89e48");
|
|
|
+ Long dateStart = DateUtils.getStartOfDay(dateStr, "yyyyMMdd");
|
|
|
+ Long dateEnd = DateUtils.getEndOfDay(dateStr, "yyyyMMdd");
|
|
|
+ long timestamp = DateUtils.dateStrToTimestamp(dateStr, "yyyyMMdd");
|
|
|
+ String dateStrS = DateUtils.timestampToYMDStr(timestamp, "yyyy-MM-dd");
|
|
|
+ List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByUpdateTimeLessThanEqual(dateStrS);
|
|
|
+ Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap = accountAvgInfoList.stream()
|
|
|
+ .filter(o -> Objects.nonNull(o.getReadAvg()) && o.getReadAvg() > 0 && o.getFans() > 1000)
|
|
|
+ .collect(Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.groupingBy(AccountAvgInfo::getUpdateTime,
|
|
|
+ Collectors.toMap(AccountAvgInfo::getPosition, o -> o))));
|
|
|
+ List<String> ghIds = accountAvgInfoList.stream().map(AccountAvgInfo::getGhId).distinct().collect(Collectors.toList());
|
|
|
+ List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeLessThanAndTypeEquals(ghIds, dateEnd, "9");
|
|
|
+ List<Article> todayPublish = articleList.stream().filter(o -> o.getUpdateTime() > dateStart).collect(Collectors.toList());
|
|
|
+ Map<String, List<Article>> hisPublishMap = articleList.stream().collect(Collectors.groupingBy(Article::getTitle));
|
|
|
+ List<String> wxSnList = articleList.stream().map(Article::getWxSn).distinct().collect(Collectors.toList());
|
|
|
+ List<ArticleDetailInfo> articleDetailInfoList = new ArrayList<>();
|
|
|
+ for (List<String> partitions : Lists.partition(wxSnList, 1000)) {
|
|
|
+ articleDetailInfoList.addAll(articleDetailInfoRepository.getAllByWxSnIn(partitions));
|
|
|
+ }
|
|
|
+ Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
|
|
|
+ .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
|
|
|
+ List<PublishSortLog> publishSortLogList = publishSortLogRepository.findByDateStr(dateStr);
|
|
|
+ Map<String, Map<Integer, PublishSortLog>> publishSortLogMap = publishSortLogList.stream()
|
|
|
+ .collect(Collectors.groupingBy(PublishSortLog::getGhId, Collectors.toMap(
|
|
|
+ PublishSortLog::getIndex, o -> o, (existing, replacement) -> replacement
|
|
|
+ )));
|
|
|
+ List<NewSortStrategyExport> newSortStrategyExportList = getNewSortStrategyExportList(todayPublish,
|
|
|
+ articleDetailInfoMap, accountAvgInfoIndexMap);
|
|
|
+
|
|
|
+ List<Article> futurePublishList = articleRepository.getByUpdateTimeGreaterThanAndTypeEquals(dateEnd, "9");
|
|
|
+ Map<String, List<Article>> futurePublishMap = futurePublishList.stream().collect(Collectors.groupingBy(Article::getTitle));
|
|
|
+
|
|
|
+ Map<String, List<String>> titleTypeMap = new HashMap<>();
|
|
|
+ Map<String, Map<Integer, List<String>>> titleTypePoolMap = new HashMap<>();
|
|
|
+ for (NewSortStrategyExport data : newSortStrategyExportList) {
|
|
|
+ String type = getArticleType(data, small);
|
|
|
+ IntermediateIndicatorsExport item = resultMap.get(type);
|
|
|
+ List<Article> list = hisPublishMap.get(data.getTitle());
|
|
|
+ Integer poolLevel = getArticlePoolLevel(data, list, small);
|
|
|
+ // 发布情况
|
|
|
+ setPublishSituation(item, type, titleTypeMap, titleTypePoolMap, poolLevel, data);
|
|
|
+ // 发布表现
|
|
|
+ setPublishPerformance(item, data, publishSortLogMap);
|
|
|
+ // 发布依赖表现
|
|
|
+ setPublishSourcePerformance(item, data, accountAvgInfoIndexMap, articleDetailInfoMap, hisPublishMap, small);
|
|
|
+ // 发布未来表现 todo
|
|
|
+ setPublishFuturePerformance(item, data, poolLevel, futurePublishMap, small);
|
|
|
+
|
|
|
+ List<String> titles = titleTypeMap.computeIfAbsent(type, k -> new ArrayList<>());
|
|
|
+ titles.add(data.getTitle());
|
|
|
+ Map<Integer, List<String>> titlePoolMap = titleTypePoolMap.computeIfAbsent(type, k -> new HashMap<>());
|
|
|
+ List<String> poolTitles = titlePoolMap.computeIfAbsent(poolLevel, k -> new ArrayList<>());
|
|
|
+ poolTitles.add(data.getTitle());
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPublishFuturePerformance(IntermediateIndicatorsExport item, NewSortStrategyExport data, Integer poolLevel,
|
|
|
+ Map<String, List<Article>> futurePublishMap, List<String> small) {
|
|
|
+ List<Article> futurePublishList = futurePublishMap.get(data.getTitle());
|
|
|
+// Integer futurePoolLevel = getArticlePoolLevel(data, futurePublishList, small);
|
|
|
+// if (futurePoolLevel > poolLevel) {
|
|
|
+//
|
|
|
+// }
|
|
|
+ item.setPromotionCountL2(item.getPromotionCountL2());
|
|
|
+ item.setPromotionCountL3(item.getPromotionCountL3());
|
|
|
+ item.setPromotionCountL4(item.getPromotionCountL4());
|
|
|
+ item.setPromotionRateL2(item.getPromotionRateL2());
|
|
|
+ item.setPromotionRateL3(item.getPromotionRateL3());
|
|
|
+ item.setPromotionRateL4(item.getPromotionRateL4());
|
|
|
+ item.setT1DayViewCount(item.getT1DayViewCount());
|
|
|
+ item.setT1DayFirstLayerUV(item.getT1DayFirstLayerUV());
|
|
|
+ item.setT1DayT0FissionUV(item.getT1DayT0FissionUV());
|
|
|
+ item.setT1DayAccountArticleRelevanceAvg(item.getT1DayAccountArticleRelevanceAvg());
|
|
|
+ item.setT1DayAverageViewToBaseRatio(item.getT1DayAverageViewToBaseRatio());
|
|
|
+ item.setT1DayAverageMiniAppOpenRate(item.getT1DayAverageMiniAppOpenRate());
|
|
|
+ item.setT1DayAverageT0FissionRate(item.getT1DayAverageT0FissionRate());
|
|
|
+ item.setT1DayAverageFirstLayerFissionToViewBaseRatio(item.getT1DayAverageFirstLayerFissionToViewBaseRatio());
|
|
|
+ item.setT1DayViewBase(item.getT1DayViewBase());
|
|
|
+ item.setT2DayViewCount(item.getT2DayViewCount());
|
|
|
+ item.setT2DayFirstLayerUV(item.getT2DayFirstLayerUV());
|
|
|
+ item.setT2DayT0FissionUV(item.getT2DayT0FissionUV());
|
|
|
+ item.setT2DayAccountArticleRelevanceAvg(item.getT2DayAccountArticleRelevanceAvg());
|
|
|
+ item.setT2DayAverageViewToBaseRatio(item.getT2DayAverageViewToBaseRatio());
|
|
|
+ item.setT2DayAverageMiniAppOpenRate(item.getT2DayAverageMiniAppOpenRate());
|
|
|
+ item.setT2DayAverageT0FissionRate(item.getT2DayAverageT0FissionRate());
|
|
|
+ item.setT2DayAverageFirstLayerFissionToViewBaseRatio(item.getT2DayAverageFirstLayerFissionToViewBaseRatio());
|
|
|
+ item.setT2DayViewBase(item.getT2DayViewBase());
|
|
|
+ item.setT3DayViewCount(item.getT3DayViewCount());
|
|
|
+ item.setT3DayFirstLayerUV(item.getT3DayFirstLayerUV());
|
|
|
+ item.setT3DayT0FissionUV(item.getT3DayT0FissionUV());
|
|
|
+ item.setT3DayAccountArticleRelevanceAvg(item.getT3DayAccountArticleRelevanceAvg());
|
|
|
+ item.setT3DayAverageViewToBaseRatio(item.getT3DayAverageViewToBaseRatio());
|
|
|
+ item.setT3DayAverageMiniAppOpenRate(item.getT3DayAverageMiniAppOpenRate());
|
|
|
+ item.setT3DayAverageT0FissionRate(item.getT3DayAverageT0FissionRate());
|
|
|
+ item.setT3DayAverageFirstLayerFissionToViewBaseRatio(item.getT3DayAverageFirstLayerFissionToViewBaseRatio());
|
|
|
+ item.setT3DayViewBase(item.getT3DayViewBase());
|
|
|
+ item.setT3PlusDayViewCount(item.getT3PlusDayViewCount());
|
|
|
+ item.setT3PlusDayFirstLayerUV(item.getT3PlusDayFirstLayerUV());
|
|
|
+ item.setT3PlusDayT0FissionUV(item.getT3PlusDayT0FissionUV());
|
|
|
+ item.setT3PlusDayAccountArticleRelevanceAvg(item.getT3PlusDayAccountArticleRelevanceAvg());
|
|
|
+ item.setT3PlusDayAverageViewToBaseRatio(item.getT3PlusDayAverageViewToBaseRatio());
|
|
|
+ item.setT3PlusDayAverageMiniAppOpenRate(item.getT3PlusDayAverageMiniAppOpenRate());
|
|
|
+ item.setT3PlusDayAverageT0FissionRate(item.getT3PlusDayAverageT0FissionRate());
|
|
|
+ item.setT3PlusDayAverageFirstLayerFissionToViewBaseRatio(item.getT3PlusDayAverageFirstLayerFissionToViewBaseRatio());
|
|
|
+ item.setT3PlusDayViewBase(item.getT3PlusDayViewBase());
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<NewSortStrategyExport> getNewSortStrategyExportList(List<Article> todayPublish,
|
|
|
+ Map<String, List<ArticleDetailInfo>> articleDetailInfoMap,
|
|
|
+ Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap) {
|
|
|
+ List<NewSortStrategyExport> result = new ArrayList<>();
|
|
|
+ for (Article article : todayPublish) {
|
|
|
+ List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
|
|
|
+ if (CollectionUtils.isEmpty(articleDetailInfos)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
|
|
|
+ int sumFirstLevel = 0;
|
|
|
+ int sumFission0 = 0;
|
|
|
+ int sumFission1 = 0;
|
|
|
+ int sumFission2 = 0;
|
|
|
+ for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
|
|
|
+ if (articleDetailInfo.getRecallDt().equals(minDate)) {
|
|
|
+ sumFirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
|
|
|
+ sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
|
|
|
+ sumFission1 += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
|
|
|
+ sumFission2 += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<String, Map<String, AccountAvgInfo>> dateAvgMap = accountAvgInfoIndexMap.get(article.getGhId());
|
|
|
+ String hisPublishDate = DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyy-MM-dd");
|
|
|
+ AccountAvgInfo avgInfo = null;
|
|
|
+ if (Objects.nonNull(dateAvgMap)) {
|
|
|
+ List<String> avgMapDateList = new ArrayList<>(dateAvgMap.keySet());
|
|
|
+ hisPublishDate = DateUtils.findNearestDate(avgMapDateList, hisPublishDate, "yyyy-MM-dd");
|
|
|
+ Map<String, AccountAvgInfo> accountAvgInfoMap = dateAvgMap.get(hisPublishDate);
|
|
|
+ if (Objects.nonNull(accountAvgInfoMap)) {
|
|
|
+ avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String date = DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyyMMdd");
|
|
|
+ NewSortStrategyExport obj = new NewSortStrategyExport();
|
|
|
+ obj.setGhId(article.getGhId());
|
|
|
+ obj.setAccountName(article.getAccountName());
|
|
|
+ obj.setTitle(article.getTitle());
|
|
|
+ obj.setLink(article.getContentUrl());
|
|
|
+ obj.setPosition(article.getItemIndex());
|
|
|
+ obj.setViewCount(article.getShowViewCount());
|
|
|
+ obj.setDateStr(date);
|
|
|
+ obj.setFirstLevel(sumFirstLevel);
|
|
|
+ obj.setFission0(sumFission0);
|
|
|
+ obj.setFission1(sumFission1);
|
|
|
+ obj.setFission2(sumFission2);
|
|
|
+ obj.setWxSn(article.getWxSn());
|
|
|
+ if (Objects.nonNull(avgInfo)) {
|
|
|
+ obj.setAccountMode(avgInfo.getAccountMode());
|
|
|
+ obj.setAccountSource(avgInfo.getAccountSource());
|
|
|
+ obj.setAccountType(avgInfo.getAccountType());
|
|
|
+ obj.setAccountStatus(avgInfo.getAccountStatus());
|
|
|
+ obj.setBusinessType(AccountBusinessTypeEnum.from(avgInfo.getBusinessType()).getDescription());
|
|
|
+ obj.setFans(avgInfo.getFans());
|
|
|
+ obj.setAvgViewCount(avgInfo.getReadAvg());
|
|
|
+ if (avgInfo.getReadAvg() > 0) {
|
|
|
+ obj.setReadRate((article.getShowViewCount() * 1.0) / avgInfo.getReadAvg());
|
|
|
+ obj.setFission0ReadAvgRate((sumFission0 * 1.0) / avgInfo.getReadAvg());
|
|
|
+ }
|
|
|
+ if (avgInfo.getFans() > 0) {
|
|
|
+ obj.setReadFansRate((article.getShowViewCount() * 1.0) / avgInfo.getFans());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sumFirstLevel > 0) {
|
|
|
+ obj.setFission0FirstRate((sumFission0 * 1.0) / sumFirstLevel);
|
|
|
+ }
|
|
|
+ if (article.getShowViewCount() > 0) {
|
|
|
+ obj.setFirstReadRate((sumFirstLevel * 1.0) / article.getShowViewCount());
|
|
|
+ }
|
|
|
+ if (sumFission0 > 0) {
|
|
|
+ obj.setFission1Fission0Rate((sumFission1 * 1.0) / sumFission0);
|
|
|
+ }
|
|
|
+ result.add(obj);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPublishSourcePerformance(IntermediateIndicatorsExport item, NewSortStrategyExport data,
|
|
|
+ Map<String, Map<String, Map<String, AccountAvgInfo>>> accountAvgInfoIndexMap,
|
|
|
+ Map<String, List<ArticleDetailInfo>> articleDetailInfoMap,
|
|
|
+ Map<String, List<Article>> hisPublishMap, List<String> small) {
|
|
|
+ List<Article> hisPublish = hisPublishMap.get(data.getTitle());
|
|
|
+ for (Article publish : hisPublish) {
|
|
|
+ Map<String, Map<String, AccountAvgInfo>> dateAvgMap = accountAvgInfoIndexMap.get(publish.getGhId());
|
|
|
+ String hisPublishDate = DateUtils.timestampToYMDStr(publish.getUpdateTime(), "yyyy-MM-dd");
|
|
|
+ AccountAvgInfo avgInfo = null;
|
|
|
+ if (Objects.nonNull(dateAvgMap)) {
|
|
|
+ List<String> avgMapDateList = new ArrayList<>(dateAvgMap.keySet());
|
|
|
+ hisPublishDate = DateUtils.findNearestDate(avgMapDateList, hisPublishDate, "yyyy-MM-dd");
|
|
|
+ Map<String, AccountAvgInfo> accountAvgInfoMap = dateAvgMap.get(hisPublishDate);
|
|
|
+ if (Objects.nonNull(accountAvgInfoMap)) {
|
|
|
+ avgInfo = accountAvgInfoMap.get(publish.getItemIndex().toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!(publish.getItemIndex() == 1 && !small.contains(publish.getGhId()))) {
|
|
|
+ item.setTotalArticleReleaseCountNonInfinite(item.getTotalArticleReleaseCountNonInfinite() + 1);
|
|
|
+ }
|
|
|
+ item.setRedundantViewCount(item.getRedundantViewCount() + publish.getShowViewCount());
|
|
|
+ if (Objects.nonNull(avgInfo)) {
|
|
|
+ item.setRedundantViewBase(item.getRedundantViewBase() + avgInfo.getReadAvg());
|
|
|
+ }
|
|
|
+ if (item.getRedundantViewBase() > 0 && item.getRedundantViewCount() > 0) {
|
|
|
+ item.setAverageViewToBaseRatio(item.getRedundantViewCount() / (double) item.getRedundantViewBase());
|
|
|
+ }
|
|
|
+ List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(publish.getWxSn());
|
|
|
+ if (CollectionUtils.isEmpty(articleDetailInfos)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ int sumFirstLevel = 0;
|
|
|
+ int sumFission0 = 0;
|
|
|
+ Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
|
|
|
+ for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
|
|
|
+ if (articleDetailInfo.getRecallDt().equals(minDate)) {
|
|
|
+ sumFirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
|
|
|
+ sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ item.setRedundantFirstLayerUV(item.getRedundantFirstLayerUV() + sumFirstLevel);
|
|
|
+ item.setRedundantT0FissionUV(item.getRedundantT0FissionUV() + sumFission0);
|
|
|
+ if (item.getRedundantFirstLayerUV() > 0 && item.getRedundantViewCount() > 0) {
|
|
|
+ item.setAverageMiniAppOpenRate(item.getRedundantFirstLayerUV() / (double) item.getRedundantViewCount());
|
|
|
+ }
|
|
|
+ if (item.getRedundantFirstLayerUV() > 0 && item.getRedundantT0FissionUV() > 0) {
|
|
|
+ item.setAverageT0FissionRate(item.getRedundantT0FissionUV() / (double) item.getRedundantFirstLayerUV());
|
|
|
+ }
|
|
|
+ if (item.getRedundantViewBase() > 0 && item.getRedundantT0FissionUV() > 0) {
|
|
|
+ item.setAverageFirstLayerFissionToViewBaseRatio(item.getRedundantT0FissionUV() / (double) item.getRedundantViewBase());
|
|
|
+ }
|
|
|
+ // todo
|
|
|
+ item.setFirstExplorationIntervalAvg(item.getFirstExplorationIntervalAvg());
|
|
|
+ item.setRedundantAccountArticleRelevanceAvg(item.getRedundantAccountArticleRelevanceAvg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPublishPerformance(IntermediateIndicatorsExport item, NewSortStrategyExport data,
|
|
|
+ Map<String, Map<Integer, PublishSortLog>> publishSortLogMap) {
|
|
|
+ item.setViewCount(item.getViewCount() + data.getViewCount());
|
|
|
+ item.setFirstLayerUV(item.getFirstLayerUV() + data.getFirstLevel());
|
|
|
+ item.setT0FissionUV(item.getT0FissionUV() + data.getFission0());
|
|
|
+ item.setViewBase(item.getViewBase() + data.getAvgViewCount());
|
|
|
+ if (item.getViewBase() > 0 && item.getViewCount() > 0) {
|
|
|
+ item.setViewToBaseRatio(item.getViewCount() / (double) item.getViewBase());
|
|
|
+ }
|
|
|
+ if (item.getFirstLayerUV() > 0 && item.getViewCount() > 0) {
|
|
|
+ item.setMiniAppOpenRate(item.getFirstLayerUV() / (double) item.getViewCount());
|
|
|
+ }
|
|
|
+ if (item.getFirstLayerUV() > 0 && item.getT0FissionUV() > 0) {
|
|
|
+ item.setT0FissionRate(item.getT0FissionUV() / (double) item.getFirstLayerUV());
|
|
|
+ item.setT0FissionRateAgain(item.getT0FissionUV() / (double) item.getFirstLayerUV());
|
|
|
+ }
|
|
|
+ item.setT0FissionCount(item.getT0FissionCount() + data.getFission0());
|
|
|
+ item.setT1FissionCount(item.getT1FissionCount() + data.getFission1());
|
|
|
+ item.setT2FissionCount(item.getT2FissionCount() + data.getFission2());
|
|
|
+ if (item.getT0FissionCount() > 0 && item.getViewBase() > 0) {
|
|
|
+ item.setFirstLayerFissionToViewBaseRatio(item.getT0FissionCount() / (double) item.getViewBase());
|
|
|
+ }
|
|
|
+ if (item.getT0FissionCount() + item.getT1FissionCount() > 0 && item.getFirstLayerUV() > 0) {
|
|
|
+ item.setT1CumulativeFissionRate((item.getT0FissionCount() + item.getT1FissionCount()) / (double) item.getFirstLayerUV());
|
|
|
+ }
|
|
|
+ if (item.getT0FissionCount() + item.getT1FissionCount() + item.getT2FissionCount() > 0 && item.getViewBase() > 0) {
|
|
|
+ item.setT2CumulativeFissionRate((item.getT0FissionCount() + item.getT1FissionCount() + item.getT2FissionCount()) / (double) item.getFirstLayerUV());
|
|
|
+ }
|
|
|
+ Map<Integer, PublishSortLog> indexMap = publishSortLogMap.get(data.getGhId());
|
|
|
+ if (Objects.nonNull(indexMap)) {
|
|
|
+ PublishSortLog log = indexMap.get(data.getPosition());
|
|
|
+ double scoreAvg = item.getAccountArticleRelevanceAvg();
|
|
|
+ double score = 0.0;
|
|
|
+ if (Objects.nonNull(log) && Objects.nonNull(log.getScore())) {
|
|
|
+ JSONObject scoreMap = JSONObject.parseObject(log.getScoreMap());
|
|
|
+ if (scoreMap.containsKey("SimilarityStrategy")) {
|
|
|
+ score = scoreMap.getDoubleValue("SimilarityStrategy");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ scoreAvg = (scoreAvg * (item.getActualArticleReleaseCount() - 1) + score) / item.getActualArticleReleaseCount();
|
|
|
+ item.setAccountArticleRelevanceAvg(scoreAvg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setPublishSituation(IntermediateIndicatorsExport item, String type, Map<String, List<String>> titleTypeMap,
|
|
|
+ Map<String, Map<Integer, List<String>>> titleTypePoolMap, Integer poolLevel,
|
|
|
+ NewSortStrategyExport data) {
|
|
|
+ item.setArticleReleaseSlot(item.getArticleReleaseSlot() + 1);
|
|
|
+ item.setActualArticleReleaseCount(item.getActualArticleReleaseCount() + 1);
|
|
|
+ if (titleTypeMap.containsKey(type) && !titleTypeMap.get(type).contains(data.getTitle())) {
|
|
|
+ item.setDistinctArticleReleaseCount(item.getDistinctArticleReleaseCount() + 1);
|
|
|
+ }
|
|
|
+ item.setDistinctArticleReleaseRatio(item.getDistinctArticleReleaseCount() / (double) item.getActualArticleReleaseCount());
|
|
|
+
|
|
|
+ if (4 == poolLevel) {
|
|
|
+ item.setActualReleaseCountL4(item.getActualReleaseCountL4() + 1);
|
|
|
+ } else if (3 == poolLevel) {
|
|
|
+ item.setActualReleaseCountL3(item.getActualReleaseCountL3() + 1);
|
|
|
+ } else if (2 == poolLevel) {
|
|
|
+ item.setActualReleaseCountL2(item.getActualReleaseCountL2() + 1);
|
|
|
+ } else {
|
|
|
+ item.setActualReleaseCountL1(item.getActualReleaseCountL1() + 1);
|
|
|
+ }
|
|
|
+ if (titleTypePoolMap.containsKey(type)
|
|
|
+ && titleTypePoolMap.get(type).containsKey(poolLevel)
|
|
|
+ && !titleTypePoolMap.get(type).get(poolLevel).contains(data.getTitle())) {
|
|
|
+ if (4 == poolLevel) {
|
|
|
+ item.setDistinctReleaseCountL4(item.getDistinctReleaseCountL4() + 1);
|
|
|
+ } else if (3 == poolLevel) {
|
|
|
+ item.setDistinctReleaseCountL3(item.getDistinctReleaseCountL3() + 1);
|
|
|
+ } else if (2 == poolLevel) {
|
|
|
+ item.setDistinctReleaseCountL2(item.getDistinctReleaseCountL2() + 1);
|
|
|
+ } else {
|
|
|
+ item.setDistinctReleaseCountL1(item.getDistinctReleaseCountL1() + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (item.getActualReleaseCountL1() > 0 && item.getDistinctReleaseCountL1() > 0) {
|
|
|
+ item.setDistinctToActualRatioL1(item.getDistinctReleaseCountL1() / (double) item.getActualReleaseCountL1());
|
|
|
+ }
|
|
|
+ if (item.getActualReleaseCountL2() > 0 && item.getDistinctReleaseCountL2() > 0) {
|
|
|
+ item.setDistinctToActualRatioL2(item.getDistinctReleaseCountL2() / (double) item.getActualReleaseCountL2());
|
|
|
+ }
|
|
|
+ if (item.getActualReleaseCountL3() > 0 && item.getDistinctReleaseCountL3() > 0) {
|
|
|
+ item.setDistinctToActualRatioL3(item.getDistinctReleaseCountL3() / (double) item.getActualReleaseCountL3());
|
|
|
+ }
|
|
|
+ if (item.getActualReleaseCountL4() > 0 && item.getDistinctReleaseCountL4() > 0) {
|
|
|
+ item.setDistinctToActualRatioL4(item.getDistinctReleaseCountL4() / (double) item.getActualReleaseCountL4());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Integer getArticlePoolLevel(NewSortStrategyExport data, List<Article> list, List<String> small) {
|
|
|
+ int minPosition = list.stream().mapToInt(Article::getItemIndex).min().orElse(8);
|
|
|
+ if (minPosition == 1) {
|
|
|
+ if (small.contains(data.getGhId())) {
|
|
|
+ return 3;
|
|
|
+ } else {
|
|
|
+ return 4;
|
|
|
+ }
|
|
|
+ } else if (data.getPosition() == 2) {
|
|
|
+ return 2;
|
|
|
+ } else {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getArticleType(NewSortStrategyExport data, List<String> small) {
|
|
|
+ if (data.getPosition() == 1) {
|
|
|
+ if (small.contains(data.getGhId())) {
|
|
|
+ return "L1-订阅号冷启1";
|
|
|
+ } else {
|
|
|
+ return "L1-订阅号无限流";
|
|
|
+ }
|
|
|
+ } else if (data.getPosition() == 2) {
|
|
|
+ return "L2-订阅号冷启2";
|
|
|
+ } else {
|
|
|
+ return "L3-订阅号利用";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<IntermediateIndicatorsExport> buildIntermediateIndicatorsData(String dateStr) {
|
|
|
+ List<IntermediateIndicatorsExport> result = new ArrayList<>();
|
|
|
+ List<String> typeList = Arrays.asList("L3-订阅号利用", "L2-订阅号冷启2", "L1-订阅号冷启1", "L1-订阅号无限流");
|
|
|
+ for (String type : typeList) {
|
|
|
+ IntermediateIndicatorsExport item = new IntermediateIndicatorsExport();
|
|
|
+ item.setDateStr(dateStr);
|
|
|
+ item.setType(type);
|
|
|
+ result.add(item);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|