some rouding to make nicer on screen
This commit is contained in:
parent
5ac31bd0ca
commit
aea505e543
8 changed files with 41 additions and 12 deletions
|
@ -37,7 +37,7 @@
|
|||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<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">
|
||||
<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">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -29,6 +29,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.utils.Round;
|
||||
|
||||
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
|
||||
|
@ -227,6 +228,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
this.delta = delta;
|
||||
this.avgdelta = avgdelta;
|
||||
}
|
||||
|
||||
public GlucoseStatus round() {
|
||||
this.glucose = Round.roundTo(this.glucose, 0.1);
|
||||
this.delta = Round.roundTo(this.delta, 0.01);
|
||||
this.avgdelta = Round.roundTo(this.avgdelta, 0.01);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -284,6 +292,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
result.round();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,8 +132,8 @@ public class DetermineBasalAdapterJS implements Parcelable {
|
|||
mV8rt.add(PARAM_iobData, mIobData);
|
||||
// Glucose status
|
||||
mGlucoseStatus = new V8Object(mV8rt);
|
||||
mGlucoseStatus.add("delta", 0);
|
||||
mGlucoseStatus.add("glucose", 0);
|
||||
mGlucoseStatus.add("delta", 0);
|
||||
mGlucoseStatus.add("avgdelta", 0);
|
||||
mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus);
|
||||
// Meal data
|
||||
|
|
|
@ -32,7 +32,7 @@ public class DetermineBasalResult extends APSResult {
|
|||
}
|
||||
if (result.contains("duration")) {
|
||||
duration = result.getInteger("duration");
|
||||
changeRequested = changeRequested & true;
|
||||
changeRequested = changeRequested;
|
||||
} else {
|
||||
duration = -1;
|
||||
changeRequested = false;
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.json.JSONObject;
|
|||
import java.util.Date;
|
||||
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.Round;
|
||||
|
||||
public class IobTotal {
|
||||
public Double iob;
|
||||
|
@ -50,6 +51,16 @@ public class IobTotal {
|
|||
return result;
|
||||
}
|
||||
|
||||
public IobTotal round() {
|
||||
this.iob = Round.roundTo(this.iob, 0.001);
|
||||
this.activity = Round.roundTo(this.activity, 0.0001);
|
||||
this.bolussnooze = Round.roundTo(this.bolussnooze, 0.0001);
|
||||
this.basaliob = Round.roundTo(this.basaliob, 0.001);
|
||||
this.netbasalinsulin = Round.roundTo(this.netbasalinsulin, 0.001);
|
||||
this.hightempinsulin = Round.roundTo(this.hightempinsulin, 0.001);
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
|
|
|
@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.ScriptReader;
|
|||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.Round;
|
||||
|
||||
public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, PluginBase, APSInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class);
|
||||
|
@ -262,6 +263,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
double maxBasal = Double.parseDouble(SP.getString("openapsma_max_basal", "1").replace(",", "."));
|
||||
double minBg = NSProfile.toMgdl(Double.parseDouble(SP.getString("openapsma_min_bg", minBgDefault).replace(",", ".")), units);
|
||||
double maxBg = NSProfile.toMgdl(Double.parseDouble(SP.getString("openapsma_max_bg", maxBgDefault).replace(",", ".")), units);
|
||||
minBg = Round.roundTo(minBg, 1d);
|
||||
maxBg = Round.roundTo(maxBg, 1d);
|
||||
|
||||
TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
|
||||
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
|
||||
|
@ -270,7 +273,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
IobTotal bolusIob = treatments.getLastCalculation();
|
||||
IobTotal basalIob = tempBasals.getLastCalculation();
|
||||
|
||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob);
|
||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||
|
||||
TreatmentsFragment.MealData mealData = treatments.getMealData();
|
||||
|
||||
|
|
|
@ -244,7 +244,7 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
|
|||
calculatedTotalInsulin = 0d;
|
||||
totalInsulin.setText("");
|
||||
} else {
|
||||
calculatedTotalInsulin = roundTo(calculatedTotalInsulin, 0.05d);
|
||||
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, 0.05d);
|
||||
total.setText("");
|
||||
totalInsulin.setText(numberFormat.format(calculatedTotalInsulin) + "U");
|
||||
}
|
||||
|
@ -260,11 +260,4 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
|
|||
wizardDialogDeliverButton.setVisibility(Button.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private Double roundTo(Double x, Double step) {
|
||||
if (x != 0d) {
|
||||
return Math.round(x / step) * step;
|
||||
}
|
||||
return 0d;
|
||||
}
|
||||
}
|
13
app/src/main/java/info/nightscout/utils/Round.java
Normal file
13
app/src/main/java/info/nightscout/utils/Round.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package info.nightscout.utils;
|
||||
|
||||
/**
|
||||
* Created by mike on 20.06.2016.
|
||||
*/
|
||||
public class Round {
|
||||
public static Double roundTo(Double x, Double step) {
|
||||
if (x != 0d) {
|
||||
return Math.round(x / step) * step;
|
||||
}
|
||||
return 0d;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue