-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequestCountBarPlots.py
More file actions
142 lines (125 loc) · 4.23 KB
/
requestCountBarPlots.py
File metadata and controls
142 lines (125 loc) · 4.23 KB
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
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
import sys
from urllib.parse import urlparse
import os
def checkResExist(df, request_id):
return request_id in df["request_id"].values
def getInitiatorURL(stack):
if len(stack["callFrames"]) != 0:
return stack["callFrames"][0]["url"]
else:
return getInitiatorURL(stack["parent"])
def extractDigits(lst):
return list(map(lambda el: [el], lst))
def countRequests(experiment):
df1 = pd.DataFrame(
extractDigits(
os.listdir("" + experiment + "/webpage-crawler-extension/server/output")
),
columns=["website"],
)
fold = "" + experiment + "/webpage-crawler-extension/"
tracking = 0
functional = 0
for j in df1.index:
try:
df = pd.read_json(
fold + "server/output/" + df1["website"][j] + "/label_request.json"
)
res = pd.read_json(
fold + "server/output/" + df1["website"][j] + "/responses.json",
lines=True,
)
for i in df.index:
if checkResExist(res, df["request_id"][i]):
if (
df["easylistflag"][i] == 1
or df["easyprivacylistflag"][i] == 1
or df["ancestorflag"][i] == 1
):
tracking += 1
else:
functional += 1
except:
pass
return tracking, functional
def countDistribution(experiment):
df1 = pd.DataFrame(
extractDigits(
os.listdir("" + experiment + "/webpage-crawler-extension/server/output")
),
columns=["website"],
)
fold = "" + experiment + "/webpage-crawler-extension/"
tracking = 0
functional = 0
website = {}
for j in df1.index:
if df1["website"][j] not in website:
website[df1["website"][j]] = [(0, 0), (0, 0)]
try:
df = pd.read_json(
fold + "server/output/" + df1["website"][j] + "/label_request.json"
)
res = pd.read_json(
fold + "server/output/" + df1["website"][j] + "/responses.json",
lines=True,
)
for i in df.index:
if checkResExist(res, df["request_id"][i]):
if (
df["easylistflag"][i] == 1
or df["easyprivacylistflag"][i] == 1
or df["ancestorflag"][i] == 1
):
website[df1["website"][j]][0][0] += 1
else:
website[df1["website"][j]][0][1] += 1
df = pd.read_json(
"ALL/webpage-crawler-extension/server/output/"
+ df1["website"][j]
+ "/label_request.json"
)
for i in df.index:
if (
df["easylistflag"][i] == 1
or df["easyprivacylistflag"][i] == 1
or df["ancestorflag"][i] == 1
):
website[df1["website"][j]][1][0] += 1
else:
website[df1["website"][j]][1][0] += 1
except:
pass
return tracking, functional
def main():
if sys.argv[2] != "None":
data = {
"Control": countRequests("Control"),
sys.argv[1]: countRequests(sys.argv[1]),
sys.argv[2]: countRequests(sys.argv[2]),
}
else:
data = {
"Control": countRequests("Control"),
sys.argv[1]: countRequests(sys.argv[1]),
}
# Create DataFrame
df = pd.DataFrame(data.items(), columns=["experiment", "tracking, functional"])
df[["tracking", "functional"]] = pd.DataFrame(
df["tracking, functional"].tolist(), index=df.index
)
df = df[["experiment", "tracking", "functional"]]
# Plot
colors = ["#E11916", "#3FD72D"]
ax = df.plot(
kind="bar", x="experiment", y=["tracking", "functional"], color=colors, rot=0
)
ax.set_xlabel("Configuration")
ax.set_ylabel("Requests Count")
plt.show()
plt.savefig("Figures/BarPlot.pdf")
main()