55from django .core .cache import cache
66from django .db import transaction
77
8- from checks .models import DomainTestReport , MailTestReport
8+ from checks .models import Fame
99from interface import redis_id
1010from interface .batch import util
1111
@@ -19,85 +19,16 @@ def __init__(self, domain):
1919 self .web_permalink = None
2020 self .mail_timestamp = None
2121 self .mail_permalink = None
22- self .mail_nomx = None
2322
2423 def __str__ (self ):
2524 return f"""------- { self .domain }
2625 web_timestamp: { self .web_timestamp }
2726 web_permalink: { self .web_permalink }
2827 mail_timestamp: { self .mail_timestamp }
2928 mail_permalink: { self .mail_permalink }
30- mail_nomx: { self .mail_nomx }
3129 """
3230
3331
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-
10132@transaction .atomic
10233def _update_hof ():
10334 """
@@ -108,28 +39,33 @@ def _update_hof():
10839 test scored 100%.
10940
11041 """
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-
11542 champions = []
11643 web = []
11744 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 } /"
13369 champions .append ({"permalink" : permalink , "domain" : entry .domain , "timestamp" : timestamp })
13470 champions = sorted (champions , key = lambda x : x ["timestamp" ], reverse = True )
13571 web = sorted (web , key = lambda x : x ["timestamp" ], reverse = True )
0 commit comments