better timestamps on Loop tab

This commit is contained in:
Milos Kozak 2020-02-02 22:12:54 +01:00
parent 8bcf901e6f
commit b5a64f4d85
8 changed files with 231 additions and 61 deletions

View file

@ -77,8 +77,11 @@ class LoopFragment : Fragment() {
loop_source?.text = it.source ?: "" loop_source?.text = it.source ?: ""
loop_lastrun?.text = it.lastAPSRun?.let { lastRun -> DateUtil.dateAndTimeString(lastRun.time) } loop_lastrun?.text = it.lastAPSRun?.let { lastRun -> DateUtil.dateAndTimeString(lastRun.time) }
?: "" ?: ""
loop_lastenact?.text = it.lastAPSRun?.let { lastEnact -> DateUtil.dateAndTimeString(lastEnact.time) } loop_smbrequest_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastSMBRequest)
?: "" loop_smbexecution_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastSMBEnact)
loop_tbrrequest_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastTBRRequest)
loop_tbrexecution_time?.text = DateUtil.dateAndTimeAndSecondsString(it.lastTBREnact)
loop_tbrsetbypump?.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) } loop_tbrsetbypump?.text = it.tbrSetByPump?.let { tbrSetByPump -> HtmlHelper.fromHtml(tbrSetByPump.toHtml()) }
?: "" ?: ""
loop_smbsetbypump?.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) } loop_smbsetbypump?.text = it.smbSetByPump?.let { smbSetByPump -> HtmlHelper.fromHtml(smbSetByPump.toHtml()) }
@ -102,7 +105,10 @@ class LoopFragment : Fragment() {
loop_constraintsprocessed?.text = "" loop_constraintsprocessed?.text = ""
loop_source?.text = "" loop_source?.text = ""
loop_lastrun?.text = "" loop_lastrun?.text = ""
loop_lastenact?.text = "" loop_smbrequest_time?.text = ""
loop_smbexecution_time?.text = ""
loop_tbrrequest_time?.text = ""
loop_tbrexecution_time?.text = ""
loop_tbrsetbypump?.text = "" loop_tbrsetbypump?.text = ""
loop_smbsetbypump?.text = "" loop_smbsetbypump?.text = ""
} }

View file

