From d58075a93c4b19c8284f4ebca01105eb4aea7660 Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Thu, 2 Jan 2020 23:22:57 +0100 Subject: [PATCH] - fixed problem parsing Bolus - reworked storing of Profile, instead of Profile we use Profile.ProfileValue[] --- .../pump/common/utils/ProfileUtil.java | 21 +++++++++++++ .../omnipod/dialogs/PodHistoryActivity.java | 30 ++++++++----------- .../driver/comm/AapsOmnipodManager.java | 4 +-- .../comm/MedtronicConverterUTest.java | 29 ++++++++++++++---- 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java index f29d8f90a1..5f1dd3c6ef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/common/utils/ProfileUtil.java @@ -29,5 +29,26 @@ public class ProfileUtil { return stringBuilder.toString(); } + public static String getBasalProfilesDisplayable(Profile.ProfileValue[] profiles, PumpType pumpType) { + + StringBuilder stringBuilder = new StringBuilder(); + + for (Profile.ProfileValue basalValue : profiles) { + + double basalValueValue = pumpType.determineCorrectBasalSize(basalValue.value); + + int hour = basalValue.timeAsSeconds / (60 * 60); + + stringBuilder.append((hour < 10 ? "0" : "") + hour + ":00"); + + stringBuilder.append(String.format(Locale.ENGLISH, "%.3f", basalValueValue)); + stringBuilder.append(", "); + } + if (stringBuilder.length() > 3) + return stringBuilder.toString().substring(0, stringBuilder.length() - 2); + else + return stringBuilder.toString(); + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodHistoryActivity.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodHistoryActivity.java index cc34b559df..27a5f81b2e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodHistoryActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dialogs/PodHistoryActivity.java @@ -13,8 +13,6 @@ import android.widget.TextView; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import org.json.JSONException; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,7 +22,6 @@ import java.util.Collections; import java.util.GregorianCalendar; import java.util.List; -import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.activities.NoSplashActivity; @@ -255,23 +252,20 @@ public class PodHistoryActivity extends NoSplashActivity { if (historyEntry.isSuccess()) { switch (historyEntry.getPodDbEntryType()) { - case FillCannulaSetBasalProfile: { - if (historyEntry.getData() != null) { - setProfileValue(historyEntry.getData(), valueView); - } - } - break; - case SetTemporaryBasal: { TempBasalPair tempBasalPair = OmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); valueView.setText(MainApp.gs(R.string.omnipod_cmd_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); } break; + case FillCannulaSetBasalProfile: case SetBasalSchedule: { - setProfileValue(historyEntry.getData(), valueView); + if (historyEntry.getData() != null) { + setProfileValue(historyEntry.getData(), valueView); + } } break; + case GetPodStatus: break; case GetPodInfo: @@ -281,10 +275,10 @@ public class PodHistoryActivity extends NoSplashActivity { case SetBolus: { if (historyEntry.getData().contains(";")) { - valueView.setText(MainApp.gs(R.string.omnipod_cmd_bolus_value, Double.valueOf(historyEntry.getData()))); - } else { String[] splitVal = historyEntry.getData().split(";"); valueView.setText(MainApp.gs(R.string.omnipod_cmd_bolus_value_with_carbs, Double.valueOf(splitVal[0]), Double.valueOf(splitVal[1]))); + } else { + valueView.setText(MainApp.gs(R.string.omnipod_cmd_bolus_value, Double.valueOf(historyEntry.getData()))); } } break; @@ -313,11 +307,13 @@ public class PodHistoryActivity extends NoSplashActivity { private void setProfileValue(String data, TextView valueView) { LOG.debug("Profile json:\n" + data); - Profile profile = null; + try { - profile = new Profile(new JSONObject(data), Constants.MGDL); - valueView.setText(ProfileUtil.getProfileDisplayable(profile, PumpType.Insulet_Omnipod)); - } catch (JSONException e) { + Profile.ProfileValue[] profileValuesArray = OmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class); + + //profile = new Profile(new JSONObject(data), Constants.MGDL); + valueView.setText(ProfileUtil.getBasalProfilesDisplayable(profileValuesArray, PumpType.Insulet_Omnipod)); + } catch (Exception e) { LOG.error("Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data); valueView.setText(""); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java index 72a0065322..c702e204ba 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/driver/comm/AapsOmnipodManager.java @@ -246,7 +246,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface throw new CommandInitializationException("Basal profile mapping failed", ex); } delegate.setBasalSchedule(basalSchedule, isBasalBeepsEnabled()); - addSuccessToHistory(time, PodHistoryEntryType.SetBasalSchedule, profile); + addSuccessToHistory(time, PodHistoryEntryType.SetBasalSchedule, profile.getBasalValues()); } catch (Exception ex) { if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) { addToHistory(time, PodHistoryEntryType.SetBasalSchedule, "Uncertain failure", false); @@ -583,7 +583,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { addToHistory(time, PodHistoryEntryType.PairAndPrime, comment, res.getResultType().isSuccess()); } else { - addToHistory(time, PodHistoryEntryType.FillCannulaSetBasalProfile, res.getResultType().isSuccess() ? profile : comment, res.getResultType().isSuccess()); + addToHistory(time, PodHistoryEntryType.FillCannulaSetBasalProfile, res.getResultType().isSuccess() ? profile.getBasalValues() : comment, res.getResultType().isSuccess()); } podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), comment); diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverterUTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverterUTest.java index 67c205fa37..1671dbd55a 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverterUTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/MedtronicConverterUTest.java @@ -1,9 +1,9 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm; +import java.util.Date; +import java.util.Locale; import java.util.Map; -import org.junit.Test; - import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.medtronic.data.dto.PumpSettingDTO; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; @@ -22,12 +22,12 @@ public class MedtronicConverterUTest { //@Test public void testDecoding554() { byte[] data = ByteUtil - .createByteArrayFromString("00 03 00 05 01 00 C8 00 A0 01 01 00 01 00 00 64 01 05 00 14 00 64 01 00 00"); + .createByteArrayFromString("00 03 00 05 01 00 C8 00 A0 01 01 00 01 00 00 64 01 05 00 14 00 64 01 00 00"); MedtronicUtil.setMedtronicPumpModel(MedtronicDeviceType.Medtronic_554_Veo); - Map settings = (Map)converter.convertResponse( - MedtronicCommandType.Settings, data); + Map settings = (Map) converter.convertResponse( + MedtronicCommandType.Settings, data); for (PumpSettingDTO pumpSettingDTO : settings.values()) { System.out.println("" + pumpSettingDTO.key + " = " + pumpSettingDTO.value); @@ -36,4 +36,23 @@ public class MedtronicConverterUTest { // byte[] data = new byte[] { 00 03 00 05 01 00 C8 00 A0 01 01 00 01 00 00 64 01 05 00 14 00 64 01 00 00 }; } + + //@Test + public void testLocale() { + Locale l = new Locale("en", "IE"); + + Locale.setDefault(l); + + Date date = new Date(); + + System.out.println("Date: toLocaleString: " + date.toLocaleString()); + System.out.println("Date: toString: " + date.toString()); + System.out.println("Date: toGMTString: " + date.toGMTString()); + + + for (String isoCountry : Locale.getISOCountries()) { + //System.out.println("ISO country: " + isoCountry); + } + } + }