use of com.eveningoutpost.dexdrip.Models.ReadingData in project xDrip-plus by jamorham.
the class LibreTrendGraph method getLatestBg.
private static ArrayList<Float> getLatestBg(LibreBlock libreBlock) {
ReadingData readingData = NFCReaderX.getTrend(libreBlock);
if (readingData == null) {
Log.e(TAG, "NFCReaderX.getTrend returned null");
return null;
}
ArrayList<Float> ret = new ArrayList<Float>();
if (readingData.trend.size() == 0 || readingData.trend.get(0).glucoseLevelRaw == 0) {
Log.e(TAG, "libreBlock exists but no trend data exists, or first value is zero ");
return null;
}
double factor = libreBlock.calculated_bg / readingData.trend.get(0).glucoseLevelRaw;
if (factor == 0) {
// We don't have the calculated value, but we do have the raw value. (No calibration exists)
// I want to show raw data.
Log.w(TAG, "Bg data was not calculated, working on raw data");
List<BgReading> latestReading = BgReading.latestForGraph(1, libreBlock.timestamp - 1000, libreBlock.timestamp + 1000);
if (latestReading == null || latestReading.size() == 0) {
Log.e(TAG, "libreBlock exists but no matching bg record exists");
return null;
}
factor = latestReading.get(0).raw_data / readingData.trend.get(0).glucoseLevelRaw;
}
for (GlucoseData data : readingData.trend) {
ret.add(new Float(factor * data.glucoseLevelRaw));
}
return ret;
}
Aggregations