diff options
author | Frederick Muriuki Muriithi | 2024-01-18 14:43:00 +0300 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2024-01-18 14:43:00 +0300 |
commit | af485aff7d25c1f5128586c550ca36debe24fd66 (patch) | |
tree | 16593e9e7a11cbd2ae2f5ab228f6620520a0b1b2 /qc_app/db/averaging.py | |
parent | 0369fc21eaa54466bd64f3b12d1fe6a1dbc81de0 (diff) | |
download | gn-uploader-af485aff7d25c1f5128586c550ca36debe24fd66.tar.gz |
UI: Create new ProbeSet dataset.
Diffstat (limited to 'qc_app/db/averaging.py')
-rw-r--r-- | qc_app/db/averaging.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/qc_app/db/averaging.py b/qc_app/db/averaging.py new file mode 100644 index 0000000..62bbe67 --- /dev/null +++ b/qc_app/db/averaging.py @@ -0,0 +1,23 @@ +"""Functions for db interactions for averaging methods""" +from typing import Optional + +import MySQLdb as mdb +from MySQLdb.cursors import DictCursor + +def averaging_methods(conn: mdb.Connection) -> tuple[dict, ...]: + """Fetch all available averaging methods""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT * FROM AvgMethod") + return tuple(dict(row) for row in cursor.fetchall()) + +def averaging_method_by_id( + conn: mdb.Connection, averageid: int) -> Optional[dict]: + """Fetch the averaging method by its ID""" + with conn.cursor(cursorclass=DictCursor) as cursor: + cursor.execute("SELECT * FROM AvgMethod WHERE Id=%s", + (averageid,)) + result = cursor.fetchone() + if bool(result): + return dict(result) + + return None |