admin
2021-09-24 f788607ff771a47bc60d6a86e00b3433c40f3d2c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
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 {
        int count = 0;
        String path = "";
        Scanner scanner = new Scanner(new FileInputStream("C:\\Users\\Administrator\\Desktop\\日志\\布丸播放\\video_play.2021-03-12.log"));
        while (scanner.hasNextLine()) {
            String text = scanner.nextLine();
            if (text != null && text.contains("getUserVideoDetail:")) {
                String content = text.split("getUserVideoDetail:")[1];
                content = content.replace("##", "# #");
                String[] sts = content.split("#");
                // device,utdId, loginUid, detailSystemId, videoId, resourceId, from
                resource(sts[4]);
                video(sts[3]);
 
                count++;
            }
        }
        scanner.close();
        System.out.println(count);
        printMap(resourceMap);
        printMap(videoMap);
    }
 
    Map<String, Integer> resourceMap = new HashMap<>();
 
 
    private void resource(String resourceId) {
        Integer r = resourceMap.get(resourceId);
        if (r == null) {
            resourceMap.put(resourceId, 0);
        }
        resourceMap.put(resourceId, resourceMap.get(resourceId) + 1);
    }
 
    Map<String, Integer> videoMap = new HashMap<>();
 
    private void video(String videoId) {
        Integer r = videoMap.get(videoId);
        if (r == null) {
            videoMap.put(videoId, 0);
        }
        videoMap.put(videoId, videoMap.get(videoId) + 1);
    }
 
    private void printMap(Map<String, Integer> map) {
        //list排序
        TreeMap<Integer, Set<String>> ordersMap = new TreeMap<>(Comparator.reverseOrder());
        for (Iterator<String> its = map.keySet().iterator(); its.hasNext(); ) {
            String key = its.next();
            Integer value = map.get(key);
            if (ordersMap.get(value) == null) {
                ordersMap.put(value, new HashSet<>());
            }
            ordersMap.get(value).add(key);
        }
 
 
        int p = 0;
        for (Iterator<Integer> its = ordersMap.keySet().iterator(); its.hasNext(); ) {
            Integer key = its.next();
            System.out.println(key + ":" + ordersMap.get(key));
            p++;
            if (p > 100) {
                break;
            }
        }
    }
 
 
    @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 : 包青天之开封奇案TV版
         * 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;
        }
    }
 
 
}