Skip to content

Commit

Permalink
Merge pull request #114 from OBOFoundry/jss/save-json
Browse files Browse the repository at this point in the history
(In addition to existing YAML output.) JSON can be parsed natively by Javascript runtimes so it's easier for other client-facing services (eg the central obofoundry table) to consume.

 * would resolve OBOFoundry/obo-dash.github.io#16
  • Loading branch information
jsstevenson authored May 6, 2024
2 parents fb5464e + b3ddc47 commit cb1266f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions util/create_dashboard_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import datetime
import os
import sys
import yaml

from argparse import ArgumentParser

import yaml
from jinja2 import Template
from lib import DashboardConfig, count_up, save_yaml, round_float, compute_dashboard_score, compute_obo_score
from lib import DashboardConfig, save_json, save_yaml


def main(args):
Expand Down Expand Up @@ -90,6 +90,7 @@ def main(args):
dashboard_score_data['oboscore']['dashboard_score_weights'] = oboscore_weights
dashboard_score_data['oboscore']['dashboard_score_max_impact'] = oboscore_maximpacts
save_yaml(dashboard_score_data, dashboard_score_data_file)
save_json(dashboard_score_data, dashboard_score_data_file.replace('.yml', '.json'))


def get_ontology_order(data):
Expand Down
9 changes: 9 additions & 0 deletions util/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,15 @@ def save_yaml(dictionary, file_path):
yaml.dump(dictionary, file)


def save_json(dictionary, file_path):
def datetime_serializer(o):
if isinstance(o, datetime):
return o.isoformat()
raise TypeError("Type not serializable")

with open(file_path, 'w', encoding='utf-8') as file:
json.dump(dictionary, file, default=datetime_serializer, indent=2)


def get_hours_since(timestamp):
modified_date = datetime.fromtimestamp(timestamp)
Expand Down

0 comments on commit cb1266f

Please sign in to comment.