Skip to content

Commit

Permalink
Moving to mongo..
Browse files Browse the repository at this point in the history
  • Loading branch information
Fokko authored and bewest committed Jun 21, 2015
1 parent 7aa0ff7 commit 9845935
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 58 deletions.
15 changes: 1 addition & 14 deletions bin/mm-glucose.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ def customize_parser (self, parser):
def download_page (self, number):
return self.exec_request(self.pump, commands.ReadGlucoseHistory, args=dict(page=number), render_decoded=False,render_hexdump=False)

def find_records (self, page):
decoder = HistoryPage(page, self.pump.model)
records = decoder.decode( )

print "Found " , len(records), " records."
for record in records:
print " * found record", record.get('timestamp'), record['_type']
if record.get('timestamp'):
dt = parse(record['timestamp'])
dt = dt.replace(tzinfo=self.timezone)
record.update(timestamp=dt.isoformat( ))
return records

def download_history (self, args, pageRange):
records = [ ]
for i in range(1 + pageRange['page'] - pageRange['isig'], pageRange['page']):
Expand All @@ -61,7 +48,7 @@ def download_history (self, args, pageRange):
recordsJson = json.dumps(records);
args.parsed_data.write(recordsJson)

handle = open('cgm.json', 'wb')
handle = open('glucose.json', 'wb')
handle.write(recordsJson)
handle.close( )

Expand Down
39 changes: 21 additions & 18 deletions bin/mm-history.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# PYTHON_ARGCOMPLETE_OK

from decocare import commands, models
import json, argparse
import json, argparse, sys

from decocare.history import HistoryPage
from decocare.helpers import cli
Expand Down Expand Up @@ -35,7 +35,7 @@ def download_page (self, number):
return self.exec_request(self.pump, commands.ReadHistoryData, args=dict(page=number), render_decoded=False,render_hexdump=False)

def find_records (self, page):
decoder = HistoryPage(page, self.pump.model)

records = decoder.decode( )

print "Found " , len(records), " records."
Expand All @@ -47,31 +47,34 @@ def find_records (self, page):
record.update(timestamp=dt.isoformat( ))
return records

def download_history (self, args):
def download_history (self, args, nrPages):
records = [ ]
for i in range(1, 38):
for i in range(1, nrPages):
print "Next page ", i
pageHistory = self.download_page(i)
records.extend(self.find_records(pageHistory.data))
args.parsed_data.write(json.dumps(records))
try:
pageRaw = self.download_page(i)
pageResult = HistoryPage(pageRaw.data, self.pump.model)
records.extend(pageResult.decode())
except:
print "Unexpected error when downloading cgm-page ", i, " from pump:", sys.exc_info()[0]

recordsJson = json.dumps(records);
args.parsed_data.write(recordsJson)

handle = open('history.json', 'wb')
handle.write(recordsJson)
handle.close( )

def getRange(self):
def getNumberOfPages(self):
range = self.exec_request(self.pump, commands.ReadCurPageNumber, render_decoded=False,render_hexdump=False)
return range.getData
return range.getData()

def main (self, args):
# Set Global variables..
self.timezone = args.timezone

info = self.getRange()
print "yes"
print info
print vars(info)
print repr(info)
print "yes"


#self.download_history(args)
nrPages = self.getNumberOfPages()
self.download_history(args, nrPages)

if __name__ == '__main__':
app = DownloadHistory( )
Expand Down
30 changes: 4 additions & 26 deletions download-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,8 @@ if [ ! -e ${PORT} 2>/dev/null ]; then
exit 1
fi

# Get the number of pages
./bin/mm-send-comm.py --init --serial ${SERIAL} --port ${PORT} --prefix-path ${FOLDER} --prefix ReadCurGlucosePageNumber --save sleep 0 > ${FOLDER}ReadCurGlucosePageNumber.markdown
./bin/mm-glucose.py --init --serial 417540 --port /dev/ttyUSB0
curl --header "Content-type: application/json" --request POST --data-binary "@glucose.json" http://localhost:9000/upload/sensor


pages=`cat ${FOLDER}ReadCurGlucosePageNumber.markdown | grep -Po "page': \K([0-9]*)" | head -n 1`
glucose=`cat ${FOLDER}ReadCurGlucosePageNumber.markdown | grep -Po "glucose': \K([0-9]*)" | head -n 1`
start=$(expr $pages - $glucose)

for page in `seq ${start} ${pages}`; do
`./bin/mm-send-comm.py --serial ${SERIAL} --port ${PORT} --prefix-path ${FOLDER} tweak ReadGlucoseHistory --page ${page} --save > ${FOLDER}ReadGlucoseHistory-page-${page}.markdown`
`./bin/mm-send-comm.py --serial ${SERIAL} --port ${PORT} --prefix-path ${FOLDER} tweak ReadHistoryData --page ${page} --save > ${FOLDER}ReadHistoryData-page-${page}.markdown`

echo "Decoding page ${page}.."
`./list_cgm.py ${FOLDER}ReadGlucoseHistory-page-${page}.data > ${FOLDER}ReadGlucoseHistory-page-${page}.json`

curl --header "Content-type: application/json" --request POST --data-binary "@data/ReadGlucoseHistory-page-${page}.json" http://localhost:9000/upload

echo "Decoding page ${page}.."
`./list_dates.py ${FOLDER}ReadHistoryData-page-${page}.data > ${FOLDER}ReadHistoryData-page-${page}-dates.json`
`./list_history.py ${FOLDER}ReadHistoryData-page-${page}.data > ${FOLDER}ReadHistoryData-page-${page}-history.json`
#curl --header "Content-type: application/json" --request POST --data-binary "@data/ReadHistoryData-page-${page}.json" http://localhost:9000/upload

done

#Page: 58
#./bin/mm-send-comm.py --serial 417540 --port /dev/ttyUSB0 --prefix-path ./ tweak ReadGlucoseHistory --page 58 --save
#python ./list_cgm.py ./ReadGlucoseHistory-page-58.data
./bin/mm-history.py --init --serial 417540 --port /dev/ttyUSB0
curl --header "Content-type: application/json" --request POST --data-binary "@history.json" http://localhost:9000/upload/pump
File renamed without changes.
1 change: 1 addition & 0 deletions history.json

Large diffs are not rendered by default.

0 comments on commit 9845935

Please sign in to comment.