update NS values from patched Dexcom app smoothing

This commit is contained in:
Milos Kozak 2021-02-07 11:14:32 +01:00
parent 7763a96d6a
commit d93865997c
5 changed files with 36 additions and 11 deletions

View file

@ -137,7 +137,7 @@ public class MainApp extends DaggerApplication {
filter.addAction(Intents.ACTION_NEW_TREATMENT);
filter.addAction(Intents.ACTION_CHANGED_TREATMENT);
filter.addAction(Intents.ACTION_REMOVED_TREATMENT);
//filter.addAction(Intents.ACTION_NEW_SGV);
filter.addAction(Intents.ACTION_NEW_SGV);
filter.addAction(Intents.ACTION_NEW_PROFILE);
filter.addAction(Intents.ACTION_NEW_MBG);
filter.addAction(Intents.ACTION_NEW_CAL);

View file

@ -136,9 +136,13 @@ class DexcomPlugin @Inject constructor(
dexcomPlugin.disposable += repository.runTransactionForResult(CgmSourceTransaction(glucoseValues, calibrations, sensorStartTime)).subscribe({ savedValues ->
savedValues.forEach {
broadcastToXDrip(it)
if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false))
if (sp.getBoolean(R.string.key_dexcomg5_nsupload, false)) {
if (it.interfaceIDs.nightscoutId != null)
nsUpload.updateBg(BgReading(injector, it), sourceSensor.text)
else
nsUpload.uploadBg(BgReading(injector, it), sourceSensor.text)
}
}
}, {
aapsLogger.error(LTag.BGSOURCE, "Error while saving values from Dexcom App", it)
})

View file

@ -107,6 +107,7 @@ class NSClientSourcePlugin @Inject constructor(
noise = null,
raw = if (sgv.filtered != null) sgv.filtered.toDouble() else sgv.mgdl.toDouble(),
trendArrow = GlucoseValue.TrendArrow.fromString(sgv.direction),
nightscoutId = sgv.id,
sourceSensor = GlucoseValue.SourceSensor.fromString(sgv.device)
)
}

View file

@ -417,6 +417,24 @@ public class NSUpload {
uploadQueue.add(new DbRequest("dbAdd", "entries", data));
}
public void updateBg(BgReading reading, String source) {
JSONObject data = new JSONObject();
try {
data.put("device", source);
data.put("date", reading.getDate());
data.put("dateString", DateUtil.toISOString(reading.getDate()));
data.put("sgv", reading.getValue());
data.put("direction", reading.getData().getTrendArrow().getText());
data.put("type", "sgv");
if (reading.getData().getInterfaceIDs_backing() != null)
if (reading.getData().getInterfaceIDs_backing().getNightscoutId() != null) {
uploadQueue.add(new DbRequest("dbUpdate", "entries", reading.getData().getInterfaceIDs_backing().getNightscoutId(), data));
}
} catch (JSONException e) {
aapsLogger.error("Unhandled exception", e);
}
}
public void uploadAppStart() {
if (sp.getBoolean(R.string.key_ns_logappstartedevent, true)) {
JSONObject data = new JSONObject();

View file

@ -40,7 +40,8 @@ data class GlucoseValue(
trendArrow == other.trendArrow &&
noise == other.noise &&
sourceSensor == other.sourceSensor &&
isValid == other.isValid
isValid == other.isValid &&
interfaceIDs?.nightscoutId == other.interfaceIDs?.nightscoutId
fun isRecordDeleted(other: GlucoseValue): Boolean =
isValid && !other.isValid
@ -94,6 +95,7 @@ data class GlucoseValue(
;
companion object {
fun fromString(source: String?) = values().firstOrNull { it.text == source } ?: UNKNOWN
}
}