accept single devicestatus, dynamic basal scale

This commit is contained in:
Milos Kozak 2016-08-09 15:09:51 +02:00
parent 77222a6c0a
commit a284f2fc38
3 changed files with 26 additions and 11 deletions

View file

@ -41,16 +41,15 @@
<intent-filter>
<!-- Receiver from NSClient -->
<action android:name="info.nightscout.client.NEW_SGV" />
<action android:name="info.nightscout.client.NEW_TREATMENT" />
<action android:name="info.nightscout.client.CHANGED_TREATMENT" />
<action android:name="info.nightscout.client.REMOVED_TREATMENT" />
<action android:name="info.nightscout.client.NEW_PROFILE" />
<action android:name="info.nightscout.client.NEW_SGV" />
<action android:name="info.nightscout.client.NEW_STATUS" />
<action android:name="info.nightscout.client.NEW_MBG" />
<action android:name="info.nightscout.client.NEW_DEVICESTATUS" />
<action android:name="info.nightscout.client.NEW_CAL" />
<action android:name="info.nightscout.client.NEW_STATUS" />
<!-- Receive new SMS messages -->
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<!-- Receiver from xDrip -->

View file

@ -217,6 +217,18 @@ public class DataService extends IntentService {
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
if (nsClientEnabled) {
try {
if (bundles.containsKey("devicestatus")) {
String devicestatusesstring = bundles.getString("devicestatus");
JSONObject devicestatusJson = new JSONObject(bundles.getString("devicestatus"));
if (devicestatusJson.has("pump")) {
// Objectives 0
ObjectivesPlugin objectivesPlugin = (ObjectivesPlugin) MainApp.getSpecificPlugin(ObjectivesPlugin.class);
if (objectivesPlugin != null) {
objectivesPlugin.pumpStatusIsAvailableInNS = true;
objectivesPlugin.saveProgress();
}
}
}
if (bundles.containsKey("devicestatuses")) {
String devicestatusesstring = bundles.getString("devicestatuses");
JSONArray jsonArray = new JSONArray(devicestatusesstring);

View file

@ -458,15 +458,18 @@ public class OverviewFragment extends Fragment {
}
Double maxAllowedBasal = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit);
Double maxBasalValueFound = 0d;
long now = new Date().getTime();
List<BarDataPoint> basalArray = new ArrayList<BarDataPoint>();
for (long time = fromTime; time < now; time += 5 * 60 * 1000L) {
TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date(time));
Double basal = 0d;
if (tb != null)
basalArray.add(new BarDataPoint(time, tb.tempBasalConvertedToAbsolute(new Date(time)), true));
basalArray.add(new BarDataPoint(time, basal = tb.tempBasalConvertedToAbsolute(new Date(time)), true));
else
basalArray.add(new BarDataPoint(time, profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false));
basalArray.add(new BarDataPoint(time, basal = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false));
maxBasalValueFound = Math.max(maxBasalValueFound, basal);
}
BarDataPoint[] basal = new BarDataPoint[basalArray.size()];
basal = basalArray.toArray(basal);
@ -480,13 +483,6 @@ public class OverviewFragment extends Fragment {
}
});
// set second scale
bgGraph.getSecondScale().addSeries(basalsSeries);
bgGraph.getSecondScale().setMinY(0);
bgGraph.getSecondScale().setMaxY(maxAllowedBasal * 4);
bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide
// **** BG graph ****
List<BgReading> bgReadingsArray = MainApp.getDbHelper().getDataFromTime(fromTime);
List<BgReading> inRangeArray = new ArrayList<BgReading>();
@ -578,6 +574,14 @@ public class OverviewFragment extends Fragment {
bgGraph.getViewport().setMinY(0);
bgGraph.getViewport().setYAxisBoundsManual(true);
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines);
// set second scale
bgGraph.getSecondScale().addSeries(basalsSeries);
bgGraph.getSecondScale().setMinY(0);
bgGraph.getSecondScale().setMaxY(maxBgValue / lowLine * maxBasalValueFound * 1.2d);
bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide
}
}