-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.py
192 lines (143 loc) · 5.76 KB
/
parse.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
import json
import ast
from collections import defaultdict
domains = []
# open file and read the content in a list
with open('alexa50-200.txt', 'r') as filehandle:
for line in filehandle:
# remove linebreak which is the last character of the string
currentPlace = line[:-1]
# add item to the list
domains.append(currentPlace)
allFiles = ["DOMinoRun.txt", "plusPlusRun.txt", "controlRun.txt"]
plusplus_domainMap = {}
control_domainMap = {}
for fileName in allFiles:
if "DOMino" in fileName:
continue
# Using readlines()
file1 = open(fileName, 'r')
Lines = file1.readlines()
count = 0
# { domain : [ [Time to DOMContentLoaded] , [conversion time] ] }
test_domainMap = {}
for line in Lines:
# [11788:14032:1112/042852.933:INFO:CONSOLE(102)] "Conversion time: 6.584999999176944", source: https://www.google.com/ (102)
unreachableDomainErrors = ["ERROR PRINTING OCCURED FOR THIS DOMAIN", "*NEEDS TO TRY HTTP*", "^FAILURE, SITE NOT REACHABLE^"]
if line.strip() in domains:
continue
if line.strip() in unreachableDomainErrors:
continue
trimmed = line.strip()
try:
jsonObj = ast.literal_eval(trimmed)
except:
print("FAILED HERE")
print(trimmed)
continue
# print(jsonObj)
if "Conversion time" in jsonObj['message']:
# print('here')
forDomain = jsonObj['message'].split(' ')
# print(forDomain[0])
domainName = forDomain[0]
# print(jsonObj['message'])
forValue = jsonObj['message'].split(': ')
print("forVal")
measuredMs = float(forValue[1])
print(measuredMs)
if domainName not in test_domainMap:
test_domainMap[domainName] = ([], [])
else:
test_domainMap[domainName][1].append(measuredMs)
# print(count)
if "Time to DOMContentLoaded" in jsonObj['message']:
# print('here')
forDomain = jsonObj['message'].split(' ')
# print(forDomain[0])
domainName = forDomain[0]
# print(jsonObj['message'])
forValue = jsonObj['message'].split(': ')
measuredMs = float(forValue[1])
# print(measuredMs)
if domainName not in test_domainMap:
test_domainMap[domainName] = ([], [])
else:
test_domainMap[domainName][0].append(measuredMs)
# print(count)
count += 1
print("TEST MAP: ")
print(test_domainMap)
print("\n")
print("TEST MAP: ")
for url in test_domainMap.keys():
print("\n")
print(url)
if len(test_domainMap[url][0]) > 0:
print("Time to DOMContentLoaded: " + url + " " + str(sum(test_domainMap[url][0])/len(test_domainMap[url][0])))
if len(test_domainMap[url][1]) > 0:
print("Conversion time: " + url + " " + str(sum(test_domainMap[url][1])/len(test_domainMap[url][1])))
if "control" in fileName:
for url in test_domainMap.keys():
# if url not in domains:
# continue
control_domainMap[url] = test_domainMap[url]
else:
for url in test_domainMap.keys():
# if url not in domains:
# continue
plusplus_domainMap[url] = test_domainMap[url]
# print(control_domainMap)
controlAverage = 0
for url in control_domainMap.keys():
if len(control_domainMap[url][0]) > 0:
avg = sum(control_domainMap[url][0]) / len(control_domainMap[url][0])
controlAverage += avg
print(url + ": " + str(avg))
controlAverage = controlAverage / len(control_domainMap.keys())
print("-----------------------")
testAverage = 0
eventConversion = 0
convertedCount = 0
for url in plusplus_domainMap.keys():
if len(plusplus_domainMap[url][0]) > 0:
avg = sum(plusplus_domainMap[url][0]) / len(plusplus_domainMap[url][0])
print(url + ": " + str(avg))
if (len(plusplus_domainMap[url][1]) == 0):
continue
convertedCount += 1
conversionAvg = sum(plusplus_domainMap[url][1]) / len(plusplus_domainMap[url][1])
eventConversion += conversionAvg
ratio = conversionAvg / avg
testAverage += ratio
eventConversion = eventConversion / convertedCount
testAverage = testAverage / convertedCount
print("-----------------------")
print("CONVERSION TIME")
print("-----------------------")
for url in plusplus_domainMap.keys():
if len(plusplus_domainMap[url][1]) > 0:
avg = sum(plusplus_domainMap[url][1]) / len(plusplus_domainMap[url][1])
print(url + ": " + str(avg))
print("-----------------------")
print("PERCENTS")
print("-----------------------")
# print(plusplus_domainMap)
percMap = {}
for url in control_domainMap.keys():
try:
keyCheck = len(control_domainMap[url][0]) > 0 and len(plusplus_domainMap[url][0]) > 0
except:
continue
if len(control_domainMap[url][0]) > 0 and len(plusplus_domainMap[url][0]) > 0:
converted = sum(control_domainMap[url][0]) / len(control_domainMap[url][0])
timeToDOMContentLoaded = sum(plusplus_domainMap[url][0]) / len(plusplus_domainMap[url][0])
percent = converted / timeToDOMContentLoaded
print(url + ": " + str(percent))
percMap[url] = percent
# Overhead measurements
finalAvg = sum(percMap.values()) / len(percMap.values())
print("FINAL AVG: " + str(finalAvg))
print(controlAverage)
print(conversionAvg)
print(testAverage)