- fixed problem parsing Bolus

- reworked storing of Profile, instead of Profile we use Profile.ProfileValue[]
This commit is contained in:
Andy Rozman 2020-01-02 23:22:57 +01:00
parent 7097689c28
commit d58075a93c
4 changed files with 60 additions and 24 deletions

View file

@ -29,5 +29,26 @@ public class ProfileUtil {
return stringBuilder.toString(); 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();
}
} }

View file

@ -13,8 +13,6 @@ import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -24,7 +22,6 @@ import java.util.Collections;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashActivity; import info.nightscout.androidaps.activities.NoSplashActivity;
@ -255,23 +252,20 @@ public class PodHistoryActivity extends NoSplashActivity {
if (historyEntry.isSuccess()) { if (historyEntry.isSuccess()) {
switch (historyEntry.getPodDbEntryType()) { switch (historyEntry.getPodDbEntryType()) {
case FillCannulaSetBasalProfile: {
if (historyEntry.getData() != null) {
setProfileValue(historyEntry.getData(), valueView);
}
}
break;
case SetTemporaryBasal: { case SetTemporaryBasal: {
TempBasalPair tempBasalPair = OmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class); TempBasalPair tempBasalPair = OmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), TempBasalPair.class);
valueView.setText(MainApp.gs(R.string.omnipod_cmd_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes())); valueView.setText(MainApp.gs(R.string.omnipod_cmd_tbr_value, tempBasalPair.getInsulinRate(), tempBasalPair.getDurationMinutes()));
} }
break; break;
case FillCannulaSetBasalProfile:
case SetBasalSchedule: { case SetBasalSchedule: {
setProfileValue(historyEntry.getData(), valueView); if (historyEntry.getData() != null) {
setProfileValue(historyEntry.getData(), valueView);
}
} }
break; break;
case GetPodStatus: case GetPodStatus:
break; break;
case GetPodInfo: case GetPodInfo:
@ -281,10 +275,10 @@ public class PodHistoryActivity extends NoSplashActivity {
case SetBolus: { case SetBolus: {
if (historyEntry.getData().contains(";")) { if (historyEntry.getData().contains(";")) {
valueView.setText(MainApp.gs(R.string.omnipod_cmd_bolus_value, Double.valueOf(historyEntry.getData())));
} else {
String[] splitVal = historyEntry.getData().split(";"); 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]))); 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; break;
@ -313,11 +307,13 @@ public class PodHistoryActivity extends NoSplashActivity {
private void setProfileValue(String data, TextView valueView) { private void setProfileValue(String data, TextView valueView) {
LOG.debug("Profile json:\n" + data); LOG.debug("Profile json:\n" + data);
Profile profile = null;
try { try {
profile = new Profile(new JSONObject(data), Constants.MGDL); Profile.ProfileValue[] profileValuesArray = OmnipodUtil.getGsonInstance().fromJson(data, Profile.ProfileValue[].class);
valueView.setText(ProfileUtil.getProfileDisplayable(profile, PumpType.Insulet_Omnipod));
} catch (JSONException e) { //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); LOG.error("Problem parsing Profile json. Ex: {}, Data:\n{}", e.getMessage(), data);
valueView.setText(""); valueView.setText("");
} }

View file

@ -246,7 +246,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
throw new CommandInitializationException("Basal profile mapping failed", ex); throw new CommandInitializationException("Basal profile mapping failed", ex);
} }
delegate.setBasalSchedule(basalSchedule, isBasalBeepsEnabled()); delegate.setBasalSchedule(basalSchedule, isBasalBeepsEnabled());
addSuccessToHistory(time, PodHistoryEntryType.SetBasalSchedule, profile); addSuccessToHistory(time, PodHistoryEntryType.SetBasalSchedule, profile.getBasalValues());
} catch (Exception ex) { } catch (Exception ex) {
if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) { if ((ex instanceof OmnipodException) && !((OmnipodException) ex).isCertainFailure()) {
addToHistory(time, PodHistoryEntryType.SetBasalSchedule, "Uncertain failure", false); addToHistory(time, PodHistoryEntryType.SetBasalSchedule, "Uncertain failure", false);
@ -583,7 +583,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) { if (podInitActionType == PodInitActionType.PairAndPrimeWizardStep) {
addToHistory(time, PodHistoryEntryType.PairAndPrime, comment, res.getResultType().isSuccess()); addToHistory(time, PodHistoryEntryType.PairAndPrime, comment, res.getResultType().isSuccess());
} else { } 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); podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), comment);

View file

@ -1,9 +1,9 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm; package info.nightscout.androidaps.plugins.pump.medtronic.comm;
import java.util.Date;
import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.junit.Test;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; 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.data.dto.PumpSettingDTO;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType; import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicCommandType;
@ -22,12 +22,12 @@ public class MedtronicConverterUTest {
//@Test //@Test
public void testDecoding554() { public void testDecoding554() {
byte[] data = ByteUtil 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); MedtronicUtil.setMedtronicPumpModel(MedtronicDeviceType.Medtronic_554_Veo);
Map<String, PumpSettingDTO> settings = (Map<String, PumpSettingDTO>)converter.convertResponse( Map<String, PumpSettingDTO> settings = (Map<String, PumpSettingDTO>) converter.convertResponse(
MedtronicCommandType.Settings, data); MedtronicCommandType.Settings, data);
for (PumpSettingDTO pumpSettingDTO : settings.values()) { for (PumpSettingDTO pumpSettingDTO : settings.values()) {
System.out.println("" + pumpSettingDTO.key + " = " + pumpSettingDTO.value); 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 }; // 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);
}
}
} }