Skip to content

Commit

Permalink
Adding date back, change dashboard score function
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
matentzn committed Jun 1, 2022
1 parent 20d73db commit 4b74be6
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 29 deletions.
14 changes: 7 additions & 7 deletions util/dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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()
Expand All @@ -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'],
Expand All @@ -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)
Expand Down
14 changes: 1 addition & 13 deletions util/dashboard/fp_004.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import dash_utils
import re
from lib import url_exists

import requests

Expand Down Expand Up @@ -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
12 changes: 4 additions & 8 deletions util/dashboard/fp_008.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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'}
5 changes: 4 additions & 1 deletion util/dashboard_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions util/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions util/templates/ontology.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<p class="lead"><b>Version</b>: {{ o.version }}</p>
<p class="lead" style="margin-top:-15px;"><b>Date run</b>: {{ o.date }}</p>
<p class="lead" style="margin-top:-15px;"><a href="dashboard.yml">View dashboard results as YAML</a></p>
<p class="lead" style="margin-top:-15px;"><a href="../index.html">Go back to Overview</a></p>
<h3>Error Breakdown</h3>
{% set summary = o.summary %}
{% if 'comment' in summary %}
Expand Down

0 comments on commit 4b74be6

Please sign in to comment.