ComboPlugin: fix usages of bolus timestamp vs generated ID.
This commit is contained in:
parent
420947be3f
commit
8eb73b81e9
|
@ -639,10 +639,10 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
||||||
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
|
private boolean addBolusToTreatments(DetailedBolusInfo detailedBolusInfo, Bolus lastPumpBolus) {
|
||||||
try {
|
try {
|
||||||
pumpSync.syncBolusWithPumpId(
|
pumpSync.syncBolusWithPumpId(
|
||||||
calculateFakeBolusDate(lastPumpBolus),
|
lastPumpBolus.timestamp,
|
||||||
lastPumpBolus.amount,
|
lastPumpBolus.amount,
|
||||||
detailedBolusInfo.getBolusType(),
|
detailedBolusInfo.getBolusType(),
|
||||||
detailedBolusInfo.timestamp,
|
generatePumpBolusId(lastPumpBolus),
|
||||||
PumpType.ACCU_CHEK_COMBO,
|
PumpType.ACCU_CHEK_COMBO,
|
||||||
serialNumber()
|
serialNumber()
|
||||||
);
|
);
|
||||||
|
@ -1149,10 +1149,10 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
||||||
boolean updated = false;
|
boolean updated = false;
|
||||||
for (Bolus pumpBolus : history.bolusHistory) {
|
for (Bolus pumpBolus : history.bolusHistory) {
|
||||||
if (pumpSync.syncBolusWithPumpId(
|
if (pumpSync.syncBolusWithPumpId(
|
||||||
calculateFakeBolusDate(pumpBolus),
|
pumpBolus.timestamp,
|
||||||
pumpBolus.amount,
|
pumpBolus.amount,
|
||||||
DetailedBolusInfo.BolusType.NORMAL,
|
DetailedBolusInfo.BolusType.NORMAL,
|
||||||
System.currentTimeMillis(),
|
generatePumpBolusId(pumpBolus),
|
||||||
PumpType.ACCU_CHEK_COMBO,
|
PumpType.ACCU_CHEK_COMBO,
|
||||||
serialNumber()
|
serialNumber()
|
||||||
)) {
|
)) {
|
||||||
|
@ -1169,7 +1169,7 @@ public class ComboPlugin extends PumpPluginBase implements PumpInterface, Constr
|
||||||
* Should be good enough, even with command mode, it's a challenge to create that situation
|
* Should be good enough, even with command mode, it's a challenge to create that situation
|
||||||
* and most time clashes will be around SMBs which are covered.
|
* and most time clashes will be around SMBs which are covered.
|
||||||
*/
|
*/
|
||||||
long calculateFakeBolusDate(Bolus pumpBolus) {
|
long generatePumpBolusId(Bolus pumpBolus) {
|
||||||
double bolus = pumpBolus.amount - 0.1;
|
double bolus = pumpBolus.amount - 0.1;
|
||||||
int secondsFromBolus = (int) (bolus * 10 * 1000);
|
int secondsFromBolus = (int) (bolus * 10 * 1000);
|
||||||
return pumpBolus.timestamp + Math.min(secondsFromBolus, 59 * 1000);
|
return pumpBolus.timestamp + Math.min(secondsFromBolus, 59 * 1000);
|
||||||
|
|
|
@ -64,22 +64,22 @@ class ComboPluginTest : TestBase() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun calculateFakePumpTimestamp() {
|
fun `generate bolus ID from timestamp and amount`() {
|
||||||
val now = System.currentTimeMillis()
|
val now = System.currentTimeMillis()
|
||||||
val pumpTimestamp = now - now % 1000
|
val pumpTimestamp = now - now % 1000
|
||||||
// same timestamp, different bolus leads to different fake timestamp
|
// same timestamp, different bolus leads to different fake timestamp
|
||||||
Assert.assertNotEquals(
|
Assert.assertNotEquals(
|
||||||
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp, 0.1, true)),
|
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.1, true)),
|
||||||
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp, 0.3, true))
|
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true))
|
||||||
)
|
)
|
||||||
// different timestamp, same bolus leads to different fake timestamp
|
// different timestamp, same bolus leads to different fake timestamp
|
||||||
Assert.assertNotEquals(
|
Assert.assertNotEquals(
|
||||||
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp, 0.3, true)),
|
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp, 0.3, true)),
|
||||||
comboPlugin.calculateFakeBolusDate(Bolus(pumpTimestamp + 60 * 1000, 0.3, true))
|
comboPlugin.generatePumpBolusId(Bolus(pumpTimestamp + 60 * 1000, 0.3, true))
|
||||||
)
|
)
|
||||||
// generated timestamp has second-precision
|
// generated timestamp has second-precision
|
||||||
val bolus = Bolus(pumpTimestamp, 0.2, true)
|
val bolus = Bolus(pumpTimestamp, 0.2, true)
|
||||||
val calculatedTimestamp = comboPlugin.calculateFakeBolusDate(bolus)
|
val calculatedTimestamp = comboPlugin.generatePumpBolusId(bolus)
|
||||||
Assert.assertEquals(calculatedTimestamp, calculatedTimestamp - calculatedTimestamp % 1000)
|
Assert.assertEquals(calculatedTimestamp, calculatedTimestamp - calculatedTimestamp % 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue