Add the green power Rater class

This commit is contained in:
Chris Adams 2019-08-31 12:58:04 +02:00
parent 27d5661dba
commit 4f626947d2
2 changed files with 33 additions and 0 deletions

View File

@ -20,6 +20,7 @@ from rating import responsive_layout
from rating import social_media_links
from rating import use_specific_fonts
from rating import www_optional
from rating import green_power
def calculate_rating(results):
@ -47,6 +48,7 @@ def calculate_rating(results):
'SOCIAL_MEDIA_LINKS': social_media_links,
'USE_SPECIFIC_FONTS': use_specific_fonts,
'WWW_OPTIONAL': www_optional,
'GREEN_POWER': green_power,
}
output = {}

31
rating/green_power.py Normal file
View File

@ -0,0 +1,31 @@
"""
This checks the result for an url using green power, and returns
a boolean based on whether it's using green power or not
"""
from rating.abstract_rater import AbstractRater
class Rater(AbstractRater):
rating_type = 'boolean'
default_value = False
depends_on_checks = ['green_power']
max_score = 1
def __init__(self, check_results):
super().__init__(check_results)
def rate(self):
value = self.default_value
score = 0
if check_results['green_power']:
value = True
score = self.max_score
return {
'type': self.rating_type,
'value': value,
'score': score,
'max_score': self.max_score,
}