some rouding to make nicer on screen

This commit is contained in:
Milos Kozak 2016-06-20 12:03:05 +02:00
parent 5ac31bd0ca
commit aea505e543
8 changed files with 41 additions and 12 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </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" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange; import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.utils.Round;
public class DatabaseHelper extends OrmLiteSqliteOpenHelper { public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class); private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
@ -227,6 +228,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
this.delta = delta; this.delta = delta;
this.avgdelta = avgdelta; 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 @Nullable
@ -284,6 +292,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
result.round();
return result; return result;
} }
} }

View file

@ -132,8 +132,8 @@ public class DetermineBasalAdapterJS implements Parcelable {
mV8rt.add(PARAM_iobData, mIobData); mV8rt.add(PARAM_iobData, mIobData);
// Glucose status // Glucose status
mGlucoseStatus = new V8Object(mV8rt); mGlucoseStatus = new V8Object(mV8rt);
mGlucoseStatus.add("delta", 0);
mGlucoseStatus.add("glucose", 0); mGlucoseStatus.add("glucose", 0);
mGlucoseStatus.add("delta", 0);
mGlucoseStatus.add("avgdelta", 0); mGlucoseStatus.add("avgdelta", 0);
mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus); mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus);
// Meal data // Meal data

View file

@ -32,7 +32,7 @@ public class DetermineBasalResult extends APSResult {
} }
if (result.contains("duration")) { if (result.contains("duration")) {
duration = result.getInteger("duration"); duration = result.getInteger("duration");
changeRequested = changeRequested & true; changeRequested = changeRequested;
} else { } else {
duration = -1; duration = -1;
changeRequested = false; changeRequested = false;

View file

@ -6,6 +6,7 @@ import org.json.JSONObject;
import java.util.Date; import java.util.Date;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Round;
public class IobTotal { public class IobTotal {
public Double iob; public Double iob;
@ -50,6 +51,16 @@ public class IobTotal {
return result; 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() { public JSONObject json() {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
try { try {

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.plugins.ScriptReader;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment; import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.Round;
public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, PluginBase, APSInterface { public class OpenAPSMAFragment extends Fragment implements View.OnClickListener, PluginBase, APSInterface {
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class); 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 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 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); 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(); TreatmentsInterface treatments = MainActivity.getConfigBuilder().getActiveTreatments();
TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals(); TempBasalsInterface tempBasals = MainActivity.getConfigBuilder().getActiveTempBasals();
@ -270,7 +273,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
IobTotal bolusIob = treatments.getLastCalculation(); IobTotal bolusIob = treatments.getLastCalculation();
IobTotal basalIob = tempBasals.getLastCalculation(); IobTotal basalIob = tempBasals.getLastCalculation();
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob); IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
TreatmentsFragment.MealData mealData = treatments.getMealData(); TreatmentsFragment.MealData mealData = treatments.getMealData();

View file

@ -244,7 +244,7 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
calculatedTotalInsulin = 0d; calculatedTotalInsulin = 0d;
totalInsulin.setText(""); totalInsulin.setText("");
} else { } else {
calculatedTotalInsulin = roundTo(calculatedTotalInsulin, 0.05d); calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, 0.05d);
total.setText(""); total.setText("");
totalInsulin.setText(numberFormat.format(calculatedTotalInsulin) + "U"); totalInsulin.setText(numberFormat.format(calculatedTotalInsulin) + "U");
} }
@ -260,11 +260,4 @@ public class WizardDialogFragment extends DialogFragment implements OnClickListe
wizardDialogDeliverButton.setVisibility(Button.GONE); wizardDialogDeliverButton.setVisibility(Button.GONE);
} }
} }
private Double roundTo(Double x, Double step) {
if (x != 0d) {
return Math.round(x / step) * step;
}
return 0d;
}
} }

View 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;
}
}