From 4b74be695e78e1f4c0b53dc5bcec8c3a3823adc1 Mon Sep 17 00:00:00 2001 From: Nico Matentzoglu Date: Wed, 1 Jun 2022 12:47:27 +0300 Subject: [PATCH] Adding date back, change dashboard score function - add date updated back to ontology pages - Make sure that the dashboard score is shown on ontology pages - Show link back to overview pages - Add new function for a simpler dashboard score, see #64 - refactor URL exists check --- util/dashboard/dashboard.py | 14 ++++---- util/dashboard/fp_004.py | 14 +------- util/dashboard/fp_008.py | 12 +++---- util/dashboard_config.py | 5 ++- util/lib.py | 50 +++++++++++++++++++++++++++++ util/templates/ontology.html.jinja2 | 1 + 6 files changed, 67 insertions(+), 29 deletions(-) diff --git a/util/dashboard/dashboard.py b/util/dashboard/dashboard.py index 9fda364..6832f90 100755 --- a/util/dashboard/dashboard.py +++ b/util/dashboard/dashboard.py @@ -29,7 +29,7 @@ from argparse import ArgumentParser, FileType from py4j.java_gateway import JavaGateway -from lib import round_float, compute_dashboard_score, compute_obo_score, DashboardConfig, \ +from lib import round_float, compute_dashboard_score_alt1, compute_obo_score, DashboardConfig, \ create_dashboard_score_badge, create_dashboard_qc_badge @@ -367,7 +367,7 @@ def run(): summary_count['WARN'] = warn summary_count['INFO'] = info date = datetime.datetime.today() - save_data = {'namespace': namespace, 'version': version_iri, + save_data = {'namespace': namespace, 'version': version_iri, 'date': date, 'summary': {'status': summary, 'comment': summary_comment, 'summary_count': summary_count}, 'results': all_checks} oboscore_weights = config.get_oboscore_weights() @@ -376,8 +376,9 @@ def run(): for key in save_data: data_yml[key] = save_data[key] - obo_dashboard_score = round_float( - float(compute_dashboard_score(data_yml, oboscore_weights, oboscore_maximpacts)) / 100) + raw_dashboard_score = compute_dashboard_score_alt1(data_yml, oboscore_weights, oboscore_maximpacts) + raw_dashboard_score = float(raw_dashboard_score) / float(100) + obo_dashboard_score = round_float(float(raw_dashboard_score)) data_yml['metrics']['Info: Experimental OBO score']['_dashboard'] = obo_dashboard_score oboscore = compute_obo_score(data_yml['metrics']['Info: Experimental OBO score']['_impact'], data_yml['metrics']['Info: Experimental OBO score']['_reuse'], @@ -388,12 +389,11 @@ def run(): data_yml['metrics']['Info: Experimental OBO score']['oboscore'] = round_float(oboscore['score']) data_yml['metrics']['Info: Experimental OBO score']['_formula'] = oboscore['formula'] - - + obo_dashboard_score_pc = round_float(float((obo_dashboard_score*100))) # Save to YAML file print('Saving results to {0}'.format(dashboard_yml)) create_dashboard_qc_badge(color, ", ".join(badge_message), ontology_dir) - create_dashboard_score_badge("blue", obo_dashboard_score, ontology_dir) + create_dashboard_score_badge("blue", f"{obo_dashboard_score_pc} %", ontology_dir) with open(dashboard_yml, 'w+') as f: yaml.dump(data_yml, f) diff --git a/util/dashboard/fp_004.py b/util/dashboard/fp_004.py index 74b7e94..6537ec4 100644 --- a/util/dashboard/fp_004.py +++ b/util/dashboard/fp_004.py @@ -24,6 +24,7 @@ import dash_utils import re +from lib import url_exists import requests @@ -99,16 +100,3 @@ def big_has_versioning(file): return {'status': 'PASS'} - -def url_exists(url: str) -> bool: - # check the URL resolves, but don't download it in full - # inspired by https://stackoverflow.com/a/61404519/5775947 - try: - with requests.get(url, stream=True) as res: - rv = res.status_code == 200 - except Exception: - # Any errors with connection will be considered - # as the URL not existing - return False - else: - return rv diff --git a/util/dashboard/fp_008.py b/util/dashboard/fp_008.py index 75afd58..d77b030 100644 --- a/util/dashboard/fp_008.py +++ b/util/dashboard/fp_008.py @@ -28,8 +28,8 @@ ## ### Implementation ## The registry data is checked for 'homepage' and 'description' entries. If either is missing, this is an error. If the homepage is present, the URL is checked to see if it resolves (does not return an HTTP status of greater than 400). If the URL does not resolve, this is also an error. -import requests +from lib import url_exists def has_documentation(data): """Check fp 8 - documentation. @@ -64,12 +64,8 @@ def has_documentation(data): 'comment': 'Missing description'} # check if URL resolves - try: - request = requests.get(home) - except Exception as e: + if not url_exists(home): return {'status': 'ERROR', - 'comment': 'homepage URL ({0}) does not resolve'.format(home)} - if request.status_code > 400: - return {'status': 'ERROR', - 'comment': 'homepage URL ({0}) does not resolve'.format(home)} + 'comment': 'Homepage URL ({0}) does not resolve'.format(home)} + return {'status': 'PASS'} diff --git a/util/dashboard_config.py b/util/dashboard_config.py index c12c144..a96b68e 100755 --- a/util/dashboard_config.py +++ b/util/dashboard_config.py @@ -450,7 +450,10 @@ def prepare_ontologies(ontologies, ontology_dir, dashboard_dir, make_parameters, # Only overwrite these metrics when we actually overwrite the dashboard.. ont_results['metrics']['Info: Which ontologies use it?'] = [use for use in uses if use != o] ont_results['metrics']['Info: How many ontologies use it?'] = uses_count - ont_results['metrics']['Info: Experimental OBO score'] = dashboard_score + if 'Info: Experimental OBO score' in ont_results['metrics']: + ont_results['metrics']['Info: Experimental OBO score'].update(dashboard_score) + else: + ont_results['metrics']['Info: Experimental OBO score'] = dashboard_score save_yaml(ont_results, ont_results_path) runcmd(f"make {make_parameters} {dashboard_html}", config.get_dashboard_report_timeout_seconds()) ont_results.pop('last_ontology_dashboard_run_failed', None) diff --git a/util/lib.py b/util/lib.py index 4379f12..3c4e0ea 100644 --- a/util/lib.py +++ b/util/lib.py @@ -452,6 +452,44 @@ def compute_dashboard_score(data, weights, maximpacts): oboscore = oboscore - score_max(weights['report_info'] * report_info, maximpacts['report_info']) return "%.2f" % oboscore +def compute_dashboard_score_alt1(data, weights, maximpacts): + """Computing dashboard score based purely on the number of failed categories""" + + if 'failure' in data: + return 0 + + score = 100 + + if 'results' in data: + ct_categories = len(data['results']) + 1 # The + 1 is the requirement of having a base. + weight_per_category = float((100 / ct_categories)) + for cat in data['results']: + if 'status' in data['results'][cat]: + if data['results'][cat]['status'] == 'ERROR': + score -= weight_per_category + elif data['results'][cat]['status'] == 'WARN': + score -= (weight_per_category/3) + elif data['results'][cat]['status'] == 'INFO': + score -= (weight_per_category / 10) + elif data['results'][cat]['status'] == 'PASS': + score -= 0 + else: + logging.warning(f"compute_dashboard_score_alt1(): Results section exists but unrecognised status {data['results'][cat]['status']}.") + return 0 + else: + logging.warning( + f"compute_dashboard_score_alt1(): Results section exists but no status entry for {cat}.") + return 0 + else: + return 0 + + if 'base_generated' in data and data['base_generated'] == True: + score -= weight_per_category + + if score < 0: + score = 0 + + return "%.2f" % score def round_float(n): strfloat = "%.3f" % n @@ -514,3 +552,15 @@ def create_badge(color: str, message: str, label:str, filepath: str): json_string = json.dumps(json_data) with open(filepath, "w") as text_file: print(json_string, file=text_file) + +def url_exists(url: str) -> bool: + # check the URL resolves, but don't download it in full + # inspired by https://stackoverflow.com/a/61404519/5775947 + try: + with requests.get(url, stream=True) as res: + return (res.status_code == 200) + except Exception as e: + # Any errors with connection will be considered + # as the URL not existing + logging.error(e, exc_info=True) + return False diff --git a/util/templates/ontology.html.jinja2 b/util/templates/ontology.html.jinja2 index 909c497..ff42c71 100644 --- a/util/templates/ontology.html.jinja2 +++ b/util/templates/ontology.html.jinja2 @@ -11,6 +11,7 @@

Version: {{ o.version }}

Date run: {{ o.date }}

View dashboard results as YAML

+

Go back to Overview

Error Breakdown

{% set summary = o.summary %} {% if 'comment' in summary %}