Improved rounding
This commit is contained in:
parent
46a1be97f7
commit
ccabb099f0
|
@ -415,13 +415,12 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
Profile.BasalValue basalValue = profile.getBasalValues()[i];
|
Profile.BasalValue basalValue = profile.getBasalValues()[i];
|
||||||
Profile.BasalValue nextValue = null;
|
Profile.BasalValue nextValue = null;
|
||||||
if (profile.getBasalValues().length > i + 1) nextValue = profile.getBasalValues()[i + 1];
|
if (profile.getBasalValues().length > i + 1) nextValue = profile.getBasalValues()[i + 1];
|
||||||
profileBlocks.add(new BRProfileBlock.ProfileBlock((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60), basalValue.value));
|
profileBlocks.add(new BRProfileBlock.ProfileBlock((((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60), Helpers.roundDouble(basalValue.value, 2)));
|
||||||
log("setNewBasalProfile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
|
log("setNewBasalProfile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
|
||||||
}
|
}
|
||||||
final UUID uuid = aSyncTaskRunner(new WriteBasalProfileTaskRunner(connector.getServiceConnector(), profileBlocks), "Write basal profile");
|
final UUID uuid = aSyncTaskRunner(new WriteBasalProfileTaskRunner(connector.getServiceConnector(), profileBlocks), "Write basal profile");
|
||||||
final Mstatus ms = async.busyWaitForCommandResult(uuid, BUSY_WAIT_TIME);
|
final Mstatus ms = async.busyWaitForCommandResult(uuid, BUSY_WAIT_TIME);
|
||||||
if (ms.success()) {
|
if (ms.success()) {
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.PROFILE_NOT_SET_NOT_INITIALIZED));
|
|
||||||
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
MainApp.bus().post(new EventDismissNotification(Notification.FAILED_UDPATE_PROFILE));
|
||||||
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60);
|
Notification notification = new Notification(Notification.PROFILE_SET_OK, MainApp.sResources.getString(R.string.profile_set_ok), Notification.INFO, 60);
|
||||||
MainApp.bus().post(new EventNewNotification(notification));
|
MainApp.bus().post(new EventNewNotification(notification));
|
||||||
|
@ -438,12 +437,8 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isThisProfileSet(Profile profile) {
|
public boolean isThisProfileSet(Profile profile) {
|
||||||
if (!isInitialized() || profileBlocks == null) {
|
if (!isInitialized() || profileBlocks == null) return true;
|
||||||
return true;
|
if (profile.getBasalValues().length != profileBlocks.size()) return false;
|
||||||
}
|
|
||||||
if (profile.getBasalValues().length != profileBlocks.size()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < profileBlocks.size(); i++) {
|
for (int i = 0; i < profileBlocks.size(); i++) {
|
||||||
BRProfileBlock.ProfileBlock profileBlock = profileBlocks.get(i);
|
BRProfileBlock.ProfileBlock profileBlock = profileBlocks.get(i);
|
||||||
Profile.BasalValue basalValue = profile.getBasalValues()[i];
|
Profile.BasalValue basalValue = profile.getBasalValues()[i];
|
||||||
|
@ -451,13 +446,9 @@ public class InsightPumpPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
if (profile.getBasalValues().length > i + 1) nextValue = profile.getBasalValues()[i + 1];
|
if (profile.getBasalValues().length > i + 1) nextValue = profile.getBasalValues()[i + 1];
|
||||||
log("isThisProfileSet - Comparing block: Pump: " + profileBlock.getAmount() + " for " + profileBlock.getDuration()
|
log("isThisProfileSet - Comparing block: Pump: " + profileBlock.getAmount() + " for " + profileBlock.getDuration()
|
||||||
+ " Profile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
|
+ " Profile: " + basalValue.value + " for " + Integer.toString(((nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) / 60));
|
||||||
if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) {
|
if (profileBlock.getDuration() * 60 != (nextValue != null ? nextValue.timeAsSeconds : 24 * 60 * 60) - basalValue.timeAsSeconds) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//Allow a little imprecision due to rounding errors
|
//Allow a little imprecision due to rounding errors
|
||||||
if (Math.abs(profileBlock.getAmount() - basalValue.value) > 0.02D) {
|
if (Math.abs(profileBlock.getAmount() - Helpers.roundDouble(basalValue.value, 2)) >= 0.01D) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue