-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_log.py
213 lines (143 loc) · 4.86 KB
/
parse_log.py
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
import logging, logging.config
import constants
import os
import datetime
import time
import collections
import numpy as np
logging.config.fileConfig('logging.conf')
def parse_UB_log():
datapath = constants.LOG_DIR + '/'
clicked_by_zoom = collections.OrderedDict()
last = ''
tot_onshow_time = []
tot_clicked_time = []
tot_zoom_arr = []
for root, directories, files in os.walk(datapath):
for filename in files:
zoom_time = []
onShowTopics_time = []
clicked_time = []
zoom_levels = []
with open(datapath + filename, 'r', encoding = 'UTF-8') as f:
lines = f.readlines()
zoom_level = '10'
zoom_levels.append(zoom_level)
for line in lines:
if line.find("[UB]") > 0:
v = line[:-1].split(' ')
if line.find("onShowTopics()") > 0:
onShowTopics_time.append(v[0])
elif line.find("Zoom") > 0:
zoom_level = v[6]
zoom_time.append(v[0])
zoom_levels.append(zoom_level)
elif line.find("A word clicked") > 0:
clicked_time.append(v[0])
if zoom_level not in clicked_by_zoom:
clicked_by_zoom[zoom_level] =0
clicked_by_zoom[zoom_level] +=1
last = v[0]
tot_onshow_time.extend(compute_time_consumed(onShowTopics_time, last))
tot_clicked_time.extend(compute_time_consumed(clicked_time, last))
tot_zoom_arr.extend(compute_zoom_time(zoom_time, last, onShowTopics_time[0], zoom_levels))
onshow_time = np.array(tot_onshow_time)
clicked_time = np.array(tot_clicked_time)
print('onshow time mean : '+ str(np.mean(onshow_time)) + ' variance: ' + str(np.var(onshow_time)))
print('clicked time mean : '+ str(np.mean(clicked_time)) + ' variance: ' + str(np.var(clicked_time)))
print(clicked_by_zoom)
print(time_by_zoom(tot_zoom_arr))
#print(zoom_arr)
#print(compute_time_consumed(clicked_time, last))
#print(clicked_by_zoom)
# for i in range(0,len(onShowTopics_time)):
# time_consumed = 0
# time_1 = convert_time_to_second(onShowTopics_time[i])
# if i == len(onShowTopics_time) - 1 :
# last_time = convert_time_to_second(last)
# time_consumed = last_time - time_1
# else :
# time_2 = convert_time_to_second(onShowTopics_time[i+1])
# time_consumed = time_2 - time_1
# if()
# x = time.strptime(onShowTopics_time[i].split(',')[0],'%H:%M:%S')
# print(datetime.timedelta(hours=x.tm_hour,minutes=x.tm_min,seconds=x.tm_sec).total_seconds())
def convert_time_to_second(time_str):
time, ms = time_str.split('.')
h, m, s = time.split(':')
return int(h) * 3600 + int(m)*60 + int(s)
def compute_time_consumed(arr, last):
time_arr = []
for i in range(0, len(arr)):
time_consumed = 0
time_1 = convert_time_to_second(arr[i])
if i == len(arr) - 1 :
last_time = convert_time_to_second(last)
time_consumed = last_time - time_1
else :
time_2 = convert_time_to_second(arr[i+1])
time_consumed = time_2 - time_1
if time_consumed < 300 and time_consumed > 0:
time_arr.append(time_consumed)
return time_arr
def compute_zoom_time(arr, last, start, zoom):
time_arr = []
zoom_arr = []
for i in range(0, len(arr)):
time_consumed = 0
time_1 = convert_time_to_second(arr[i])
if i == 0 :
start_time = convert_time_to_second(start)
time_consumed = time_1 - start_time
elif i == len(arr) - 1 :
last_time = convert_time_to_second(last)
time_consumed = last_time - time_1
else:
time_2 = convert_time_to_second(arr[i+1])
time_consumed = time_2 - time_1
# print(time_consumed)
time = {}
time['time_consumed'] = time_consumed
time['zoom'] = zoom[i]
time_arr.append(time)
return time_arr
def time_by_zoom(dictionary):
tot = []
for i in range(9,14):
temp_arr = []
for element in dictionary:
if element.get("zoom") == str(i):
temp_arr.append(element.get("time_consumed"))
temp_np = np.array(temp_arr)
temp_mean = np.mean(temp_np)
temp_var = np.var(temp_np)
temp = {}
temp['zoom'] = i
temp['mean'] = temp_mean
temp['var'] = temp_var
tot.append(temp)
return tot
def Parse_log_info(filename):
datapath = constants.LOG_DIR + '/'
onShowTopic_time = []
Zoom_time = []
word_clicked =[]
with open(datapath + filename, 'r', encoding = 'UTF-8') as f:
lines = f.readlines()
for line in lines:
if line.find("[UB]") > 0:
v = line.split(' ')
if line.find("onShowTopics()") > 0:
#print(v[0])
onShowTopic_time.append(v[0])
elif line.find("Zoom") > 0:
zoom = {}
zoom['level'] = v[6]
zoom['time'] = v[0]
Zoom_time.append(zoom)
elif line.find("A word clicked") > 0:
print(v)
print(v[0])
word_clicked.append(v[0])
parse_UB_log()
#Parse_log_info('163.152.20.64-1505456434529_sujong')