use bg targets in overview from nightscout

This commit is contained in:
Milos Kozak 2016-06-27 19:34:59 +02:00
parent a3d32fcb44
commit 877b760aef
4 changed files with 29 additions and 5 deletions

View file

@ -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">

View file

@ -36,6 +36,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
import info.nightscout.androidaps.receivers.NSClientDataReceiver;
@ -169,6 +170,26 @@ public class DataService extends IntentService {
} else {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
}
if (bundles.containsKey("status")) {
try {
JSONObject statusJson = new JSONObject(bundles.getString("status"));
if (statusJson.has("settings")) {
JSONObject settings = statusJson.getJSONObject("settings");
if (settings.has("thresholds")) {
JSONObject thresholds = settings.getJSONObject("thresholds");
OverviewFragment overviewFragment = (OverviewFragment) MainActivity.getSpecificPlugin(OverviewFragment.class);
if (thresholds.has("bgTargetTop")) {
overviewFragment.bgTargetHigh = thresholds.getDouble("bgTargetTop");
}
if (thresholds.has("bgTargetBottom")) {
overviewFragment.bgTargetLow = thresholds.getDouble("bgTargetBottom");
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
if (nsClientEnabled) {

View file

@ -183,7 +183,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
queryBuilder.orderBy("timeIndex", true);
Where where = queryBuilder.where();
where.ge("timeIndex", (long) Math.ceil(mills / 60000d));
where.ge("timeIndex", mills);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgReadings = daoBgreadings.query(preparedQuery);
return bgReadings;

View file

@ -88,6 +88,9 @@ public class OverviewFragment extends Fragment implements PluginBase {
Handler loopHandler = new Handler();
Runnable refreshLoop = null;
public Double bgTargetLow = 80d;
public Double bgTargetHigh = 180d;
public OverviewFragment() {
super();
registerBus();
@ -342,7 +345,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
log.debug("EventNewBG: Activity is null");
}
@Subscribe
@Subscribe
public void onStatusEvent(final EventRefreshOpenLoop ev) {
Activity activity = getActivity();
if (activity != null)
@ -473,8 +476,8 @@ public class OverviewFragment extends Fragment implements PluginBase {
long toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding
long fromTime = toTime - hoursToFetch * 60 * 60 * 1000l;
Double lowLine = NSProfile.toUnits(80d, 4d, units); // TODO: make this customisable
Double highLine = NSProfile.toUnits(180d, 10d, units);
Double lowLine = NSProfile.fromMgdlToUnits(bgTargetLow, units);
Double highLine = NSProfile.fromMgdlToUnits(bgTargetHigh, units);
BarGraphSeries<DataPoint> basalsSeries = null;
LineGraphSeries<DataPoint> seriesLow = null;