Skip to content
Snippets Groups Projects
Commit 1da00c21 authored by Ben Wagner's avatar Ben Wagner
Browse files

Updates DOB (but is off by TimeZone) and Age

parent ae508360
Branches
No related merge requests found
......@@ -4,7 +4,7 @@ FROM python:3.10-alpine
RUN apk update && apk add bash
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir --extra-index-url https://package_access_token:5pBy3bmcwmL-_Mwa4_T6@git.biohpc.swmed.edu/api/v4/projects/1606/packages/pypi/simple flywheel-gear-toolkit[sdk] fiffreader
RUN pip install --no-cache-dir --extra-index-url https://package_access_token:5pBy3bmcwmL-_Mwa4_T6@git.biohpc.swmed.edu/api/v4/projects/1606/packages/pypi/simple flywheel-gear-toolkit[sdk] fiffreader pytz
ENV FLYWHEEL=/flywheel/v0
RUN mkdir -p ${FLYWHEEL}
......
......@@ -16,7 +16,7 @@
},
"gear-builder": {
"category": "utility",
"image": "ansir/meg-metadata-importer:0.0.013"
"image": "ansir/meg-metadata-importer:0.0.028"
}
},
"description": "Import file metadata into Flywheel. Metadata is stored under file.info.header. May also update blank fields in acquisition, session, and subject. Supports FIFF files.",
......@@ -28,7 +28,7 @@
"input-file": {
"base": "file",
"description": "Input file.",
"optional": false,
"optional": true,
"type": {
"enum": [
"fiff"
......@@ -42,5 +42,5 @@
"name": "meg-metadata-importer",
"source": "https://git.biohpc.swmed.edu/ben.wagner/meg-metadata-importer",
"url": "https://git.biohpc.swmed.edu/ben.wagner/meg-metadata-importer",
"version": "0.0.013"
"version": "0.0.028"
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ import logging
import math
import os
import pprint
import pytz
import sys
from flywheel_gear_toolkit import GearToolkitContext
......@@ -117,19 +118,23 @@ def main(context):
if session_id:
session = context.client.get(session_id)
if not session.age and meas_date and dob:
if (not session.age or session.age == 0) and meas_date and dob:
age_delta = datetime.datetime.strptime(
meas_date, "%Y-%m-%d %H:%M:%S"
) - datetime.datetime.strptime(dob, "%Y-%m-%d")
age = math.floor(age_delta.days / 365.2425)
print(f"Setting age to {age}")
session.update(age=age)
age_years = math.floor(age_delta.days / 365.2425)
age_seconds = int(age_delta.total_seconds())
print(f"Setting age to {age_years} ({age_seconds} seconds)")
session.update(age=age_seconds)
if not session.weight and weight:
print(f"Setting weight to {weight}")
session.update(weight=weight)
if not session.operator and experimenter:
print(f"Setting operator to {experimenter}")
session.update(operator=experimenter)
if isinstance(experimenter, str):
session.update(operator=experimenter)
else:
session.update(operator=set(experimenter))
if subject_id:
subject = context.client.get(subject_id)
......@@ -139,15 +144,19 @@ def main(context):
if not subject.lastname and subj_last_name:
print(f"Setting lastname to {subj_last_name}")
subject.update(lastname=subj_last_name)
if not subject.sex and sex:
if (not subject.sex or subject.sex == "unknown") and sex:
mfu = "unknown"
# not sure if 0 is male/female or something else...same for 1
if sex == 0:
mfu = "male"
if sex == 1:
mfu = "male"
if sex == 2:
mfu = "female"
print(f"Setting sex to {mfu}")
subject.update(sex=mfu)
if (not subject.date_of_birth) and dob:
dt_dob = datetime.datetime.strptime(dob, "%Y-%m-%d")
dt_dob = dt_dob.replace(tzinfo=pytz.UTC)
print(f"Setting DOB to {dt_dob} from {dob}")
subject.update(date_of_birth=dt_dob)
# return sucessful exit code
return 0
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment