Merge pull request #156 from AAPS-Omnipod/show-total-dose-in-fragment

Show total dose in fragment
This commit is contained in:
bartsopers 2020-08-23 19:41:35 +02:00 committed by GitHub
commit f94c73a911
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 1 deletions

View file

@ -248,6 +248,7 @@ class OmnipodFragment : DaggerFragment() {
omnipod_pod_firmware_version.text = "-" omnipod_pod_firmware_version.text = "-"
omnipod_pod_expiry.text = "-" omnipod_pod_expiry.text = "-"
omnipod_basabasalrate.text = "-" omnipod_basabasalrate.text = "-"
omnipod_total_delivered.text = "-"
omnipod_reservoir.text = "-" omnipod_reservoir.text = "-"
omnipod_tempbasal.text = "-" omnipod_tempbasal.text = "-"
omnipod_lastbolus.text = "-" omnipod_lastbolus.text = "-"
@ -279,6 +280,13 @@ class OmnipodFragment : DaggerFragment() {
omnipod_tempbasal.text = activePlugin.activeTreatments omnipod_tempbasal.text = activePlugin.activeTreatments
.getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-" .getTempBasalFromHistory(System.currentTimeMillis())?.toStringFull() ?: "-"
// total delivered
omnipod_total_delivered.text = if (podStateManager.isPodActivationCompleted) {
resourceHelper.gs(R.string.omnipod_total_delivered, podStateManager.totalInsulinDelivered - OmnipodConst.POD_SETUP_UNITS);
} else {
"-"
}
// reservoir // reservoir
if (podStateManager.reservoirLevel == null) { if (podStateManager.reservoirLevel == null) {
omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_over50) omnipod_reservoir.text = resourceHelper.gs(R.string.omnipod_reservoir_over50)

View file

@ -20,6 +20,7 @@ public class StatusResponse extends MessageBlock {
private final PodProgressStatus podProgressStatus; private final PodProgressStatus podProgressStatus;
private final Duration timeActive; private final Duration timeActive;
private final Double reservoirLevel; private final Double reservoirLevel;
private final int ticksDelivered;
private final double insulinDelivered; private final double insulinDelivered;
private final double insulinNotDelivered; private final double insulinNotDelivered;
private final byte podMessageCounter; private final byte podMessageCounter;
@ -40,7 +41,8 @@ public class StatusResponse extends MessageBlock {
int highInsulinBits = (encodedData[2] & 0xF) << 9; int highInsulinBits = (encodedData[2] & 0xF) << 9;
int middleInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[3]) << 1; int middleInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[3]) << 1;
int lowInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[4]) >>> 7; int lowInsulinBits = ByteUtil.convertUnsignedByteToInt(encodedData[4]) >>> 7;
insulinDelivered = OmnipodConst.POD_PULSE_SIZE * (highInsulinBits | middleInsulinBits | lowInsulinBits); ticksDelivered = (highInsulinBits | middleInsulinBits | lowInsulinBits);
insulinDelivered = OmnipodConst.POD_PULSE_SIZE * ticksDelivered;
podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf); podMessageCounter = (byte) ((encodedData[4] >>> 3) & 0xf);
insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5])); insulinNotDelivered = OmnipodConst.POD_PULSE_SIZE * (((encodedData[4] & 0x03) << 8) | ByteUtil.convertUnsignedByteToInt(encodedData[5]));
@ -75,6 +77,8 @@ public class StatusResponse extends MessageBlock {
return reservoirLevel; return reservoirLevel;
} }
public int getTicksDelivered() { return ticksDelivered; }
public double getInsulinDelivered() { public double getInsulinDelivered() {
return insulinDelivered; return insulinDelivered;
} }

View file

