Skip to content

Commit

Permalink
BgGraphBuilder: activate smoothing functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Aug 1, 2022
1 parent 1f65489 commit dd1af49
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.eveningoutpost.dexdrip.calibrations.CalibrationAbstract;
import com.eveningoutpost.dexdrip.calibrations.PluggableCalibration;
import com.eveningoutpost.dexdrip.insulin.opennov.Options;
import com.eveningoutpost.dexdrip.processing.SmootherFactory;
import com.eveningoutpost.dexdrip.store.FastStore;
import com.eveningoutpost.dexdrip.store.KeyStore;
import com.eveningoutpost.dexdrip.ui.classifier.NoteClassifier;
Expand Down Expand Up @@ -78,6 +79,7 @@
import lecho.lib.hellocharts.model.Viewport;
import lecho.lib.hellocharts.util.ChartUtils;
import lecho.lib.hellocharts.view.Chart;
import lombok.val;

import static com.eveningoutpost.dexdrip.Models.JoH.tolerantParseDouble;
import static com.eveningoutpost.dexdrip.UtilityModels.ColorCache.X;
Expand Down Expand Up @@ -114,6 +116,7 @@ public class BgGraphBuilder {

// flag to indicate if readings data has been adjusted
private static boolean plugin_adjusted = false;
private boolean smoother_adjusted;
// used to prevent concurrency problems with calibration plugins
private static final ReentrantLock readings_lock = new ReentrantLock();

Expand Down Expand Up @@ -1041,7 +1044,7 @@ private synchronized void addBgReadingValues(final boolean simple) {

try {

if (plugin_adjusted) {
if (plugin_adjusted || smoother_adjusted) {
Log.i(TAG, "Reloading as Plugin modified data: " + JoH.backTrace(1) + " size:" + bgReadings.size());
bgReadings.clear();
bgReadings.addAll(BgReading.latestForGraph(loaded_numValues, loaded_start, loaded_end));
Expand Down Expand Up @@ -1071,6 +1074,14 @@ private synchronized void addBgReadingValues(final boolean simple) {
iconValues.clear();
smbValues.clear();

if (Pref.getBooleanDefaultFalse("graph_smoothing")) {
if (Home.get_engineering_mode() && Pref.getBooleanDefaultFalse("show-unsmoothed-values-as-plugin")) {
showUnSmoothedValues(bgReadings);
}
SmootherFactory.get(Pref.getString("main-chart-smoothing-alg","")).smoothBgReadings(bgReadings);
smoother_adjusted = true;
}

final double bgScale = bgScale();
final double now = JoH.ts();

Expand Down Expand Up @@ -2090,6 +2101,13 @@ public Axis previewXAxis() {
return previewXaxis;
}

public void showUnSmoothedValues(final List<BgReading> readings) {
pluginValues.clear();
for (val bgReading : readings) {
pluginValues.add(new HPointValue((double) (bgReading.timestamp / FUZZER), (float) unitized(bgReading.calculated_value)));
}
}

private SimpleDateFormat hourFormat() {
return new SimpleDateFormat(DateFormat.is24HourFormat(context) ? "HH" : "h a");
}
Expand Down

0 comments on commit dd1af49

Please sign in to comment.