ensure we are loading 24h + dia data

This commit is contained in:
Milos Kozak 2017-01-09 10:57:15 +01:00
parent 5f146f90de
commit c62e498aac
9 changed files with 57 additions and 62 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -4,11 +4,6 @@ import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spanned;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -61,7 +56,7 @@ public class GlucoseStatus {
public static GlucoseStatus getGlucoseStatusData() {
// load 45min
long fromtime = (long) (new Date().getTime() - 60 * 1000L * 45);
List<BgReading> data = MainApp.getDbHelper().getDataFromTime(fromtime, false);
List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
int sizeRecords = data.size();
if (sizeRecords < 4 || data.get(0).timeIndex < new Date().getTime() - 7 * 60 * 1000L) {

View file

@ -24,7 +24,7 @@ public class MealData {
if (profile == null) return;
// TODO: not sure how much data do i need for AMA
List<BgReading> bgReadings = MainApp.getDbHelper().getDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * profile.getDia() * 2), false);
List<BgReading> bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * profile.getDia() * 2), false);
long now = new Date().getTime();
long dia_ago = now - (new Double(profile.getDia() * 60 * 60 * 1000l)).longValue();

View file

@ -183,7 +183,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return null;
}
public List<BgReading> getDataFromTime(long mills, boolean ascending) {
public List<BgReading> getBgreadingsDataFromTime(long mills, boolean ascending) {
try {
Dao<BgReading, Long> daoBgreadings = getDaoBgReadings();
List<BgReading> bgReadings;
@ -200,4 +200,38 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<BgReading>();
}
public List<Treatment> getTreatmentDataFromTime(long mills, boolean ascending) {
try {
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
List<Treatment> treatments;
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
queryBuilder.orderBy("timeIndex", ascending);
Where where = queryBuilder.where();
where.ge("timeIndex", mills);
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
treatments = daoTreatments.query(preparedQuery);
return treatments;
} catch (SQLException e) {
e.printStackTrace();
}
return new ArrayList<Treatment>();
}
public List<TempBasal> getTempbasalsDataFromTime(long mills, boolean ascending, boolean isExtended) {
try {
Dao<TempBasal, Long> daoTempbasals = getDaoTempBasals();
List<TempBasal> tempbasals;
QueryBuilder<TempBasal, Long> queryBuilder = daoTempbasals.queryBuilder();
queryBuilder.orderBy("timeIndex", ascending);
Where where = queryBuilder.where();
where.ge("timeIndex", mills).and().eq("isExtended", isExtended);
PreparedQuery<TempBasal> preparedQuery = queryBuilder.prepare();
tempbasals = daoTempbasals.query(preparedQuery);
return tempbasals;
} catch (SQLException e) {
e.printStackTrace();
}
return new ArrayList<TempBasal>();
}
}

View file

@ -21,8 +21,6 @@ import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
import info.nightscout.androidaps.data.IobTotal;
@ -184,7 +182,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
List<BgReading> bgReadings = MainApp.getDbHelper().getDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia())), false);
List<BgReading> bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia())), false);
AutosensResult autosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime());
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,

View file

@ -746,7 +746,7 @@ public class OverviewFragment extends Fragment {
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
// **** BG graph ****
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getDataFromTime(fromTime, true);
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
List<BgReading> inRangeArray = new ArrayList<BgReading>();
List<BgReading> outOfRangeArray = new ArrayList<BgReading>();

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.client.data.NSProfile;
/**
* Created by mike on 05.08.2016.
@ -95,44 +96,16 @@ public class TempBasalsPlugin implements PluginBase, TempBasalsInterface {
}
private void initializeData() {
try {
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();
/*
// **************** TESTING CREATE FAKE RECORD *****************
TempBasal fake = new TempBasal();
fake.timeStart = new Date(new Date().getTime() - 45 * 40 * 1000);
fake.timeEnd = new Date(new Date().getTime() - new Double(Math.random() * 45d * 40 * 1000).longValue());
fake.duration = 30;
fake.percent = 150;
fake.isAbsolute = false;
fake.isExtended = false;
dao.createOrUpdate(fake);
// **************** TESTING CREATE FAKE RECORD *****************
*/
QueryBuilder<TempBasal, Long> queryBuilder = dao.queryBuilder();
queryBuilder.orderBy("timeIndex", false);
Where where = queryBuilder.where();
where.eq("isExtended", false);
queryBuilder.limit(30L);
PreparedQuery<TempBasal> preparedQuery = queryBuilder.prepare();
tempBasals = dao.query(preparedQuery);
QueryBuilder<TempBasal, Long> queryBuilderExt = dao.queryBuilder();
queryBuilderExt.orderBy("timeIndex", false);
Where whereExt = queryBuilderExt.where();
whereExt.eq("isExtended", true);
queryBuilderExt.limit(30L);
PreparedQuery<TempBasal> preparedQueryExt = queryBuilderExt.prepare();
extendedBoluses = dao.query(preparedQueryExt);
double dia = 3;
if (MainApp.getConfigBuilder().getActiveProfile() != null)
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia));
tempBasals = MainApp.getDbHelper().getTempbasalsDataFromTime(fromMills, false, false);
extendedBoluses = MainApp.getDbHelper().getTempbasalsDataFromTime(fromMills, false, true);
// Update ended
checkForExpiredExtended();
checkForExpiredTemps();
} catch (SQLException e) {
log.debug(e.getMessage(), e);
tempBasals = new ArrayList<TempBasal>();
extendedBoluses = new ArrayList<TempBasal>();
}
}
public void checkForExpiredTemps() {

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.Treatments;
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 org.slf4j.Logger;
@ -86,17 +87,11 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
public void initializeData() {
try {
Dao<Treatment, Long> dao = MainApp.getDbHelper().getDaoTreatments();
QueryBuilder<Treatment, Long> queryBuilder = dao.queryBuilder();
queryBuilder.orderBy("timeIndex", false);
queryBuilder.limit(30l);
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
treatments = dao.query(preparedQuery);
} catch (SQLException e) {
log.debug(e.getMessage(), e);
treatments = new ArrayList<Treatment>();
}
double dia = 3;
if (MainApp.getConfigBuilder().getActiveProfile() != null)
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia));
treatments = MainApp.getDbHelper().getTreatmentDataFromTime(fromMills, false);
}
/*

View file

@ -254,7 +254,7 @@ public class WatchUpdaterService extends WearableListenerService implements
if (last_bg == null) return;
List<BgReading> graph_bgs = MainApp.getDbHelper().getDataFromTime(startTime, true);
List<BgReading> graph_bgs = MainApp.getDbHelper().getBgreadingsDataFromTime(startTime, true);
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
if (!graph_bgs.isEmpty()) {