Skip to content

Commit

Permalink
BgReading: add latestDeduplicateToPeriod()
Browse files Browse the repository at this point in the history
  • Loading branch information
jamorham committed Aug 1, 2022
1 parent 52513e9 commit 0fcbb7c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions app/src/main/java/com/eveningoutpost/dexdrip/Models/BgReading.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.eveningoutpost.dexdrip.Models;

import static com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.NOT_COMPUTABLE;
import static com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.getTrend;
import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.getCalibrationPluginFromPreferences;
import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.newCloseSensorData;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
Expand Down Expand Up @@ -56,9 +61,7 @@
import java.util.Random;
import java.util.UUID;

import static com.eveningoutpost.dexdrip.ImportedLibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.*;
import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.getCalibrationPluginFromPreferences;
import static com.eveningoutpost.dexdrip.calibrations.PluggableCalibration.newCloseSensorData;
import lombok.val;

@Table(name = "BgReadings", id = BaseColumns._ID)
public class BgReading extends Model implements ShareUploadableBg {
Expand Down Expand Up @@ -835,6 +838,21 @@ public static List<BgReading> latest(int number, boolean is_follower) {
}
}

public static List<BgReading> latestDeduplicateToPeriod(final int number, final boolean is_follower, final long period) {
val input = latest(number * 6, is_follower);
if (input == null) return null;
val output = new ArrayList<BgReading>(number);
long last = -1L;
for (val item : input) {
if (Math.abs(item.timestamp - last) >= period) {
output.add(item);
if (output.size() >= number) break;
last = item.timestamp;
}
}
return output;
}

public static boolean isDataStale() {
final BgReading last = lastNoSenssor();
if (last == null) return true;
Expand Down

0 comments on commit 0fcbb7c

Please sign in to comment.