mirror of
https://github.com/netzbegruenung/green-spider.git
synced 2024-05-01 16:44:51 +02:00
New rating: no network errors
This commit is contained in:
parent
92cfb4375c
commit
1f9c764a66
46
rating/no_network_errors.py
Normal file
46
rating/no_network_errors.py
Normal file
|
@ -0,0 +1,46 @@
|
|||
"""
|
||||
If all URLs could be loaded without severe network errors, this rater gives a score.
|
||||
"""
|
||||
|
||||
from rating.abstract_rater import AbstractRater
|
||||
|
||||
class Rater(AbstractRater):
|
||||
|
||||
rating_type = 'boolean'
|
||||
default_value = False
|
||||
depends_on_checks = ['responsive_layout']
|
||||
max_score = 1
|
||||
|
||||
def __init__(self, check_results):
|
||||
super().__init__(check_results)
|
||||
|
||||
def rate(self):
|
||||
value = self.default_value
|
||||
score = 0
|
||||
|
||||
found_pageloads = 0
|
||||
found_errors = 0
|
||||
for url in self.check_results['responsive_layout']:
|
||||
if self.check_results['responsive_layout'][url]['logs'] == []:
|
||||
found_pageloads += 1
|
||||
continue
|
||||
|
||||
# scan log entries for script errors
|
||||
for entry in self.check_results['responsive_layout'][url]['logs']:
|
||||
if entry['source'] != 'network':
|
||||
continue
|
||||
if entry['level'] != 'SEVERE':
|
||||
continue
|
||||
|
||||
found_errors += 1
|
||||
|
||||
if found_pageloads > 0 and found_errors == 0:
|
||||
value = True
|
||||
score = self.max_score
|
||||
|
||||
return {
|
||||
'type': self.rating_type,
|
||||
'value': value,
|
||||
'score': score,
|
||||
'max_score': self.max_score,
|
||||
}
|
Loading…
Reference in a new issue