@ -302,6 +302,8 @@ public abstract class PodStateManager {
return getSafe(() -> podState.getReservoirLevel()); return getSafe(() -> podState.getReservoirLevel());
} }
public final Double getTotalInsulinDelivered() { return getSafe(() -> podState.getTotalInsulinDelivered()); }
public final Duration getScheduleOffset() { public final Duration getScheduleOffset() {
DateTime now = getTime(); DateTime now = getTime();
return new Duration(now.withTimeAtStartOfDay(), now); return new Duration(now.withTimeAtStartOfDay(), now);
@ -373,6 +375,7 @@ public abstract class PodStateManager {
podState.setActiveAlerts(statusResponse.getAlerts()); podState.setActiveAlerts(statusResponse.getAlerts());
podState.setLastDeliveryStatus(statusResponse.getDeliveryStatus()); podState.setLastDeliveryStatus(statusResponse.getDeliveryStatus());
podState.setReservoirLevel(statusResponse.getReservoirLevel()); podState.setReservoirLevel(statusResponse.getReservoirLevel());
podState.setTotalTicksDelivered(statusResponse.getTicksDelivered());
podState.setPodProgressStatus(statusResponse.getPodProgressStatus()); podState.setPodProgressStatus(statusResponse.getPodProgressStatus());
podState.setLastUpdatedFromStatusResponse(DateTime.now()); podState.setLastUpdatedFromStatusResponse(DateTime.now());
}); });
@ -469,6 +472,7 @@ public abstract class PodStateManager {
private DateTime expiresAt; private DateTime expiresAt;
private PodInfoFaultEvent faultEvent; private PodInfoFaultEvent faultEvent;
private Double reservoirLevel; private Double reservoirLevel;
private Integer totalTicksDelivered;
private boolean suspended; private boolean suspended;
private NonceState nonceState; private NonceState nonceState;
private PodProgressStatus podProgressStatus; private PodProgressStatus podProgressStatus;
@ -602,6 +606,20 @@ public abstract class PodStateManager {
this.reservoirLevel = reservoirLevel; this.reservoirLevel = reservoirLevel;
} }
public Integer getTotalTicksDelivered() {
return totalTicksDelivered;
}
public Double getTotalInsulinDelivered() {
if (totalTicksDelivered != null) {
return totalTicksDelivered * OmnipodConst.POD_PULSE_SIZE;
} else {
return null;
}
}
void setTotalTicksDelivered(Integer totalTicksDelivered) { this.totalTicksDelivered = totalTicksDelivered; }
public boolean isSuspended() { public boolean isSuspended() {
return suspended; return suspended;
} }

View file

@ -53,4 +53,5 @@ public class OmnipodConst {
public static final double POD_PRIME_BOLUS_UNITS = 2.6; public static final double POD_PRIME_BOLUS_UNITS = 2.6;
public static final double POD_CANNULA_INSERTION_BOLUS_UNITS = 0.5; public static final double POD_CANNULA_INSERTION_BOLUS_UNITS = 0.5;
public static final double POD_SETUP_UNITS = POD_PRIME_BOLUS_UNITS + POD_CANNULA_INSERTION_BOLUS_UNITS;
} }

View file

@ -517,6 +517,42 @@
android:layout_marginBottom="5dp" android:layout_marginBottom="5dp"
android:background="@color/listdelimiter" /> android:background="@color/listdelimiter" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/omnipod_total_delivered_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/omnipod_total_delivered"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:paddingLeft="5dp"
android:textColor="@android:color/white"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -26,6 +26,8 @@
<string name="omnipod_moments_ago">Moments ago</string> <string name="omnipod_moments_ago">Moments ago</string>
<string name="omnipod_pod_mgmt">Pod Mgmt</string> <string name="omnipod_pod_mgmt">Pod Mgmt</string>
<string name="omnipod_pod_status">Pod Status</string> <string name="omnipod_pod_status">Pod Status</string>
<string name="omnipod_total_delivered_label">Total Delivered</string>
<string name="omnipod_total_delivered">%1$.2f U</string>
<string name="omnipod_reservoir_left">%1$.2f U left</string> <string name="omnipod_reservoir_left">%1$.2f U left</string>
<string name="omnipod_reservoir_over50">Over 50 U</string> <string name="omnipod_reservoir_over50">Over 50 U</string>
<string name="omnipod_pod_address">Pod Address</string> <string name="omnipod_pod_address">Pod Address</string>

