generated from carpentries-incubator/python-intermediate-inflammation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinflammation-analysis.py
79 lines (58 loc) · 2.33 KB
/
inflammation-analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python3
"""Software for managing and analysing patients' inflammation data in our imaginary hospital."""
import argparse
from inflammation import models, views, serializers
def main(args):
"""The MVC Controller of the patient inflammation data system.
The Controller is responsible for:
- selecting the necessary models and views for the current task
- passing data between models and views
"""
infiles = args.infiles
if not isinstance(infiles, list):
infiles = [args.infiles]
for filename in infiles:
if args.file_type == 'cvs':
inflammation_data = models.load_csv(filename)
elif args.file_type == 'json':
inflammation_data = serializers.PatientJSONSerializer.load(filename)
if args.view == 'visualize':
view_data = {
'average': models.daily_mean(inflammation_data),
'max': models.daily_max(inflammation_data),
'min': models.daily_min(inflammation_data),
}
views.visualize(view_data)
elif args.view == 'record' and args.file_type == 'cvs':
patient_data = inflammation_data[args.patient]
observations = [models.Observation(day, value) for day, value in enumerate(patient_data)]
patient = models.Patient('UNKNOWN', observations)
views.display_patient_record(patient)
elif args.view == 'record' and args.file_type == 'json':
for patient in inflammation_data:
#print(patient.name)
views.display_patient_record(patient)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='A basic patient inflammation data management system')
parser.add_argument(
'--infiles',
nargs='+',
help='Input containing inflammation series for each patient')
parser.add_argument(
'--file_type',
default='cvs',
choices=['cvs', 'json'],
help='The file type to load')
parser.add_argument(
'--view',
default='visualize',
choices=['visualize', 'record'],
help='Which view should be used?')
parser.add_argument(
'--patient',
type=int,
default=0,
help='Which patient should be displayed?')
args = parser.parse_args()
main(args)