mirror of
https://github.com/netzbegruenung/green-spider.git
synced 2024-05-06 02:43:42 +02:00
Marian Steinbach
618e29d763
* CLI: remove 'jobs' command, add 'manager' * Add job definition * Move jobs to manage folder * Rename jobs to manager * Add rq and redis dependencies * Add docker-compose YAML * Downgrade to alpine 3.8 * Adjust paths in Dockerfile, remove entrypoint * Rename 'make spiderjobs' to 'make jobs' * Fix docker exectution * Adapt 'make jobs' * Fix metadata scheme * Add docker dependency * Rendomize queue (a bit) * Use latest image, remove debug output * Make docker-compose file downwards-compatible * Use latest instead of dev image tag * Update docker-compose.yaml * Adapt job start script * Fix redis connection in manager * Add support for increasing timeout via environment variable * Adapt load_in_browser to cookies table schema change * Fix execution * Mitigate yaml warning * Bump some dependency versions * Report resource usage stats for each job * checks/load_in_browser: Return DOM size, prevent multiple page loads * Update .dockerignore * Code update * Script update * Update README.md * WIP * WIP commit * Update Dockerfile to alpine:edge and chromium v90 * Update TestCertificateChecker * Set defaults for __init__ function * Detect sunflower theme * Update unit test for new datetime (zero-basing) * Set logging prefs from Chromium in a new way * Move datastore client instantiation As it is not needed for all commands * Change green-directory repository URL * Add git settings for cloning green-directory * Pin alpine version 3.14, fix py3-cryptography * Use plain docker build progress output * Add volumes to 'make test' docker run command * Fix bug * Update example command in README * Update dependencies * Add creation of Kubernetes jobs
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
"""
|
|
This looks at the response duration(s) and scores based on the bucket
|
|
the value is in. Fast responses get one point, slower half a point,
|
|
more than a seconds gets nothing.
|
|
"""
|
|
|
|
from rating.abstract_rater import AbstractRater
|
|
|
|
class Rater(AbstractRater):
|
|
|
|
rating_type = 'number'
|
|
default_value = 0
|
|
depends_on_checks = ['page_content']
|
|
max_score = 1.0
|
|
|
|
def __init__(self, check_results):
|
|
super().__init__(check_results)
|
|
|
|
def rate(self):
|
|
value = self.default_value
|
|
score = 0
|
|
|
|
duration_sum = 0
|
|
duration_count = 0
|
|
|
|
for url in self.check_results['page_content']:
|
|
if self.check_results['page_content'][url]['exception'] is not None:
|
|
continue
|
|
duration_sum += self.check_results['page_content'][url]['duration']
|
|
duration_count += 1
|
|
|
|
if duration_count > 0:
|
|
value = round(duration_sum / duration_count)
|
|
|
|
# value is duration in milliseconds
|
|
if value < 100:
|
|
score = self.max_score
|
|
elif value < 1000:
|
|
score = self.max_score * 0.5
|
|
|
|
return {
|
|
'type': self.rating_type,
|
|
'value': value,
|
|
'score': score,
|
|
'max_score': self.max_score,
|
|
}
|