|
@@ -16,6 +16,8 @@ import com.tzld.longarticle.recommend.server.repository.crawler.PublishSortLogRe
|
|
|
import com.tzld.longarticle.recommend.server.service.RecommendService;
|
|
|
import com.tzld.longarticle.recommend.server.service.recall.RecallService;
|
|
|
import com.tzld.longarticle.recommend.server.util.DateUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.math3.stat.correlation.PearsonsCorrelation;
|
|
|
import org.apache.poi.ss.usermodel.Cell;
|
|
|
import org.apache.poi.ss.usermodel.Row;
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
@@ -25,12 +27,16 @@ import org.junit.jupiter.api.Test;
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.nio.file.Files;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@SpringBootTest(classes = Application.class)
|
|
|
+@Slf4j
|
|
|
public class RecommendTest {
|
|
|
|
|
|
@Resource
|
|
@@ -542,4 +548,128 @@ public class RecommendTest {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void getScoreFromLogFile() {
|
|
|
+
|
|
|
+ String folderPath = "/Users/wangyunpeng/Downloads/b78020b8-d9df-466f-bd01-cd982bb986d0.json";
|
|
|
+
|
|
|
+ File file = new File(folderPath);
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet("ExampleSheet");
|
|
|
+ int rowNum = 0;
|
|
|
+ // 创建标题行
|
|
|
+ Row titleRow = sheet.createRow(rowNum);
|
|
|
+ Cell titleCell = titleRow.createCell(0);
|
|
|
+ titleCell.setCellValue("日期");
|
|
|
+ titleCell = titleRow.createCell(1);
|
|
|
+ titleCell.setCellValue("账号名称");
|
|
|
+ titleCell = titleRow.createCell(2);
|
|
|
+ titleCell.setCellValue("id");
|
|
|
+ titleCell = titleRow.createCell(3);
|
|
|
+ titleCell.setCellValue("标题");
|
|
|
+ titleCell = titleRow.createCell(4);
|
|
|
+ titleCell.setCellValue("策略");
|
|
|
+ titleCell = titleRow.createCell(5);
|
|
|
+ titleCell.setCellValue("得分");
|
|
|
+ titleCell = titleRow.createCell(6);
|
|
|
+ titleCell.setCellValue("HisFissionFansRateRateStrategy");
|
|
|
+ titleCell = titleRow.createCell(7);
|
|
|
+ titleCell.setCellValue("HisFissionAvgReadRateRateStrategy");
|
|
|
+ titleCell = titleRow.createCell(8);
|
|
|
+ titleCell.setCellValue("PublishTimesStrategy");
|
|
|
+ titleCell = titleRow.createCell(9);
|
|
|
+ titleCell.setCellValue("ViewCountRateCorrelationStrategy");
|
|
|
+ titleCell = titleRow.createCell(10);
|
|
|
+ titleCell.setCellValue("HisFissionAvgReadSumRateStrategy");
|
|
|
+ titleCell = titleRow.createCell(11);
|
|
|
+ titleCell.setCellValue("HisFissionAvgReadRateCorrelationRateStrategy");
|
|
|
+ titleCell = titleRow.createCell(12);
|
|
|
+ titleCell.setCellValue("HisFissionFansSumRateStrategy");
|
|
|
+ titleCell = titleRow.createCell(13);
|
|
|
+ titleCell.setCellValue("SimilarityStrategy");
|
|
|
+ titleCell = titleRow.createCell(14);
|
|
|
+ titleCell.setCellValue("ViewCountStrategy");
|
|
|
+ titleCell = titleRow.createCell(15);
|
|
|
+ titleCell.setCellValue("ViewCountRateStrategy");
|
|
|
+ titleCell = titleRow.createCell(16);
|
|
|
+ titleCell.setCellValue("HisFissionDeWeightAvgReadSumRateStrategy");
|
|
|
+ try {
|
|
|
+ String content = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8);
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(content);
|
|
|
+ for (Object o : jsonArray) {
|
|
|
+ JSONObject jsonObject = (JSONObject) o;
|
|
|
+ Long time = jsonObject.getLong("__time__");
|
|
|
+ String message = jsonObject.getString("message");
|
|
|
+ int index = message.indexOf("[");
|
|
|
+ String info = message.substring(0, index);
|
|
|
+ String strategy = info.substring(0, info.indexOf(" "));
|
|
|
+ String accountName = info.substring(info.indexOf(" ")).replace("账号名称 ", "")
|
|
|
+ .replace(" 头条评分结果", "");
|
|
|
+ String json = message.substring(index);
|
|
|
+ JSONArray scoreArray = JSONArray.parseArray(json);
|
|
|
+ for (Object scoreJSON : scoreArray) {
|
|
|
+ JSONObject scoreObject = (JSONObject) scoreJSON;
|
|
|
+ String id = scoreObject.getString("id");
|
|
|
+ String title = scoreObject.getString("title");
|
|
|
+ String score = scoreObject.getString("score");
|
|
|
+ String scoreMapStr = scoreObject.getString("scoreMap");
|
|
|
+ rowNum++;
|
|
|
+ Row row = sheet.createRow(rowNum);
|
|
|
+ Cell cell = row.createCell(0);
|
|
|
+ cell.setCellValue(DateUtils.timestampToYMDStr(time, "yyyyMMdd"));
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue(accountName);
|
|
|
+ cell = row.createCell(2);
|
|
|
+ cell.setCellValue(id);
|
|
|
+ cell = row.createCell(3);
|
|
|
+ cell.setCellValue(title);
|
|
|
+ cell = row.createCell(4);
|
|
|
+ cell.setCellValue(strategy);
|
|
|
+ cell = row.createCell(5);
|
|
|
+ cell.setCellValue(score);
|
|
|
+ cell = row.createCell(6);
|
|
|
+ JSONObject scoreMap = JSONObject.parseObject(scoreMapStr);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionFansRateRateStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(7);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionAvgReadRateRateStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(8);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("PublishTimesStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(9);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountRateCorrelationStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(10);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionAvgReadSumRateStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(11);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionAvgReadRateCorrelationRateStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(12);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionFansSumRateStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(13);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("SimilarityStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(14);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(15);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("ViewCountRateStrategy")).orElse(0.0)));
|
|
|
+ cell = row.createCell(16);
|
|
|
+ cell.setCellValue(String.format("%.3f", Optional.of(scoreMap.getDoubleValue("HisFissionDeWeightAvgReadSumRateStrategy")).orElse(0.0)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try (FileOutputStream outputStream = new FileOutputStream("/Users/wangyunpeng/Downloads/example.xlsx")) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("readFileError fileName:{}", file.getName(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|