-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats.py
78 lines (63 loc) · 2.64 KB
/
stats.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
from dataclasses import dataclass
@dataclass
class SearchStats:
browser_id: int = 0
captcha_seen: bool = False
captcha_solved: bool = False
ads_found: int = 0
num_filtered_ads: int = 0
num_excluded_ads: int = 0
ads_clicked: int = 0
non_ads_clicked: int = 0
shopping_ads_found: int = 0
num_filtered_shopping_ads: int = 0
num_excluded_shopping_ads: int = 0
shopping_ads_clicked: int = 0
def to_pre_text(self) -> str:
"""Return statistics as pre-formatted fixed-width text
:rtype: str
:returns: Statistics as html pre block
"""
lines = [
("Browser ID", self.browser_id) if self.browser_id else None,
("Captcha Seen", "Yes" if self.captcha_seen else "No"),
("Captcha Solved", "Yes" if self.captcha_solved else "No"),
("Ads Found", self.ads_found),
("Num Filtered Ads", self.num_filtered_ads),
("Num Excluded Ads", self.num_excluded_ads),
("Ads Clicked", self.ads_clicked),
("Non-ads Clicked", self.non_ads_clicked),
("Shopping Ads Found", self.shopping_ads_found),
("Num Filtered Shopping Ads", self.num_filtered_shopping_ads),
("Num Excluded Shopping Ads", self.num_excluded_shopping_ads),
("Shopping Ads Clicked", self.shopping_ads_clicked),
]
text = "<pre>Summary of Statistics"
for line in lines:
if line:
text += f"\n{line[0]:<25}: {line[1]:<8}"
text += "</pre>\n"
return text
def __str__(self):
rows = [
("Browser ID", self.browser_id) if self.browser_id else None,
("Captcha Seen", "Yes" if self.captcha_seen else "No"),
("Captcha Solved", "Yes" if self.captcha_solved else "No"),
("Ads Found", self.ads_found),
("Num Filtered Ads", self.num_filtered_ads),
("Num Excluded Ads", self.num_excluded_ads),
("Ads Clicked", self.ads_clicked),
("Non-ads Clicked", self.non_ads_clicked),
("Shopping Ads Found", self.shopping_ads_found),
("Num Filtered Shopping Ads", self.num_filtered_shopping_ads),
("Num Excluded Shopping Ads", self.num_excluded_shopping_ads),
("Shopping Ads Clicked", self.shopping_ads_clicked),
]
border = "+" + "-" * 27 + "+" + "-" * 10 + "+"
table = ["Summary of Statistics", border]
for row in rows:
if row:
row_str = f"| {row[0]:<25} | {row[1]:<8} |"
table.append(row_str)
table.append(border)
return "\n".join(table)