detect oldest data available
This commit is contained in:
parent
dcc6acdf31
commit
12eec7108a
3 changed files with 17 additions and 5 deletions
|
@ -15,4 +15,6 @@ public interface TempBasalsInterface {
|
||||||
|
|
||||||
TempBasal getTempBasal (Date time);
|
TempBasal getTempBasal (Date time);
|
||||||
TempBasal getExtendedBolus (Date time);
|
TempBasal getExtendedBolus (Date time);
|
||||||
|
|
||||||
|
long oldestDataAvaialable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
|
@ -182,7 +183,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
||||||
|
|
||||||
List<BgReading> bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia())), false);
|
long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTempBasals().oldestDataAvaialable();
|
||||||
|
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());
|
||||||
|
List<BgReading> bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia()))), false);
|
||||||
AutosensResult autosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime());
|
AutosensResult autosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime());
|
||||||
|
|
||||||
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
|
||||||
|
|
|
@ -5,9 +5,6 @@ import android.preference.PreferenceManager;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import com.j256.ormlite.dao.Dao;
|
import com.j256.ormlite.dao.Dao;
|
||||||
import com.j256.ormlite.stmt.PreparedQuery;
|
|
||||||
import com.j256.ormlite.stmt.QueryBuilder;
|
|
||||||
import com.j256.ormlite.stmt.Where;
|
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -29,7 +26,6 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.client.data.NSProfile;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
|
@ -217,6 +213,17 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long oldestDataAvaialable() {
|
||||||
|
long oldestTemp = new Date().getTime();
|
||||||
|
if (tempBasals.size() > 0)
|
||||||
|
oldestTemp = Math.min(oldestTemp, tempBasals.get(tempBasals.size() - 1).timeStart.getTime());
|
||||||
|
if (extendedBoluses.size() > 0)
|
||||||
|
oldestTemp = Math.min(oldestTemp, extendedBoluses.get(tempBasals.size() - 1).timeStart.getTime());
|
||||||
|
oldestTemp -= 15 * 60 * 1000L; // allow 15 min before
|
||||||
|
return oldestTemp;
|
||||||
|
}
|
||||||
|
|
||||||
List<TempBasal> getMergedList() {
|
List<TempBasal> getMergedList() {
|
||||||
if (useExtendedBoluses) {
|
if (useExtendedBoluses) {
|
||||||
List<TempBasal> merged = new ArrayList<TempBasal>();
|
List<TempBasal> merged = new ArrayList<TempBasal>();
|
||||||
|
|
Loading…
Reference in a new issue