Skip to content

Commit

Permalink
Libre: add Libre2 source info identifier to processed L2 readings
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Jan 31, 2025
1 parent f768152 commit f6bd8e5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class LibreAlarmReceiver extends BroadcastReceiver {
private static final Object lock = new Object();
private static long sensorAge = 0;
private static long timeShiftNearest = -1;
public static final String LIBRE_SOURCE_INFO = "Libre2";

public static void clearSensorStats() {
Pref.setInt("nfc_sensor_age", 0); // reset for nfc sensors
Expand Down Expand Up @@ -273,7 +274,7 @@ public static void CalculateFromDataTransferObject(ReadingData readingData, bool
if (use_raw) {
createBGfromGD(gd, use_smoothed_data, false); // not quick for recent
} else {
BgReading.bgReadingInsertFromInt(use_smoothed_data ? gd.glucoseLevelSmoothed : gd.glucoseLevel, gd.realDate, segmentation_timeslice, true);
BgReading.bgReadingInsertFromInt(use_smoothed_data ? gd.glucoseLevelSmoothed : gd.glucoseLevel, gd.realDate, segmentation_timeslice, true, LIBRE_SOURCE_INFO);
}
}
} else {
Expand Down Expand Up @@ -306,7 +307,9 @@ public static void insertFromHistory(final List<GlucoseData> mHistory, final boo
} else {
polyyList.add((double) gd.glucoseLevel);
// add in the actual value
BgReading.bgReadingInsertFromInt(gd.glucoseLevel, gd.realDate, timeslice, false);
if (gd.glucoseLevel > 0) {
BgReading.bgReadingInsertFromInt(gd.glucoseLevel, gd.realDate, timeslice, false, LIBRE_SOURCE_INFO);
}
}
}

Expand All @@ -332,7 +335,7 @@ public static void insertFromHistory(final List<GlucoseData> mHistory, final boo
// Here we do not use smoothed data, since data is already smoothed for the history
createBGfromGD(new GlucoseData((int) polySplineF.value(ptime), ptime), false, true);
} else {
BgReading.bgReadingInsertFromInt((int) polySplineF.value(ptime), ptime, timeslice, false);
BgReading.bgReadingInsertFromInt((int) polySplineF.value(ptime), ptime, timeslice, false, LIBRE_SOURCE_INFO);
}
}
} catch (org.apache.commons.math3.exception.NonMonotonicSequenceException e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package com.eveningoutpost.dexdrip;

import static com.eveningoutpost.dexdrip.Home.get_engineering_mode;
import static com.eveningoutpost.dexdrip.LibreAlarmReceiver.LIBRE_SOURCE_INFO;
import static com.eveningoutpost.dexdrip.models.JoH.emptyString;
import static com.eveningoutpost.dexdrip.models.Libre2Sensor.Libre2Sensors;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.PowerManager;
import android.preference.PreferenceManager;
import android.text.format.DateFormat;

import com.eveningoutpost.dexdrip.models.BgReading;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void run() {
val glucose = item.getDouble("glucoseValue");
val timestamp = item.getLong("timestamp");
if (d) UserError.Log.d(TAG, "Real time item: " + JoH.dateTimeText(timestamp) + " value: " + Unitized.unitized_string_static(glucose));
BgReading.bgReadingInsertFromInt((int) Math.round(glucose), timestamp, timeslice, false);
BgReading.bgReadingInsertFromInt((int) Math.round(glucose), timestamp, timeslice, false, LIBRE_SOURCE_INFO);
}

} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,12 @@ public static BgReading bgReadingInsertFromJson(String json, boolean do_notifica
return bgr;
}

// TODO this method shares some code with above.. merge
public static void bgReadingInsertFromInt(int value, long timestamp, long margin, boolean do_notification) {
bgReadingInsertFromInt(value, timestamp, margin, do_notification, "");
}

// TODO this method shares some code with above.. merge
public static void bgReadingInsertFromInt(int value, long timestamp, long margin, boolean do_notification, String source_info) {
// TODO sanity check data!

if ((value <= 0) || (timestamp <= 0)) {
Expand All @@ -1355,6 +1359,8 @@ public static void bgReadingInsertFromInt(int value, long timestamp, long margin
bgr.age_adjusted_raw_value = value;
bgr.filtered_data = value;

bgr.source_info = source_info;

final Sensor forced_sensor = Sensor.currentSensor();
if (forced_sensor != null) {
bgr.sensor = forced_sensor;
Expand Down

0 comments on commit f6bd8e5

Please sign in to comment.