5
5
from django .core .cache import cache
6
6
from django .db import transaction
7
7
8
- from checks .models import DomainTestReport , MailTestReport
8
+ from checks .models import Fame
9
9
from interface import redis_id
10
10
from interface .batch import util
11
11
@@ -19,85 +19,16 @@ def __init__(self, domain):
19
19
self .web_permalink = None
20
20
self .mail_timestamp = None
21
21
self .mail_permalink = None
22
- self .mail_nomx = None
23
22
24
23
def __str__ (self ):
25
24
return f"""------- { self .domain }
26
25
web_timestamp: { self .web_timestamp }
27
26
web_permalink: { self .web_permalink }
28
27
mail_timestamp: { self .mail_timestamp }
29
28
mail_permalink: { self .mail_permalink }
30
- mail_nomx: { self .mail_nomx }
31
29
"""
32
30
33
31
34
- def _create_hof_entry (hof , domain_name ):
35
- """
36
- Create an entry in the Hall of Fame.
37
-
38
- """
39
- if domain_name in hof :
40
- return hof [domain_name ]
41
- hof [domain_name ] = HOFEntry (domain_name )
42
- return hof [domain_name ]
43
-
44
-
45
- def _update_web_entry (hof , domain_name , report_id , timestamp ):
46
- """
47
- Update a web entry in the Hall of Fame.
48
-
49
- """
50
- entry = _create_hof_entry (hof , domain_name )
51
- entry .web_timestamp = timestamp
52
- entry .web_permalink = f"/site/{ domain_name } /{ report_id } /"
53
-
54
-
55
- def _update_mail_entry (hof , domain_name , report_id , timestamp ):
56
- """
57
- Update a mail entry in the Hall of Fame.
58
-
59
- """
60
- entry = _create_hof_entry (hof , domain_name )
61
- entry .mail_timestamp = timestamp
62
- entry .mail_permalink = f"/mail/{ domain_name } /{ report_id } /"
63
- report = MailTestReport .objects .get (id = report_id )
64
- ipv6_report = report .ipv6 .report
65
- if not isinstance (ipv6_report , dict ):
66
- return
67
- entry .mail_nomx = ipv6_report ["mx_aaaa" ]["verdict" ] == "detail mail ipv6 mx-AAAA verdict other"
68
-
69
-
70
- def _populate_HOF (hof , model , entry_creation ):
71
- """
72
- Find entries that qualify for the Hall of Fame.
73
-
74
- """
75
- previousname = None
76
- previousscore = 0
77
- previoustimestamp = None
78
- previousreportid = None
79
- for report in model .objects .all ().order_by ("domain" , "timestamp" ):
80
- if previousname != report .domain and previousname is not None :
81
- if previousscore >= 100 :
82
- entry_creation (hof , previousname , previousreportid , previoustimestamp )
83
- previousname = report .domain
84
- previousscore = report .score or 0
85
- previoustimestamp = report .timestamp
86
- previousreportid = report .id
87
-
88
- else :
89
- report_score = report .score or 0
90
- if report_score != previousscore :
91
- previoustimestamp = report .timestamp
92
- previousname = report .domain
93
- previousreportid = report .id
94
- previousscore = report_score
95
-
96
- # Last domain name.
97
- if previousscore >= 100 :
98
- entry_creation (hof , previousname , previousreportid , previoustimestamp )
99
-
100
-
101
32
@transaction .atomic
102
33
def _update_hof ():
103
34
"""
@@ -108,28 +39,33 @@ def _update_hof():
108
39
test scored 100%.
109
40
110
41
"""
111
- hof = dict ()
112
- for model , entry_creation in ((DomainTestReport , _update_web_entry ), (MailTestReport , _update_mail_entry )):
113
- _populate_HOF (hof , model , entry_creation )
114
-
115
42
champions = []
116
43
web = []
117
44
mail = []
118
- for entry in hof .values ():
119
- is_web = False
120
- is_mail = False
121
- if entry .web_permalink :
122
- web .append ({"permalink" : entry .web_permalink , "domain" : entry .domain , "timestamp" : entry .web_timestamp })
123
- is_web = True
124
- if entry .mail_permalink :
125
- mail .append ({"permalink" : entry .mail_permalink , "domain" : entry .domain , "timestamp" : entry .mail_timestamp })
126
- is_mail = True
127
- if is_web and is_mail :
128
- timestamp = entry .mail_timestamp
129
- permalink = entry .mail_permalink
130
- if entry .web_timestamp > entry .mail_timestamp :
131
- timestamp = entry .web_timestamp
132
- permalink = entry .web_permalink
45
+
46
+ for entry in Fame .objects .all ().iterator ():
47
+ if entry .site_report_id is not None :
48
+ web .append (
49
+ {
50
+ "permalink" : f"/site/{ entry .domain } /{ entry .site_report_id } /" ,
51
+ "domain" : entry .domain ,
52
+ "timestamp" : entry .site_report_timestamp ,
53
+ }
54
+ )
55
+ if entry .mail_report_id is not None :
56
+ mail .append (
57
+ {
58
+ "permalink" : f"/mail/{ entry .domain } /{ entry .mail_report_id } /" ,
59
+ "domain" : entry .domain ,
60
+ "timestamp" : entry .mail_report_timestamp ,
61
+ }
62
+ )
63
+ if entry .site_report_id is not None and entry .mail_report_id is not None :
64
+ timestamp = entry .mail_report_timestamp
65
+ permalink = f"/mail/{ entry .domain } /{ entry .mail_report_id } /"
66
+ if entry .site_report_timestamp > entry .mail_report_timestamp :
67
+ timestamp = entry .site_report_timestamp
68
+ permalink = f"/site/{ entry .domain } /{ entry .site_report_id } /"
133
69
champions .append ({"permalink" : permalink , "domain" : entry .domain , "timestamp" : timestamp })
134
70
champions = sorted (champions , key = lambda x : x ["timestamp" ], reverse = True )
135
71
web = sorted (web , key = lambda x : x ["timestamp" ], reverse = True )
0 commit comments