View file

@ -45,6 +45,7 @@ public class StatusResponseTest {
assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, statusResponse.getPodProgressStatus()); assertEquals(PodProgressStatus.ABOVE_FIFTY_UNITS, statusResponse.getPodProgressStatus());
assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); assertNull("Reservoir level should be null", statusResponse.getReservoirLevel());
assertEquals(Duration.standardMinutes(1307).getMillis(), statusResponse.getTimeActive().getMillis()); assertEquals(Duration.standardMinutes(1307).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(1201, statusResponse.getTicksDelivered());
assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001); assertEquals(60.05, statusResponse.getInsulinDelivered(), 0.000001);
assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(15, statusResponse.getPodMessageCounter());
assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001); assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001);
@ -62,6 +63,7 @@ public class StatusResponseTest {
assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus());
assertEquals(24.4, statusResponse.getReservoirLevel(), 0.000001); assertEquals(24.4, statusResponse.getReservoirLevel(), 0.000001);
assertEquals(Duration.standardMinutes(4261).getMillis(), statusResponse.getTimeActive().getMillis()); assertEquals(Duration.standardMinutes(4261).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(3134, statusResponse.getTicksDelivered());
assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001); assertEquals(156.7, statusResponse.getInsulinDelivered(), 0.000001);
assertEquals(13, statusResponse.getPodMessageCounter()); assertEquals(13, statusResponse.getPodMessageCounter());
assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001); assertEquals(0, statusResponse.getInsulinNotDelivered(), 0.000001);
@ -79,6 +81,7 @@ public class StatusResponseTest {
assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis()); assertEquals(Duration.standardMinutes(8191).getMillis(), statusResponse.getTimeActive().getMillis());
assertEquals(OmnipodConst.POD_PULSE_SIZE * 1023, statusResponse.getInsulinNotDelivered(), 0.000001); assertEquals(OmnipodConst.POD_PULSE_SIZE * 1023, statusResponse.getInsulinNotDelivered(), 0.000001);
assertNull("Reservoir level should be null", statusResponse.getReservoirLevel()); assertNull("Reservoir level should be null", statusResponse.getReservoirLevel());
assertEquals(8191, statusResponse.getTicksDelivered());
assertEquals(OmnipodConst.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001); assertEquals(OmnipodConst.POD_PULSE_SIZE * 8191, statusResponse.getInsulinDelivered(), 0.0000001);
assertEquals(15, statusResponse.getPodMessageCounter()); assertEquals(15, statusResponse.getPodMessageCounter());
assertEquals(8, statusResponse.getAlerts().getAlertSlots().size()); assertEquals(8, statusResponse.getAlerts().getAlertSlots().size());
@ -94,6 +97,7 @@ public class StatusResponseTest {
assertTrue(Duration.standardMinutes(3547).isEqual(statusResponse.getTimeActive())); assertTrue(Duration.standardMinutes(3547).isEqual(statusResponse.getTimeActive()));
assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus()); assertEquals(DeliveryStatus.NORMAL, statusResponse.getDeliveryStatus());
assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus()); assertEquals(PodProgressStatus.FIFTY_OR_LESS_UNITS, statusResponse.getPodProgressStatus());
assertEquals(2589, statusResponse.getTicksDelivered());
assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001); assertEquals(129.45, statusResponse.getInsulinDelivered(), 0.00001);
assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001); assertEquals(46.00, statusResponse.getReservoirLevel(), 0.00001);
assertEquals(2.2, statusResponse.getInsulinNotDelivered(), 0.0001); assertEquals(2.2, statusResponse.getInsulinNotDelivered(), 0.0001);