@ -57,6 +57,7 @@ import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback; import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.queue.commands.Command; import info.nightscout.androidaps.queue.commands.Command;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy; import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
@ -84,9 +85,9 @@ public class LoopPlugin extends PluginBase {
return loopPlugin; return loopPlugin;
} }
private long loopSuspendedTill = 0L; // end of manual loop suspend private long loopSuspendedTill; // end of manual loop suspend
private boolean isSuperBolus = false; private boolean isSuperBolus;
private boolean isDisconnected = false; private boolean isDisconnected;
public class LastRun { public class LastRun {
public APSResult request = null; public APSResult request = null;
@ -95,8 +96,11 @@ public class LoopPlugin extends PluginBase {
public PumpEnactResult smbSetByPump = null; public PumpEnactResult smbSetByPump = null;
public String source = null; public String source = null;
public Date lastAPSRun = null; public Date lastAPSRun = null;
public Date lastEnact = null; public long lastTBREnact = 0;
public Date lastOpenModeAccept; public long lastSMBEnact = 0;
public long lastTBRRequest = 0;
public long lastSMBRequest = 0;
public long lastOpenModeAccept;
} }
static public LastRun lastRun = null; static public LastRun lastRun = null;
@ -342,6 +346,10 @@ public class LoopPlugin extends PluginBase {
lastRun.source = ((PluginBase) usedAPS).getName(); lastRun.source = ((PluginBase) usedAPS).getName();
lastRun.tbrSetByPump = null; lastRun.tbrSetByPump = null;
lastRun.smbSetByPump = null; lastRun.smbSetByPump = null;
lastRun.lastTBREnact = 0;
lastRun.lastTBRRequest = 0;
lastRun.lastSMBEnact = 0;
lastRun.lastSMBRequest = 0;
NSUpload.uploadDeviceStatus(); NSUpload.uploadDeviceStatus();
@ -378,14 +386,17 @@ public class LoopPlugin extends PluginBase {
public void run() { public void run() {
if (result.enacted || result.success) { if (result.enacted || result.success) {
lastRun.tbrSetByPump = result; lastRun.tbrSetByPump = result;
lastRun.lastEnact = lastRun.lastAPSRun; lastRun.lastTBRRequest = lastRun.lastAPSRun.getTime();
lastRun.lastTBREnact = DateUtil.now();
RxBus.INSTANCE.send(new EventLoopUpdateGui());
applySMBRequest(resultAfterConstraints, new Callback() { applySMBRequest(resultAfterConstraints, new Callback() {
@Override @Override
public void run() { public void run() {
//Callback is only called if a bolus was acutally requested //Callback is only called if a bolus was acutally requested
if (result.enacted || result.success) { if (result.enacted || result.success) {
lastRun.smbSetByPump = result; lastRun.smbSetByPump = result;
lastRun.lastEnact = lastRun.lastAPSRun; lastRun.lastSMBRequest = lastRun.lastAPSRun.getTime();
lastRun.lastSMBEnact = DateUtil.now();
} else { } else {
new Thread(() -> { new Thread(() -> {
SystemClock.sleep(1000); SystemClock.sleep(1000);
@ -465,8 +476,9 @@ public class LoopPlugin extends PluginBase {
public void run() { public void run() {
if (result.enacted) { if (result.enacted) {
lastRun.tbrSetByPump = result; lastRun.tbrSetByPump = result;
lastRun.lastEnact = new Date(); lastRun.lastTBRRequest = lastRun.lastAPSRun.getTime();
lastRun.lastOpenModeAccept = new Date(); lastRun.lastTBREnact = DateUtil.now();
lastRun.lastOpenModeAccept = DateUtil.now();
NSUpload.uploadDeviceStatus(); NSUpload.uploadDeviceStatus();
SP.incInt(R.string.key_ObjectivesmanualEnacts); SP.incInt(R.string.key_ObjectivesmanualEnacts);
} }

View file

@ -1113,7 +1113,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
if (acceptTempButton != null) { if (acceptTempButton != null) {
boolean showAcceptButton = !closedLoopEnabled.value(); // Open mode needed boolean showAcceptButton = !closedLoopEnabled.value(); // Open mode needed
showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist showAcceptButton = showAcceptButton && finalLastRun != null && finalLastRun.lastAPSRun != null; // aps result must exist
showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == null || finalLastRun.lastOpenModeAccept.getTime() < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result showAcceptButton = showAcceptButton && (finalLastRun.lastOpenModeAccept == 0 || finalLastRun.lastOpenModeAccept < finalLastRun.lastAPSRun.getTime()); // never accepted or before last result
showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.isChangeRequested(); // change is requested showAcceptButton = showAcceptButton && finalLastRun.constraintsProcessed.isChangeRequested(); // change is requested
if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) { if (showAcceptButton && pump.isInitialized() && !pump.isSuspended() && LoopPlugin.getPlugin().isEnabled(PluginType.LOOP)) {

View file

@ -502,8 +502,8 @@ public class ActionStringHandler {
if (LoopPlugin.lastRun.lastAPSRun != null) if (LoopPlugin.lastRun.lastAPSRun != null)
ret += "\nLast Run: " + DateUtil.timeString(LoopPlugin.lastRun.lastAPSRun); ret += "\nLast Run: " + DateUtil.timeString(LoopPlugin.lastRun.lastAPSRun);
if (LoopPlugin.lastRun.lastEnact != null) if (LoopPlugin.lastRun.lastTBREnact != 0)
ret += "\nLast Enact: " + DateUtil.timeString(LoopPlugin.lastRun.lastEnact); ret += "\nLast Enact: " + DateUtil.timeString(LoopPlugin.lastRun.lastTBREnact);
} }

View file

@ -735,7 +735,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
//OpenAPS status //OpenAPS status
if (Config.APS) { if (Config.APS) {
//we are AndroidAPS //we are AndroidAPS
openApsStatus = LoopPlugin.lastRun != null && LoopPlugin.lastRun.lastEnact != null && LoopPlugin.lastRun.lastEnact.getTime() != 0 ? LoopPlugin.lastRun.lastEnact.getTime() : -1; openApsStatus = LoopPlugin.lastRun != null && LoopPlugin.lastRun.lastTBREnact != 0 ? LoopPlugin.lastRun.lastTBREnact : -1;
} else { } else {
//NSClient or remote //NSClient or remote
openApsStatus = NSDeviceStatus.getOpenApsTimestamp(); openApsStatus = NSDeviceStatus.getOpenApsTimestamp();

View file

@ -141,6 +141,14 @@ public class DateUtil {
return new DateTime(mills).toString(DateTimeFormat.forPattern(format)); return new DateTime(mills).toString(DateTimeFormat.forPattern(format));
} }
public static String timeStringWithSeconds(long mills) {
String format = "hh:mm:ssa";
if (android.text.format.DateFormat.is24HourFormat(MainApp.instance())) {
format = "HH:mm:ss";
}
return new DateTime(mills).toString(DateTimeFormat.forPattern(format));
}
public static String timeFullString(long mills) { public static String timeFullString(long mills) {
return new DateTime(mills).toString(DateTimeFormat.fullTime()); return new DateTime(mills).toString(DateTimeFormat.fullTime());
} }
@ -158,6 +166,11 @@ public class DateUtil {
return dateString(mills) + " " + timeString(mills); return dateString(mills) + " " + timeString(mills);
} }
public static String dateAndTimeAndSecondsString(long mills) {
if (mills == 0) return "";
return dateString(mills) + " " + timeStringWithSeconds(mills);
}
public static String dateAndTimeFullString(long mills) { public static String dateAndTimeFullString(long mills) {
return dateString(mills) + " " + timeFullString(mills); return dateString(mills) + " " + timeFullString(mills);
} }

View file

@ -57,51 +57,6 @@
</LinearLayout> </LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
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="2"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/openapsma_lastenact_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/loop_lastenact"
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>
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"
@ -282,6 +237,96 @@
</LinearLayout> </LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
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="2"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/loop_tbrrequest_time_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/loop_tbrrequest_time"
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>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
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="2"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/loop_tbrexecution_time_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/loop_tbrexecution_time"
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>
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"
@ -327,6 +372,96 @@
</LinearLayout> </LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
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="2"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/loop_smbrequest_time_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/loop_smbrequest_time"
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>
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
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="2"
android:gravity="end"
android:paddingRight="5dp"
android:text="@string/loop_smbexecution_time_label"
android:textSize="14sp" />
<TextView
android:layout_width="5dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:gravity="center_horizontal"
android:paddingEnd="2dp"
android:paddingStart="2dp"
android:text=":"
android:textSize="14sp" />
<TextView
android:id="@+id/loop_smbexecution_time"
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>
<View <View
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="2dip" android:layout_height="2dip"

View file

@ -1693,5 +1693,9 @@
<string name="phonechecker">\"PhoneChecker\"</string> <string name="phonechecker">\"PhoneChecker\"</string>
<string name="chartmenu">Chart menu</string> <string name="chartmenu">Chart menu</string>
<string name="sensitivity_short">AS</string> <string name="sensitivity_short">AS</string>
<string name="loop_smbrequest_time_label">SMB request time</string>
<string name="loop_smbexecution_time_label">SMB execution time</string>
<string name="loop_tbrrequest_time_label">Temp basal request time</string>
<string name="loop_tbrexecution_time_label">Temp basal execution time</string>
</resources> </resources>