Distribute carbs strictly within timeframe
This commit is contained in:
parent
bf02edd871
commit
10b9171afe
1 changed files with 5 additions and 6 deletions
|
@ -401,13 +401,12 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
|
||||||
createCarb(carbsAfterConstraints, time, finalNotes);
|
createCarb(carbsAfterConstraints, time, finalNotes);
|
||||||
} else {
|
} else {
|
||||||
long remainingCarbs = carbsAfterConstraints;
|
long remainingCarbs = carbsAfterConstraints;
|
||||||
long carbTime = time;
|
int ticks = (duration * 4); //duration guaranteed to be integer greater zero
|
||||||
long smallCarbAmount = Math.round(remainingCarbs / (editDuration.getValue() * 4));
|
for (int i = 0; i < ticks; i++){
|
||||||
if (smallCarbAmount == 0) smallCarbAmount = 1;
|
long carbTime = time + i * 15 * 60 * 1000;
|
||||||
while (remainingCarbs > 0) {
|
long smallCarbAmount = Math.round((1d * remainingCarbs) / (ticks-i)); //on last iteration (ticks-i) is 1 -> smallCarbAmount == remainingCarbs
|
||||||
createCarb(Math.min(smallCarbAmount, remainingCarbs), carbTime, finalNotes);
|
|
||||||
remainingCarbs -= smallCarbAmount;
|
remainingCarbs -= smallCarbAmount;
|
||||||
carbTime += 15 * 60 * 1000;
|
createCarb(smallCarbAmount, carbTime, finalNotes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue