- moved PumpHistoryEntryGroup to commons package

- added ProfileUtil with method to show basal profile so that we can display it
- changed PodHistoryActivity to display values (for Bolus, TBR and SetProfile)
This commit is contained in:
Andy Rozman 2020-01-01 18:45:15 +01:00
parent 827eee0c3a
commit 5230a2dda0
10 changed files with 167 additions and 60 deletions

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
package info.nightscout.androidaps.plugins.pump.common.defs;
import java.util.ArrayList;
import java.util.List;
@ -9,7 +9,7 @@ import info.nightscout.androidaps.R;
/**
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS.
*
* <p>
* Author: Andy {andy.rozman@gmail.com}
*/

View file

@ -0,0 +1,33 @@
package info.nightscout.androidaps.plugins.pump.common.utils;
import java.util.Locale;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
public class ProfileUtil {
public static String getProfileDisplayable(Profile profile, PumpType pumpType) {
StringBuilder stringBuilder = new StringBuilder();
for (Profile.ProfileValue basalValue : profile.getBasalValues()) {
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

@ -5,13 +5,14 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.medtronic.defs.MedtronicDeviceType;
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
/**
* This file was taken from GGC - GNU Gluco Control (ggc.sourceforge.net), application for diabetes
* management and modified/extended for AAPS.
*
* <p>
* Author: Andy {andy.rozman@gmail.com}
*/

View file

@ -22,9 +22,9 @@ import java.util.List;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashActivity;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryGroup;
public class MedtronicHistoryActivity extends NoSplashActivity {

View file

@ -1,22 +1,15 @@
package info.nightscout.androidaps.plugins.pump.omnipod;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.SystemClock;
import android.view.View;
import androidx.annotation.NonNull;
import com.tech.freak.wizardpager.model.Page;
import org.joda.time.LocalDateTime;
import org.mozilla.javascript.tools.jsc.Main;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,7 +20,6 @@ import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import info.nightscout.androidaps.BuildConfig;
import info.nightscout.androidaps.MainApp;
@ -46,7 +38,6 @@ import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomAction;
import info.nightscout.androidaps.plugins.general.actions.defs.CustomActionType;
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.general.overview.dialogs.ErrorHelperActivity;
import info.nightscout.androidaps.plugins.general.overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
@ -202,6 +193,11 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
refreshConfiguration();
}
// @Override
// protected void onResume() {
//
// }
private void refreshConfiguration() {
if (pumpStatusLocal != null) {
pumpStatusLocal.refreshConfiguration();
@ -767,9 +763,6 @@ public class OmnipodPumpPlugin extends PumpPluginAbstract implements OmnipodPump
}
@Override
public PumpEnactResult cancelTempBasal(boolean enforceNew) {

View file

@ -18,18 +18,21 @@ import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.GregorianCalendar;
import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.activities.NoSplashActivity;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntry;
import info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.common.data.TempBasalPair;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil;
import info.nightscout.androidaps.plugins.pump.omnipod.driver.db.PodHistory;
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil;
public class PodHistoryActivity extends NoSplashActivity {
@ -71,12 +74,11 @@ public class PodHistoryActivity extends NoSplashActivity {
this.filteredHistoryList.clear();
//LOG.debug("Items on full list: {}", list.size());
this.filteredHistoryList.addAll(fullHistoryList);
// TODO
// TODO grouping
// if (group == PumpHistoryEntryGroup.All) {
// this.filteredHistoryList.addAll(list);
@ -220,6 +222,8 @@ public class PodHistoryActivity extends NoSplashActivity {
this.historyList = historyList;
Collections.sort(this.historyList);
// this.notifyDataSetChanged();
}
@ -239,11 +243,74 @@ public class PodHistoryActivity extends NoSplashActivity {
if (record != null) {
holder.timeView.setText(record.getDateTimeString());
holder.typeView.setText(record.getPodDbEntryType().getResourceId());
holder.valueView.setText(""); // TODO
//holder.valueView.setText(""); // TODO
setValue(record, holder.valueView);
}
}
private void setValue(PodHistory historyEntry, TextView valueView) {
if (historyEntry.isSuccess()) {
switch (historyEntry.getPodDbEntryType()) {
case FillCannulaSetBasalProfile: {
if (historyEntry.getData() != null) {
Profile profile = OmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), Profile.class);
valueView.setText(ProfileUtil.getProfileDisplayable(profile, PumpType.Insulet_Omnipod));
}
}
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 SetBasalSchedule: {
Profile profile = OmnipodUtil.getGsonInstance().fromJson(historyEntry.getData(), Profile.class);
valueView.setText(ProfileUtil.getProfileDisplayable(profile, PumpType.Insulet_Omnipod));
}
break;
case GetPodStatus:
break;
case GetPodInfo:
break;
case SetTime:
break;
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])));
}
}
break;
case PairAndPrime:
case CancelTemporaryBasal:
case CancelTemporaryBasalForce:
case ConfigureAlerts:
case CancelBolus:
case DeactivatePod:
case ResetPodState:
case AcknowledgeAlerts:
case SuspendDelivery:
case ResumeDelivery:
case UnknownEntryType:
default:
break;
}
} else {
valueView.setText(historyEntry.getData());
}
}
@Override
public int getItemCount() {
return historyList.size();

View file

@ -168,7 +168,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
if (PodInitActionType.PairAndPrimeWizardStep.equals(podInitActionType)) {
try {
Disposable disposable = delegate.pairAndPrime().subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time));
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, null));
return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
@ -185,7 +185,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
throw new CommandInitializationException("Basal profile mapping failed", ex);
}
Disposable disposable = delegate.insertCannula(basalSchedule).subscribe(res -> //
handleSetupActionResult(podInitActionType, podInitReceiver, res, time));
handleSetupActionResult(podInitActionType, podInitReceiver, res, time, profile));
return new PumpEnactResult().success(true).enacted(true);
} catch (Exception ex) {
String comment = handleAndTranslateException(ex);
@ -316,7 +316,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
lastBolusUnits = pumpStatus.lastBolusAmount = unitsDelivered;
}
long pumpId = addSuccessToHistory(bolusStarted.getTime(), PodHistoryEntryType.SetBolus, unitsDelivered);
long pumpId = addSuccessToHistory(bolusStarted.getTime(), PodHistoryEntryType.SetBolus, unitsDelivered + ";" + detailedBolusInfo.carbs);
detailedBolusInfo.date = bolusStarted.getTime();
detailedBolusInfo.insulin = unitsDelivered;
@ -556,7 +556,7 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
}
private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res, long time) {
private void handleSetupActionResult(PodInitActionType podInitActionType, PodInitReceiver podInitReceiver, SetupActionResult res, long time, Profile profile) {
String comment = null;
switch (res.getResultType()) {
case FAILURE:
@ -573,8 +573,11 @@ public class AapsOmnipodManager implements OmnipodCommunicationManagerInterface
break;
}
addToHistory(time, podInitActionType == PodInitActionType.PairAndPrimeWizardStep ?
PodHistoryEntryType.PairAndPrime : PodHistoryEntryType.FillCannulaSetBasalProfile, comment, res.getResultType().isSuccess());
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());
}
podInitReceiver.returnInitTaskStatus(podInitActionType, res.getResultType().isSuccess(), comment);
}

View file

@ -15,7 +15,7 @@ import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil;
* Created by andy on 30.11.2019.
*/
@DatabaseTable(tableName = DatabaseHelper.DATABASE_POD_HISTORY)
public class PodHistory implements DbObjectBase {
public class PodHistory implements DbObjectBase, Comparable<PodHistory> {
private static Logger log = LoggerFactory.getLogger(L.DATABASE);
@ -134,4 +134,9 @@ public class PodHistory implements DbObjectBase {
public void setPodSerial(String podSerial) {
this.podSerial = podSerial;
}
@Override
public int compareTo(PodHistory otherOne) {
return (int) (this.date - otherOne.date);
}
}

View file

@ -1713,7 +1713,11 @@
<string name="omnipod_cmd_acknowledge_alerts">Acknowledge Alerts</string>
<string name="omnipod_cmd_suspend_delivery">Suspend Delivery</string>
<string name="omnipod_cmd_resume_delivery">Resume Delivery</string>
<string name="omnipod_cmd_umknown_entry">Unknown Entry</string>
<string name="omnipod_cmd_unknown_entry">Unknown Entry</string>
<string name="omnipod_cmd_bolus_value">%1$.1f U</string>
<string name="omnipod_cmd_bolus_value_with_carbs">%1$.1f U, CH=%2$.1f g</string>
<string name="omnipod_cmd_tbr_value">Rate: %1$.1f U, Duration: %2$d min</string>
<string name="omnipod_cmd_reset_pod_desc">If you press <b>OK</b>, the Pod state will be forcibly reset and you will not be able to communicate with the Pod anymore. Do this only if you can not communicate with the Pod anymore. If you can still communicate with the Pod, please use the <b>Deactivate Pod</b> option.</string>
<string name="omnipod_cmd_pod_history_na">Pod History not available at the moment.</string>

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump;
import org.junit.Before;
import org.junit.Ignore;
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil;
/**