-
Notifications
You must be signed in to change notification settings - Fork 0
/
dexcom_charts.py
43 lines (31 loc) · 1.05 KB
/
dexcom_charts.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
import csv
import datetime
from rpy2.robjects.vectors import DataFrame
from rpy2.robjects.packages import importr
import rpy2.robjects as robjects
r = robjects.r
r_base = importr('base')
grdevices = importr('grDevices')
class DexcomCharts():
"""Produces charts for Dexcom data via R."""
def __init__(self, dex_name):
self.dexcom_data = DataFrame.from_csvfile(dex_name)
def summarize(self):
"""Print R's summary of the data."""
dexcom_summary = r_base.summary(self.dexcom_data.rx2('blood_glucose'))
print
print "Summary of Dexcom blood glucose data:"
print
for k, v in dexcom_summary.iteritems():
print("%s: %.3f\n" %(k, v))
def boxplot(self):
"""Create a boxplot of all Dexcom blood glucose readings."""
grdevices.pdf(file="img/boxplot.pdf")
r.boxplot(self.dexcom_data.rx2('blood_glucose'))
grdevices.dev_off()
def main():
dc = DexcomCharts('raw/all_dexcom.csv')
dc.summarize()
dc.boxplot()
if __name__ == '__main__':
main()