RecommendTest.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. package com.tzld.longarticle.recommend.server;
  2. import cn.hutool.core.collection.CollectionUtil;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.google.common.collect.Lists;
  6. import com.tzld.longarticle.recommend.server.mapper.crawler.CrawlerBaseMapper;
  7. import com.tzld.longarticle.recommend.server.model.entity.crawler.AccountAvgInfo;
  8. import com.tzld.longarticle.recommend.server.model.entity.crawler.Article;
  9. import com.tzld.longarticle.recommend.server.model.entity.crawler.ArticleDetailInfo;
  10. import com.tzld.longarticle.recommend.server.model.entity.crawler.PublishSortLog;
  11. import com.tzld.longarticle.recommend.server.repository.crawler.AccountAvgInfoRepository;
  12. import com.tzld.longarticle.recommend.server.repository.crawler.ArticleDetailInfoRepository;
  13. import com.tzld.longarticle.recommend.server.repository.crawler.ArticleRepository;
  14. import com.tzld.longarticle.recommend.server.repository.crawler.PublishSortLogRepository;
  15. import com.tzld.longarticle.recommend.server.service.RecommendService;
  16. import com.tzld.longarticle.recommend.server.service.recall.RecallService;
  17. import com.tzld.longarticle.recommend.server.util.DateUtils;
  18. import org.apache.poi.ss.usermodel.Cell;
  19. import org.apache.poi.ss.usermodel.Row;
  20. import org.apache.poi.ss.usermodel.Sheet;
  21. import org.apache.poi.ss.usermodel.Workbook;
  22. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  23. import org.junit.jupiter.api.Test;
  24. import org.springframework.boot.test.context.SpringBootTest;
  25. import javax.annotation.Resource;
  26. import java.io.FileOutputStream;
  27. import java.io.IOException;
  28. import java.util.*;
  29. import java.util.stream.Collectors;
  30. @SpringBootTest(classes = Application.class)
  31. public class RecommendTest {
  32. @Resource
  33. private RecommendService recommendService;
  34. @Resource
  35. private RecallService recallService;
  36. @Resource
  37. private ArticleRepository articleRepository;
  38. @Resource
  39. private ArticleDetailInfoRepository articleDetailInfoRepository;
  40. @Resource
  41. private AccountAvgInfoRepository accountAvgInfoRepository;
  42. @Resource
  43. private CrawlerBaseMapper crawlerBaseMapper;
  44. @Resource
  45. private PublishSortLogRepository publishSortLogRepository;
  46. // @Test
  47. // void recall() {
  48. // RecallParam param = new RecallParam();
  49. // param.setAccountId("20231213123536190184852");
  50. // param.setPlanId("20240718181730864154902");
  51. // RecallResult recallResult = recallService.recall(param);
  52. // System.out.println(JSONObject.toJSONString(recallResult));
  53. // }
  54. //
  55. // @Test
  56. // void exportData() {
  57. // Set<String> ghIds = new HashSet<>(Arrays.asList("gh_adca24a8f429", "gh_e0eb490115f5", "gh_51e4ad40466d", "gh_95ed5ecf9363"));
  58. // List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThanAndTypeEquals(ghIds, 1722441600L, "9");
  59. //
  60. // Map<String, Map<Integer, List<Article>>> map = articleList.stream()
  61. // .collect(Collectors.groupingBy(Article::getTitle, Collectors.groupingBy(Article::getItemIndex)));
  62. // Set<String> snList = articleList.stream().map(Article::getWxSn).collect(Collectors.toSet());
  63. // List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(new ArrayList<>(snList));
  64. // Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
  65. // .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
  66. //
  67. // List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByGhIdInAndStatusEquals(ghIds, 1);
  68. // Map<String, Map<String, AccountAvgInfo>> accountAvgInfoIndexMap = accountAvgInfoList.stream().collect(
  69. // Collectors.groupingBy(AccountAvgInfo::getGhId, Collectors.toMap(AccountAvgInfo::getPosition, o -> o)));
  70. // JSONArray jsonArray = new JSONArray();
  71. // for (Article article : articleList) {
  72. // List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
  73. // if (CollectionUtils.isEmpty(articleDetailInfos)) {
  74. // continue;
  75. // }
  76. // Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
  77. // int sumfirstLevel = 0;
  78. // int sumFission0 = 0;
  79. // int sumFission1 = 0;
  80. // int sumFission2 = 0;
  81. // for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
  82. // if (articleDetailInfo.getRecallDt().equals(minDate)) {
  83. // sumfirstLevel += Optional.ofNullable(articleDetailInfo.getFirstLevel()).orElse(0);
  84. // sumFission0 += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
  85. // sumFission1 += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
  86. // sumFission2 += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
  87. // }
  88. // }
  89. // Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoIndexMap.get(article.getGhId());
  90. // AccountAvgInfo avgInfo = accountAvgInfoMap.get(article.getItemIndex().toString());
  91. // SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  92. // String date = sdf.format(new Date(article.getUpdateTime() * 1000));
  93. // JSONObject obj = new JSONObject();
  94. // obj.put("ghId", article.getGhId());
  95. // obj.put("accountName", article.getAccountName());
  96. // obj.put("title", article.getTitle());
  97. // obj.put("index", article.getItemIndex());
  98. // obj.put("viewCount", article.getShowViewCount());
  99. // obj.put("time", date);
  100. // if (Objects.nonNull(avgInfo)) {
  101. // obj.put("fans", avgInfo.getFans());
  102. // obj.put("avgViewCount", avgInfo.getReadAvg());
  103. // obj.put("viewCountRate", (article.getShowViewCount() * 1.0) / avgInfo.getReadAvg());
  104. // }
  105. // obj.put("firstLevel", sumfirstLevel);
  106. // obj.put("fission0", sumFission0);
  107. // obj.put("fission1", sumFission1);
  108. // obj.put("fission2", sumFission2);
  109. // jsonArray.add(obj);
  110. // }
  111. // System.out.println(jsonArray.toJSONString());
  112. // }
  113. //
  114. // @Test
  115. // void ii() throws IOException {
  116. // String dateStr = "20240911";
  117. // List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByStatusEquals(1);
  118. // Map<String, String> accountMap = accountAvgInfoList.stream().collect(
  119. // Collectors.toMap(AccountAvgInfo::getAccountName, AccountAvgInfo::getGhId, (existing, replacement) -> replacement));
  120. // BufferedReader reader = new BufferedReader(new FileReader("/Users/wangyunpeng/Downloads/账号相关性.json"));
  121. // StringBuilder sb = new StringBuilder();
  122. // String line;
  123. // while ((line = reader.readLine()) != null) {
  124. // sb.append(line);
  125. // }
  126. // String jsonStr = sb.toString();
  127. // // 使用 ObjectMapper 解析 JSON
  128. // ObjectMapper objectMapper = new ObjectMapper();
  129. //
  130. // try {
  131. // // 将 JSON 转换为 Map<String, Map<String, Double>>
  132. // Map<String, Map<String, Double>> result = objectMapper.readValue(jsonStr,
  133. // new TypeReference<Map<String, Map<String, Double>>>() {
  134. // });
  135. //
  136. // // 输出转换结果
  137. // System.out.println(result);
  138. // List<AccountCorrelation> saveList = new ArrayList<>();
  139. // result.forEach((k, v) -> {
  140. // String ghId = accountMap.get(k);
  141. // v.forEach((k1, v1) -> {
  142. // String relGhId = accountMap.get(k1);
  143. // AccountCorrelation save = new AccountCorrelation();
  144. // save.setDateStr(dateStr);
  145. // save.setGhId(ghId);
  146. // save.setAccountName(k);
  147. // save.setRelGhId(relGhId);
  148. // save.setRelAccountName(k1);
  149. // save.setStatus(1);
  150. // save.setCorrelation(v1);
  151. // saveList.add(save);
  152. // });
  153. // });
  154. // List<AccountCorrelation> all = new ArrayList<>(saveList);
  155. // for (AccountCorrelation item : all) {
  156. // if (!item.getGhId().equals(item.getRelGhId())) {
  157. // AccountCorrelation save = new AccountCorrelation();
  158. // BeanUtils.copyProperties(item, save);
  159. // save.setGhId(item.getRelGhId());
  160. // save.setAccountName(item.getRelAccountName());
  161. // save.setRelGhId(item.getGhId());
  162. // save.setRelAccountName(item.getAccountName());
  163. // saveList.add(save);
  164. // }
  165. // }
  166. // crawlerBaseMapper.batchInsertAccountCorrelation(saveList);
  167. //
  168. //
  169. // } catch (IOException e) {
  170. // e.printStackTrace();
  171. // }
  172. // }
  173. @Test
  174. public void test() {
  175. List<String> morning = Lists.newArrayList("gh_084a485e859a", "gh_183d80deffb8", "gh_5ff48e9fb9ef", "gh_6d9f36e3a7be", "gh_9f8dc5b0c74e", "gh_e0eb490115f5", "gh_e24da99dc899");
  176. List<String> noon = Lists.newArrayList("gh_080bb43aa0dc", "gh_0c89e11f8bf3", "gh_192c9cf58b13", "gh_1b27dd1beeca", "gh_1d887d61088c", "gh_29074b51f2b7", "gh_3ed305b5817f", "gh_5ae65db96cb7", "gh_6b7c2a257263", "gh_6cfd1132df94", "gh_6d205db62f04", "gh_72bace6b3059", "gh_7e5818b2dd83", "gh_7f5075624a50", "gh_89ef4798d3ea", "gh_9877c8541764", "gh_9eef14ad6c16", "gh_a2901d34f75b", "gh_b15de7c99912", "gh_b676b7ad9b74", "gh_b6f2c5332c72", "gh_bfe5b705324a", "gh_bff0bcb0694a", "gh_c5cdf60d9ab4", "gh_c69776baf2cd", "gh_d49df5e974ca", "gh_d4dffc34ac39", "gh_dd4c857bbb36", "gh_ee78360d06f5", "gh_f25b5fb01977", "gh_f902cea89e48", "gh_ff487cb5dab3");
  177. String dateStr = "2024-09-12";
  178. List<Article> articleList = articleRepository.getByUpdateTimeGreaterThanAndTypeEquals(1725120000L, "9");
  179. articleList = articleList.stream().filter(o -> o.getItemIndex() == 1 && o.getUpdateTime() < 1726675200).collect(Collectors.toList());
  180. Map<String, List<Article>> map = articleList.stream().collect(Collectors.groupingBy(Article::getTitle));
  181. List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByUpdateTime(dateStr);
  182. accountAvgInfoList = accountAvgInfoList.stream().filter(o -> o.getPosition().equals("1")).collect(Collectors.toList());
  183. Map<String, AccountAvgInfo> accountAvgInfoMap = accountAvgInfoList.stream().collect(Collectors.toMap(AccountAvgInfo::getGhId, o -> o));
  184. List<String> wxSnList = articleList.stream().map(Article::getWxSn).collect(Collectors.toList());
  185. List<ArticleDetailInfo> articleDetailInfoList = articleDetailInfoRepository.getAllByWxSnIn(wxSnList);
  186. Map<String, List<ArticleDetailInfo>> articleDetailInfoMap = articleDetailInfoList.stream()
  187. .collect(Collectors.groupingBy(ArticleDetailInfo::getWxSn));
  188. JSONArray result = new JSONArray();
  189. int sumFissionMorning = 0;
  190. int sumFissionMoon = 0;
  191. int sumReadMorning = 0;
  192. int sumReadNoon = 0;
  193. long sumFansMorning = 0;
  194. long sumFansMoon = 0;
  195. double readAvgMorning = 0.0;
  196. double readAvgMoon = 0.0;
  197. for (Article article : articleList) {
  198. List<ArticleDetailInfo> articleDetailInfos = articleDetailInfoMap.get(article.getWxSn());
  199. if (CollectionUtil.isEmpty(articleDetailInfos)) {
  200. continue;
  201. }
  202. Date minDate = articleDetailInfos.stream().map(ArticleDetailInfo::getRecallDt).min(Date::compareTo).orElse(new Date());
  203. AccountAvgInfo accountAvgInfo = accountAvgInfoMap.get(article.getGhId());
  204. for (ArticleDetailInfo articleDetailInfo : articleDetailInfos) {
  205. if (articleDetailInfo.getRecallDt().equals(minDate)) {
  206. if (morning.contains(article.getGhId())) {
  207. sumFissionMorning += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
  208. sumFissionMorning += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
  209. sumFissionMorning += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
  210. }
  211. if (noon.contains(article.getGhId())) {
  212. sumFissionMoon += Optional.ofNullable(articleDetailInfo.getFission0()).orElse(0);
  213. sumFissionMoon += Optional.ofNullable(articleDetailInfo.getFission1()).orElse(0);
  214. sumFissionMoon += Optional.ofNullable(articleDetailInfo.getFission2()).orElse(0);
  215. }
  216. }
  217. }
  218. if (Objects.nonNull(accountAvgInfo)) {
  219. if (morning.contains(article.getGhId())) {
  220. readAvgMorning += accountAvgInfo.getReadAvg();
  221. sumFansMorning += accountAvgInfo.getFans();
  222. sumReadMorning += article.getShowViewCount();
  223. }
  224. if (noon.contains(article.getGhId())) {
  225. readAvgMoon += accountAvgInfo.getReadAvg();
  226. sumFansMoon += accountAvgInfo.getFans();
  227. sumReadNoon += article.getShowViewCount();
  228. }
  229. }
  230. }
  231. JSONObject jsonObjectMorning = new JSONObject();
  232. jsonObjectMorning.put("时间", "早上");
  233. jsonObjectMorning.put("sumFission", sumFissionMorning);
  234. jsonObjectMorning.put("readAvg", readAvgMorning);
  235. jsonObjectMorning.put("rate", sumFissionMorning / readAvgMorning);
  236. jsonObjectMorning.put("sumRead", sumReadMorning);
  237. jsonObjectMorning.put("sumFans", sumFansMorning);
  238. jsonObjectMorning.put("阅读率", sumReadMorning / (double) sumFansMorning);
  239. result.add(jsonObjectMorning);
  240. JSONObject jsonObjectMoon = new JSONObject();
  241. jsonObjectMoon.put("时间", "中午");
  242. jsonObjectMoon.put("sumFission", sumFissionMoon);
  243. jsonObjectMoon.put("readAvg", readAvgMoon);
  244. jsonObjectMoon.put("rate", sumFissionMoon / readAvgMoon);
  245. jsonObjectMoon.put("sumRead", sumReadNoon);
  246. jsonObjectMoon.put("sumFans", sumFansMoon);
  247. jsonObjectMoon.put("阅读率", sumReadNoon / (double) sumFansMoon);
  248. result.add(jsonObjectMoon);
  249. System.out.println(JSONObject.toJSONString(result));
  250. }
  251. @Test
  252. public void exportScoreData() {
  253. List<String> ghIds = Lists.newArrayList("gh_e24da99dc899",
  254. "gh_183d80deffb8",
  255. "gh_be8c29139989",
  256. "gh_c69776baf2cd",
  257. "gh_b15de7c99912",
  258. "gh_1d887d61088c",
  259. "gh_3ed305b5817f",
  260. "gh_3e91f0624545",
  261. "gh_30816d8adb52",
  262. "gh_970460d9ccec",
  263. "gh_749271f1ccd5"
  264. );
  265. List<PublishSortLog> sortLogList = publishSortLogRepository.findByGhIdInAndDateStrGreaterThanEqual(ghIds, "20240907");
  266. sortLogList = sortLogList.stream().filter(o -> o.getIndex() == 1).collect(Collectors.toList());
  267. sortLogList.sort(Comparator.comparing(PublishSortLog::getGhId).thenComparing(PublishSortLog::getDateStr));
  268. List<Article> articleList = articleRepository.getByGhIdInAndUpdateTimeGreaterThanAndTypeEquals(ghIds, 1725638400L, "9");
  269. articleList = articleList.stream().filter(o -> o.getItemIndex() == 1).collect(Collectors.toList());
  270. Map<String, Map<String, Article>> articleMap = articleList.stream().collect(Collectors.groupingBy(Article::getGhId, Collectors.toMap(
  271. o -> DateUtils.timestampToYMDStr(o.getUpdateTime(),"yyyyMMdd"), o -> o,
  272. (existing, replacement) -> replacement)));
  273. List<AccountAvgInfo> accountAvgInfoList = accountAvgInfoRepository.getAllByGhIdIn(new HashSet<>(ghIds));
  274. Map<String, Map<String, AccountAvgInfo>> accountAvgInfoMap = accountAvgInfoList.stream()
  275. .filter(o -> Objects.equals(o.getPosition(), "1")).collect(Collectors.groupingBy(AccountAvgInfo::getGhId,
  276. Collectors.toMap(AccountAvgInfo::getUpdateTime, o -> o)));
  277. Workbook workbook = new XSSFWorkbook();
  278. Sheet sheet = workbook.createSheet("ExampleSheet");
  279. int rowNum = 0;
  280. // 创建标题行
  281. Row titleRow = sheet.createRow(rowNum);
  282. Cell titleCell = titleRow.createCell(0);
  283. titleCell.setCellValue("日期");
  284. titleCell = titleRow.createCell(1);
  285. titleCell.setCellValue("ghID");
  286. titleCell = titleRow.createCell(2);
  287. titleCell.setCellValue("账号名称");
  288. titleCell = titleRow.createCell(3);
  289. titleCell.setCellValue("标题");
  290. titleCell = titleRow.createCell(4);
  291. titleCell.setCellValue("策略");
  292. titleCell = titleRow.createCell(5);
  293. titleCell.setCellValue("得分");
  294. titleCell = titleRow.createCell(6);
  295. titleCell.setCellValue("HisFissionFansRateRateStrategy");
  296. titleCell = titleRow.createCell(7);
  297. titleCell.setCellValue("HisFissionAvgReadRateRateStrategy");
  298. titleCell = titleRow.createCell(8);
  299. titleCell.setCellValue("PublishTimesStrategy");
  300. titleCell = titleRow.createCell(9);
  301. titleCell.setCellValue("ViewCountRateCorrelationStrategy");
  302. titleCell = titleRow.createCell(10);
  303. titleCell.setCellValue("HisFissionAvgReadSumRateStrategy");
  304. titleCell = titleRow.createCell(11);
  305. titleCell.setCellValue("HisFissionAvgReadRateCorrelationRateStrategy");
  306. titleCell = titleRow.createCell(12);
  307. titleCell.setCellValue("HisFissionFansSumRateStrategy");
  308. titleCell = titleRow.createCell(13);
  309. titleCell.setCellValue("SimilarityStrategy");
  310. titleCell = titleRow.createCell(14);
  311. titleCell.setCellValue("ViewCountStrategy");
  312. titleCell = titleRow.createCell(15);
  313. titleCell.setCellValue("ViewCountRateStrategy");
  314. titleCell = titleRow.createCell(16);
  315. titleCell.setCellValue("HisFissionDeWeightAvgReadSumRateStrategy");
  316. titleCell = titleRow.createCell(17);
  317. titleCell.setCellValue("阅读量");
  318. titleCell = titleRow.createCell(18);
  319. titleCell.setCellValue("阅读均值");
  320. titleCell = titleRow.createCell(19);
  321. titleCell.setCellValue("阅读均值倍数");
  322. // 填充数据
  323. String title = "";
  324. for (PublishSortLog publishSortLog : sortLogList) {
  325. Map<String, Article> dateArticleMap = articleMap.get(publishSortLog.getGhId());
  326. Article article = dateArticleMap.get(publishSortLog.getDateStr());
  327. if (Objects.isNull(article) || !publishSortLog.getTitle().equals(article.getTitle())) {
  328. continue;
  329. }
  330. if (publishSortLog.getTitle().equals(title)) {
  331. continue;
  332. }
  333. title = publishSortLog.getTitle();
  334. rowNum++;
  335. Row row = sheet.createRow(rowNum);
  336. Cell cell = row.createCell(0);
  337. cell.setCellValue(publishSortLog.getDateStr());
  338. cell = row.createCell(1);
  339. cell.setCellValue(publishSortLog.getGhId());
  340. cell = row.createCell(2);
  341. cell.setCellValue(publishSortLog.getAccountName());
  342. cell = row.createCell(3);
  343. cell.setCellValue(publishSortLog.getTitle());
  344. cell = row.createCell(4);
  345. cell.setCellValue(publishSortLog.getStrategy());
  346. cell = row.createCell(5);
  347. cell.setCellValue(publishSortLog.getScore());
  348. cell = row.createCell(6);
  349. JSONObject scoreMap = JSONObject.parseObject(publishSortLog.getScoreMap());
  350. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionFansRateRateStrategy")).orElse(0.0)));
  351. cell = row.createCell(7);
  352. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionAvgReadRateRateStrategy")).orElse(0.0)));
  353. cell = row.createCell(8);
  354. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("PublishTimesStrategy")).orElse(0.0)));
  355. cell = row.createCell(9);
  356. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountRateCorrelationStrategy")).orElse(0.0)));
  357. cell = row.createCell(10);
  358. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionAvgReadSumRateStrategy")).orElse(0.0)));
  359. cell = row.createCell(11);
  360. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionAvgReadRateCorrelationRateStrategy")).orElse(0.0)));
  361. cell = row.createCell(12);
  362. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionFansSumRateStrategy")).orElse(0.0)));
  363. cell = row.createCell(13);
  364. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("SimilarityStrategy")).orElse(0.0)));
  365. cell = row.createCell(14);
  366. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountStrategy")).orElse(0.0)));
  367. cell = row.createCell(15);
  368. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountRateStrategy")).orElse(0.0)));
  369. cell = row.createCell(16);
  370. cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionDeWeightAvgReadSumRateStrategy")).orElse(0.0)));
  371. cell = row.createCell(17);
  372. cell.setCellValue(article.getShowViewCount());
  373. cell = row.createCell(18);
  374. Map<String, AccountAvgInfo> map = accountAvgInfoMap.get(article.getGhId());
  375. if (Objects.nonNull(map)) {
  376. List<String> avgMapDateList = new ArrayList<>(map.keySet());
  377. String publishDate = DateUtils.findNearestDate(avgMapDateList,
  378. DateUtils.timestampToYMDStr(article.getUpdateTime(), "yyyy-MM-dd"), "yyyy-MM-dd");
  379. AccountAvgInfo accountAvgInfo = map.get(publishDate);
  380. if (Objects.nonNull(accountAvgInfo)) {
  381. cell.setCellValue(accountAvgInfo.getReadAvg());
  382. cell = row.createCell(19);
  383. cell.setCellValue(String.format("%.3f", article.getShowViewCount() / (double) accountAvgInfo.getReadAvg()));
  384. }
  385. }
  386. }
  387. try (FileOutputStream outputStream = new FileOutputStream("/Users/wangyunpeng/Downloads/example.xlsx")) {
  388. workbook.write(outputStream);
  389. } catch (IOException e) {
  390. e.printStackTrace();
  391. } finally {
  392. try {
  393. workbook.close();
  394. } catch (IOException e) {
  395. e.printStackTrace();
  396. }
  397. }
  398. }
  399. }