use of com.nightscout.core.model.SensorGlucoseValueEntry in project android-uploader by nightscout.
the class DexcomG4 method doDownload.
@Override
protected DownloadResults doDownload() {
DownloadStatus status = DownloadStatus.SUCCESS;
try {
transport.open();
} catch (IOException e) {
//TODO record this in the event log later
status = DownloadStatus.IO_ERROR;
}
ReadData readData = new ReadData(transport);
List<EGVRecord> recentRecords = new ArrayList<>();
List<MeterRecord> meterRecords = new ArrayList<>();
List<SensorRecord> sensorRecords = new ArrayList<>();
List<CalRecord> calRecords = new ArrayList<>();
long displayTime = 0;
long timeSinceLastRecord = 0;
int batLevel = 100;
long systemTime = 0;
if (status == DownloadStatus.SUCCESS) {
try {
recentRecords = readData.getRecentEGVsPages(numOfPages);
meterRecords = readData.getRecentMeterRecords();
if (preferences.isSensorUploadEnabled()) {
sensorRecords = readData.getRecentSensorRecords(numOfPages);
}
if (preferences.isCalibrationUploadEnabled()) {
calRecords = readData.getRecentCalRecords();
}
if (recentRecords.size() == 0) {
status = DownloadStatus.NO_DATA;
}
displayTime = readData.readDisplayTime().getTime();
if (status == DownloadStatus.SUCCESS && recentRecords.size() > 0) {
timeSinceLastRecord = readData.getTimeSinceEGVRecord(recentRecords.get(recentRecords.size() - 1));
}
systemTime = readData.readSystemTime();
// FIXME: readData.readBatteryLevel() seems to flake out on battery level reads.
// Removing for now.
batLevel = 100;
// TODO pull in other exceptions once we have the analytics/acra reporters
} catch (IOException e) {
//TODO record this in the event log later
status = DownloadStatus.IO_ERROR;
} catch (InvalidRecordLengthException e) {
status = DownloadStatus.APPLICATION_ERROR;
} finally {
try {
transport.close();
} catch (IOException e) {
//TODO record this in the event log later
status = DownloadStatus.IO_ERROR;
}
}
}
List<SensorGlucoseValueEntry> cookieMonsterG4SGVs = EGVRecord.toProtobufList(recentRecords);
List<CalibrationEntry> cookieMonsterG4Cals = CalRecord.toProtobufList(calRecords);
List<MeterEntry> cookieMonsterG4Meters = MeterRecord.toProtobufList(meterRecords);
List<SensorEntry> cookieMonsterG4Sensors = SensorRecord.toProtobufList(sensorRecords);
G4Download.Builder downloadBuilder = new G4Download.Builder();
downloadBuilder.sgv(cookieMonsterG4SGVs).cal(cookieMonsterG4Cals).sensor(cookieMonsterG4Sensors).meter(cookieMonsterG4Meters).receiver_system_time_sec(systemTime).download_timestamp(new Date().toString()).download_status(status).uploader_battery(uploaderDevice.getBatteryLevel()).receiver_battery(batLevel).units(GlucoseUnit.MGDL);
// TODO: determine if the logic here is correct. I suspect it assumes the last record was
// less than 5
// minutes ago. If a reading is skipped and the device is plugged in then nextUploadTime
// will be set to a negative number. This situation will eventually correct itself.
long nextUploadTime = standardMinutes(5).minus(standardSeconds(timeSinceLastRecord)).getMillis();
// convert into json for d3 plot
JSONArray array = new JSONArray();
for (EGVRecord recentRecord : recentRecords) {
try {
array.put(recentRecord.toJSON());
} catch (JSONException e) {
e.printStackTrace();
}
}
return new DownloadResults(downloadBuilder.build(), nextUploadTime, array, displayTime);
}
use of com.nightscout.core.model.SensorGlucoseValueEntry in project android-uploader by nightscout.
the class Uploader method upload.
public boolean upload(DownloadResults downloadResults, int numRecords) {
G4Download download = downloadResults.getDownload();
List<SensorGlucoseValueEntry> sgvList = filterRecords(numRecords, download.sgv);
List<CalibrationEntry> calList = filterRecords(numRecords, download.cal);
List<MeterEntry> meterList = filterRecords(numRecords, download.meter);
List<SensorEntry> sensorList = filterRecords(numRecords, download.sensor);
List<GlucoseDataSet> glucoseDataSets = Utils.mergeGlucoseDataRecords(sgvList, sensorList);
return upload(glucoseDataSets, meterList, calList);
}
Aggregations