aboutsummaryrefslogtreecommitdiff
path: root/gn3
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-28 10:53:26 +0300
committerFrederick Muriuki Muriithi2023-10-10 11:12:46 +0300
commit413a9d52984850d232d97138485c73d857f7b8c8 (patch)
tree09a79c0c08b12ce409cda3ab3e093c3711bc627d /gn3
parentfb313dfc178560eb5d5ec7900eee0e4f61b80b3a (diff)
downloadgenenetwork3-413a9d52984850d232d97138485c73d857f7b8c8.tar.gz
Clean-up original data, and case-attribute names
For diff-generation purposes, this commit processes the data into a form that is useful for generation of the CSV files to be used for the diffs.
Diffstat (limited to 'gn3')
-rw-r--r--gn3/case_attributes.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/gn3/case_attributes.py b/gn3/case_attributes.py
index cc5feb7..3f5649a 100644
--- a/gn3/case_attributes.py
+++ b/gn3/case_attributes.py
@@ -85,6 +85,17 @@ def inbredset_case_attribute_values(inbredset_id: int) -> Response:
with database_connection(current_app.config["SQL_URI"]) as conn:
return jsonify(__case_attribute_values_by_inbred_set__(conn, inbredset_id))
+def __process_orig_data__(data) -> tuple[dict, ...]:
+ """Process data from database and return tuple of dicts."""
+ return tuple(
+ {
+ "Strain": row["StrainName"],
+ **{
+ key: row["case-attributes"][key]
+ for key in sorted(row["case-attributes"].keys())
+ }
+ } for row in data)
+
def __process_edit_data__(form_data) -> tuple[dict, ...]:
"""Process data from form and return tuple of dicts."""
raise NotImplementedError
@@ -167,7 +178,11 @@ def edit_case_attributes(inbredset_id: int) -> Response:
# TODO: Check user has "edit case attribute privileges"
user = the_token.user
diff_filename = __queue_diff__(conn, user, __compute_diff__(
- __case_attributes_by_inbred_set__(conn, inbredset_id)
+ (["Strain"] + sorted(
+ attr["Name"] for attr in
+ __case_attribute_labels_by_inbred_set__(conn, inbredset_id))),
+ __process_orig_data__(
+ __case_attribute_values_by_inbred_set__(conn, inbredset_id)),
__process_edit_data__(request.form)))
try:
__apply_diff__(conn, user, diff_filename)