aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMunyoki Kilyungi2023-01-16 15:31:19 +0300
committerBonfaceKilz2023-01-20 15:02:46 +0300
commit609fca7ec0908c9937a3c3bd3862cf166e71214e (patch)
tree16d626c85d7d8b2a16a4813447576b83a9f378ca
parentbb2d80af509c0697eebe5ced23de99345135dc6b (diff)
downloadgenenetwork2-609fca7ec0908c9937a3c3bd3862cf166e71214e.tar.gz
Create script to dumple sample data given the dataset and trait id
* scripts/sampledata.py: New file.
-rw-r--r--scripts/sampledata.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/scripts/sampledata.py b/scripts/sampledata.py
new file mode 100644
index 00000000..e1b38f3c
--- /dev/null
+++ b/scripts/sampledata.py
@@ -0,0 +1,50 @@
+import json
+
+# Required Evils!
+from flask import g
+from wqflask import app
+
+from wqflask.show_trait import show_trait
+from wqflask.database import database_connection
+
+
+class UserSessionSimulator():
+ def __init__(self, user_id):
+ self._user_id = user_id
+
+ @property
+ def user_id(self):
+ return self._user_id
+
+
+def dump_sample_data(dataset_name, trait_id):
+ """Givena DATASET_NAME e.g. 'BXDPublish' and a TRAIT_ID
+ e.g. '10007', dump the sample data as json object"""
+ with database_connection() as conn, conn.cursor() as cursor:
+ sample_data = {"headers": ["Name", "Value", "SE"], "data": []}
+
+ with app.app_context():
+ g.user_session = UserSessionSimulator(None)
+ data = show_trait.ShowTrait(
+ cursor, user_id=None,
+ kw={
+ "trait_id": "10007",
+ "dataset": "BXDPublish",
+ }
+ )
+ attributes = data.js_data.get("attributes")
+ for id_ in attributes:
+ sample_data["headers"].append(attributes[id_].name)
+ for sample in data.js_data.get("sample_lists")[0]:
+ sample_data["data"].append(
+ [
+ sample.name,
+ sample.value or 'x',
+ sample.variance or 'x',
+ *[str(sample.extra_attributes.get(str(key), "x"))
+ for key in attributes],
+ ])
+ return sample_data
+
+
+print(json.dumps(dump_sample_data("BXDPublish", "10007")))