From 190e1c7cb924ac9598956ac0f2be37ed3915ab23 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 23 Jan 2025 11:23:05 -0600 Subject: Provide summary for review before entering data to database. --- uploader/phenotypes/views.py | 76 +++++++++++++++- uploader/templates/phenotypes/job-status.html | 8 +- uploader/templates/phenotypes/review-job-data.html | 101 +++++++++++++++++++++ 3 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 uploader/templates/phenotypes/review-job-data.html (limited to 'uploader') diff --git a/uploader/phenotypes/views.py b/uploader/phenotypes/views.py index ec4c840..53e68d1 100644 --- a/uploader/phenotypes/views.py +++ b/uploader/phenotypes/views.py @@ -5,7 +5,7 @@ import json import datetime from pathlib import Path from zipfile import ZipFile -from functools import wraps +from functools import wraps, reduce from logging import INFO, ERROR, DEBUG, FATAL, CRITICAL, WARNING from redis import Redis @@ -502,3 +502,77 @@ def job_status( metadata=jobs.job_files_metadata( rconn, jobs.jobsnamespace(), job['jobid']), activelink="add-phenotypes") + + +@phenotypesbp.route( + "/populations//phenotypes/datasets" + "//review-job/", + methods=["GET"]) +@require_login +@with_dataset( + species_redirect_uri="species.populations.phenotypes.index", + population_redirect_uri="species.populations.phenotypes.select_population", + redirect_uri="species.populations.phenotypes.list_datasets") +def review_job_data( + species: dict, + population: dict, + dataset: dict, + job_id: uuid.UUID, + **kwargs +):# pylint: disable=[unused-argument] + """Review data one more time before entering it into the database.""" + with Redis.from_url(app.config["REDIS_URL"], decode_responses=True) as rconn: + try: + job = jobs.job(rconn, jobs.jobsnamespace(), str(job_id)) + except jobs.JobNotFound as _jnf: + job = None + + def __metadata_by_type__(by_type, item): + filetype = item[1]["filetype"] + return { + **by_type, + filetype: (by_type.get(filetype, tuple()) + + ({"filename": item[0], **item[1]},)) + } + metadata = reduce(__metadata_by_type__, + (jobs.job_files_metadata( + rconn, jobs.jobsnamespace(), job['jobid']) + if job else {}).items(), + {}) + + def __desc__(filetype): + match filetype: + case "phenocovar": + desc = "phenotypes" + case "pheno": + desc = "phenotypes data" + case "phenose": + desc = "phenotypes standard-errors" + case "phenonum": + desc = "phenotypes samples" + case _: + desc = f"unknown file type '{filetype}'." + + return desc + + def __summarise__(filetype, files): + return { + "filetype": filetype, + "number-of-files": len(files), + "total-data-rows": sum( + int(afile["linecount"]) - 1 for afile in files), + "description": __desc__(filetype) + } + + summary = { + filetype: __summarise__(filetype, meta) + for filetype,meta in metadata.items() + } + return render_template("phenotypes/review-job-data.html", + species=species, + population=population, + dataset=dataset, + job_id=job_id, + job=job, + summary=summary, + activelink="add-phenotypes") diff --git a/uploader/templates/phenotypes/job-status.html b/uploader/templates/phenotypes/job-status.html index 6f43d22..12963c1 100644 --- a/uploader/templates/phenotypes/job-status.html +++ b/uploader/templates/phenotypes/job-status.html @@ -62,8 +62,12 @@ {%if job.status in ("completed:success", "success")%}

{%if errors | length == 0%} - Continue {%else%} +{%endif%} +{%endblock%} + +{%block title%}Phenotypes{%endblock%} + +{%block pagetitle%}Phenotypes{%endblock%} + +{%block lvl4_breadcrumbs%} +

+{%endblock%} + +{%block contents%} + +{%if job%} +
+

Data Review

+

The “{{dataset.FullName}}” dataset from the + “{{population.FullName}}” population of the + species “{{species.SpeciesName}} ({{species.FullName}})” + will be updated as follows:

+ + {%for ftype in ("phenocovar", "pheno", "phenose", "phenonum")%} + {%if summary.get(ftype, False)%} +
    +
  • A total of {{summary[ftype]["number-of-files"]}} files will be processed + adding {%if ftype == "phenocovar"%}(possibly){%endif%} + {{summary[ftype]["total-data-rows"]}} new + {%if ftype == "phenocovar"%} + phenotypes + {%else%} + {{summary[ftype]["description"]}} rows + {%endif%} + to the database. +
  • +
+ {%endif%} + {%endfor%} + + continue +
+{%else%} +
+

Invalid Job

+

+ Could not find a job with the ID: {{job_id}}.

+

You will be redirected in + 20 second(s)

+

+ + If you are not redirected, please + click here to continue + +

+
+{%endif%} +{%endblock%} + +{%block sidebarcontents%} +{{display_pheno_dataset_card(species, population, dataset)}} +{%endblock%} + + +{%block javascript%} + +{%endblock%} -- cgit v1.2.3