From f788607ff771a47bc60d6a86e00b3433c40f3d2c Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 24 九月 2021 15:22:03 +0800 Subject: [PATCH] 接入视频直播 --- src/test/java/com/hxh/spring/test/LogTest.java | 382 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 379 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/hxh/spring/test/LogTest.java b/src/test/java/com/hxh/spring/test/LogTest.java index 6a14b9d..01ff850 100644 --- a/src/test/java/com/hxh/spring/test/LogTest.java +++ b/src/test/java/com/hxh/spring/test/LogTest.java @@ -1,16 +1,40 @@ package com.hxh.spring.test; +import com.google.gson.Gson; +import com.yeshi.buwan.util.StringUtil; +import com.yeshi.buwan.util.TimeUtil; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.*; public class LogTest { private final static Logger logger = LoggerFactory.getLogger(LogTest.class); + + private static List<String> loadLog(String filePath) { + List<String> list = new ArrayList<>(); + Scanner scanner = null; + try { + scanner = new Scanner(new FileInputStream(filePath)); + while (scanner.hasNextLine()) { + String text = scanner.nextLine(); + if (!StringUtil.isNullOrEmpty(text)) { + list.add(text); + } + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } finally { + scanner.close(); + } + return list; + } @Test public void testLog() throws FileNotFoundException { @@ -70,9 +94,6 @@ } - - - int p = 0; for (Iterator<Integer> its = ordersMap.keySet().iterator(); its.hasNext(); ) { Integer key = its.next(); @@ -84,4 +105,359 @@ } } + + @Test + public void videoPlay() throws Exception { + Set<String> sets = new HashSet<>(); + Set<String> totalSets = new HashSet<>(); + Gson gson = new Gson(); + Scanner scanner = new Scanner(new FileInputStream("D:\\鏂囦欢浼犺緭\\鏃ュ織\\2021_04_27.log")); + Map<String, Integer> countMap = new HashMap<>(); + List<String> videoList = new ArrayList<>(); + int ppcount = 0; + int count = 0; + while (scanner.hasNextLine()) { + count++; + String text = scanner.nextLine(); + UserVideoPlayLogInfo logInfo = gson.fromJson(text, UserVideoPlayLogInfo.class); + totalSets.add(logInfo.getUtdId()); + if ("25".equalsIgnoreCase(logInfo.getResourceId())) { + sets.add(logInfo.getUtdId()); + ppcount++; + } + if (countMap.get(logInfo.getUtdId()) == null) { + countMap.put(logInfo.getUtdId(), 0); + } + if (logInfo.getUtdId() != null && logInfo.getUtdId().equalsIgnoreCase("X8UXEo0HT/0DAMYZJa0w9lWp")) { + videoList.add(text); + } + countMap.put(logInfo.getUtdId(), countMap.get(logInfo.getUtdId()) + 1); + System.out.println(logInfo); + } + System.out.println("鎾斁UV鎬绘暟涓�:" + totalSets.size()); + System.out.println("PPTV UV鎾斁鎬绘暟涓�:" + sets.size()); + System.out.println("PPTV UV姣斾緥:" + new BigDecimal(sets.size()).divide(new BigDecimal(totalSets.size()), 2, RoundingMode.FLOOR)); + + System.out.println("鎾斁鎬绘暟涓�:" + count); + System.out.println("PPTV 鎾斁鎬绘暟涓�:" + ppcount); + System.out.println("PPTV 姣斾緥:" + new BigDecimal(ppcount).divide(new BigDecimal(count), 2, RoundingMode.FLOOR)); + + scanner.close(); + + for (String st : videoList) { + System.out.println(st); + } + } + + @Test + public void searchKey() { + Logger logger = LoggerFactory.getLogger("searchKey"); + logger.info("{}"); + } + + private void printAction(String utdId, List<UserActiveLogInfo> infoList) { + StringBuilder builder = new StringBuilder(); + + builder.append(utdId); + builder.append("#"); + Date last = null; + for (UserActiveLogInfo info : infoList) { + Date thisDate = new Date(TimeUtil.convertGernalTime(info.getTime(), "yyyy-MM-dd HH:mm:ss.SSS")); + builder.append(info.getType()); + if (last != null) { + builder.append("("); + builder.append((thisDate.getTime() - last.getTime()) + ""); + builder.append(")"); + } + if ("videoDetail".equalsIgnoreCase(info.getType())) { + builder.append(":" + info.getParams2()); + } + if ("search".equalsIgnoreCase(info.getType())) { + builder.append(":" + info.getParams1()); + } + builder.append("-"); + last = thisDate; + } + System.out.println(builder.toString()); + } + + private String getAction(List<UserActiveLogInfo> infoList) { + List<String> typeList = new ArrayList<>(); + for (UserActiveLogInfo info : infoList) { + typeList.add(info.getType()); + } + + return org.yeshi.utils.StringUtil.concat(typeList, "-"); + } + + private String getPercent(int total, int count) { + + return new BigDecimal(count).multiply(new BigDecimal(100)).divide(new BigDecimal(total), 2, RoundingMode.FLOOR) + "%"; + + } + + @Test + public void userActive() throws Exception { + Gson gson = new Gson(); + List<String> list = loadLog("D:\\鏂囦欢浼犺緭\\鏃ュ織\\active_2021_04_27.log"); + Map<String, List<UserActiveLogInfo>> map = new HashMap<>(); + for (String st : list) { + UserActiveLogInfo activeLogInfo = gson.fromJson(st, UserActiveLogInfo.class); + if (activeLogInfo != null && !StringUtil.isNullOrEmpty(activeLogInfo.getUtdId())) { + if (map.get(activeLogInfo.getUtdId()) == null) { + map.put(activeLogInfo.getUtdId(), new ArrayList<>()); + } + map.get(activeLogInfo.getUtdId()).add(activeLogInfo); + } + } + + int recommendPlay = 0; + int playCount = 0; + int searchCount = 0; + int searchPlayCount = 0; + int noSearchAndPlay = 0; + int searchNoPlay = 0; + int noComeInCount = 0; + int comeinAndNoAction = 0; + + for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) { + String key = its.next(); +// printAction(key, map.get(key)); + String actions = getAction(map.get(key)); + if (actions.contains("splash-home-videoDetail")) { + recommendPlay++; + } + if (actions.contains("videoDetail")) { + playCount++; + } + + if (actions.contains("search")) { + searchCount++; + } + + if (actions.contains("search-videoDetail")) { + searchPlayCount++; + } + + + //鎼滅储鏈挱鏀� + if (!actions.contains("search-videoDetail") && actions.contains("search")) { + searchNoPlay++; +// printAction(key, map.get(key)); + } + + if (!actions.contains("search") && !actions.contains("videoDetail")) { + noSearchAndPlay++; + } + + if (actions.contains("splash") && !actions.contains("home") && !actions.contains("search") && !actions.contains("videoDetail")) { + noComeInCount++; + printAction(key, map.get(key)); + } + + if (actions.contains("splash") && actions.contains("home") && !actions.contains("search") && !actions.contains("videoDetail")) { + comeinAndNoAction++; + } + + } + System.out.println("娲昏穬鎬绘暟锛�" + map.size()); + System.out.println("鎾斁鎬绘暟锛�" + playCount + "姣斾緥涓猴細" + getPercent(map.size(), playCount)); + System.out.println("鎺ㄨ崘鎾斁锛�" + recommendPlay + "姣斾緥涓猴細" + getPercent(map.size(), recommendPlay)); + System.out.println("鎼滅储鎬绘暟锛�" + searchCount + "姣斾緥涓猴細" + getPercent(map.size(), searchCount)); + System.out.println("鎼滅储涔嬪悗鎾斁鎬绘暟锛�" + searchPlayCount + "姣斾緥涓猴細" + getPercent(map.size(), searchPlayCount)); + System.out.println("鎼滅储涔嬪悗鏈挱鏀炬�绘暟锛�" + searchNoPlay + "姣斾緥涓猴細" + getPercent(map.size(), searchNoPlay)); + System.out.println("鏈悳绱篃鏈挱鏀炬�绘暟锛�" + noSearchAndPlay + "姣斾緥涓猴細" + getPercent(map.size(), noSearchAndPlay)); + System.out.println("鎼滅储婊℃剰搴︼細" + getPercent(searchCount, searchPlayCount)); + System.out.println("鏈兘鎴愬姛杩涘叆棣栭〉鎬绘暟锛�" + noComeInCount + "姣斾緥涓猴細" + getPercent(map.size(), noComeInCount)); + System.out.println("杩涘叆棣栭〉鍚庢棤鍔ㄤ綔鐨勬�绘暟锛�" + comeinAndNoAction + "姣斾緥涓猴細" + getPercent(map.size(), comeinAndNoAction)); + } + + + class UserVideoPlayLogInfo { + + /** + * resourceId : 25 + * detailSystemId : 44 + * device : e07f8f33-3c42-3d7f-99f0-c26e2b294117 + * utdId : YFYbx3x95gADACWMYFfQNm5Q + * time : 2021-03-21 00:00:05.866 + * videoId : 7724416 + * method : getUserVideoDetail + */ + + private String resourceId; + private String detailSystemId; + private String device; + private String utdId; + private String time; + private String videoId; + private String method; + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(String resourceId) { + this.resourceId = resourceId; + } + + public String getDetailSystemId() { + return detailSystemId; + } + + public void setDetailSystemId(String detailSystemId) { + this.detailSystemId = detailSystemId; + } + + public String getDevice() { + return device; + } + + public void setDevice(String device) { + this.device = device; + } + + public String getUtdId() { + return utdId; + } + + public void setUtdId(String utdId) { + this.utdId = utdId; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getVideoId() { + return videoId; + } + + public void setVideoId(String videoId) { + this.videoId = videoId; + } + + public String getMethod() { + return method; + } + + public void setMethod(String method) { + this.method = method; + } + } + + + class UserActiveLogInfo { + + + /** + * logName : userActive + * type : videoDetail + * device : aaad1d79-78d6-36a1-9bd1-83f489dec3ad + * time : 2021-03-22 14:04:10.663 + * utdId : X++3kU3tfqIDAP+Ug24skyKv + * params1 : 1206314 + * params2 : 鍖呴潚澶╀箣寮�灏佸妗圱V鐗� + * params3 : search + * version : 107 + * detailSystemId : 44 + */ + + private String logName; + private String type; + private String device; + private String time; + private String utdId; + private String params1; + private String params2; + private String params3; + private String version; + private String detailSystemId; + + public String getLogName() { + return logName; + } + + public void setLogName(String logName) { + this.logName = logName; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getDevice() { + return device; + } + + public void setDevice(String device) { + this.device = device; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getUtdId() { + return utdId; + } + + public void setUtdId(String utdId) { + this.utdId = utdId; + } + + public String getParams1() { + return params1; + } + + public void setParams1(String params1) { + this.params1 = params1; + } + + public String getParams2() { + return params2; + } + + public void setParams2(String params2) { + this.params2 = params2; + } + + public String getParams3() { + return params3; + } + + public void setParams3(String params3) { + this.params3 = params3; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getDetailSystemId() { + return detailSystemId; + } + + public void setDetailSystemId(String detailSystemId) { + this.detailSystemId = detailSystemId; + } + } + + } -- Gitblit v1.8.0