From da15e439e64c8314825ad5f28073fbcbd436946f Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Thu, 30 May 2019 13:29:31 +0100 Subject: Initial version of demo This commit introduces the demo functionality. The task assignment has been removed at the moment, as this will be changed in a future commit. --- app/utils/datasets.py | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'app/utils') diff --git a/app/utils/datasets.py b/app/utils/datasets.py index 74785cb..1fef85f 100644 --- a/app/utils/datasets.py +++ b/app/utils/datasets.py @@ -41,7 +41,7 @@ import re from flask import current_app -logger = logging.getLogger(__file__) +LOGGER = logging.getLogger(__file__) def validate_dataset(filename): @@ -95,6 +95,32 @@ def get_name_from_dataset(filename): return data["name"] +def dataset_is_demo(filename): + with open(filename, "rb") as fid: + data = json.load(fid) + return "demo" in data + + +def get_demo_true_cps(name): + dataset_dir = os.path.join( + current_app.instance_path, current_app.config["DATASET_DIR"] + ) + target_filename = os.path.join(dataset_dir, name + ".json") + if not os.path.exists(target_filename): + LOGGER.error("Dataset with name '%s' can't be found!" % name) + return None + with open(target_filename, "rb") as fid: + data = json.load(fid) + if not "demo" in data: + LOGGER.error("Asked for 'demo' key in non-demo dataset '%s'" % name) + return None + if not "true_CPs" in data["demo"]: + LOGGER.error( + "Expected field'true_cps' field missing for dataset '%s'" % name + ) + return data["demo"]["true_CPs"] + + def md5sum(filename): """ Compute the MD5 hash for a given filename """ blocksize = 65536 @@ -112,8 +138,11 @@ def load_data_for_chart(name, known_md5): current_app.instance_path, current_app.config["DATASET_DIR"] ) target_filename = os.path.join(dataset_dir, name + ".json") + if not os.path.exists(target_filename): + LOGGER.error("Dataset with name '%s' can't be found!" % name) + return None if not md5sum(target_filename) == known_md5: - logger.error( + LOGGER.error( """ MD5 checksum failed for dataset with name: %s. Found: %s. -- cgit v1.2.3