This commit is contained in:
Milos Kozak 2019-03-17 18:51:16 +01:00
parent f9904d15d8
commit 18ba5878d2
3 changed files with 23 additions and 13 deletions

View file

@ -464,7 +464,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<BgReading>();
return new ArrayList<>();
}
public List<BgReading> getBgreadingsDataFromTime(long start, long end, boolean ascending) {
@ -481,7 +481,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<BgReading>();
return new ArrayList<>();
}
public List<BgReading> getAllBgreadingsDataFromTime(long mills, boolean ascending) {

View file

@ -65,8 +65,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
private volatile List<BgReading> bgReadings = null; // newest at index 0
private volatile List<BgReading> bucketed_data = null;
private double dia = Constants.defaultDIA;
final Object dataLock = new Object();
boolean stopCalculationTrigger = false;
@ -118,11 +116,22 @@ public class IobCobCalculatorPlugin extends PluginBase {
return rounded;
}
void loadBgData(long now) {
long start = (long) (now - 60 * 60 * 1000L * (24 + dia));
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, now, false);
if (L.isEnabled(L.AUTOSENS))
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(now));
void loadBgData(long to) {
Profile profile = ProfileFunctions.getInstance().getProfile(to);
double dia = Constants.defaultDIA;
if (profile != null) dia = profile.getDia();
long start = to - T.hours((long) (24 + dia)).msecs();
if (DateUtil.isCloseToNow(to)) {
// if close to now expect there can be some readings with time in close future (caused by wrong time setting)
// so read all records
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, false);
if (L.isEnabled(L.AUTOSENS))
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
} else {
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, to, false);
if (L.isEnabled(L.AUTOSENS))
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to));
}
}
public boolean isAbout5minData() {
@ -608,10 +617,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
}
if (ConfigBuilderPlugin.getPlugin() == null)
return; // app still initializing
Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile == null)
return; // app still initializing
dia = profile.getDia();
if (ev == null) { // on init no need of reset
return;
}

View file

@ -182,4 +182,9 @@ public class DateUtil {
public static long roundDateToSec(long date) {
return date - date % 1000;
}
public static boolean isCloseToNow(long date) {
long diff = Math.abs(date - now());
return diff < T.mins(2).msecs();
}
}