commit
7d29c3a433
33 changed files with 849 additions and 271 deletions
|
@ -1,4 +1,19 @@
|
|||
buildscript {
|
||||
repositories {
|
||||
maven { url 'https://maven.fabric.io/public' }
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'io.fabric.tools:gradle:1.+'
|
||||
}
|
||||
}
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'io.fabric'
|
||||
|
||||
repositories {
|
||||
maven { url 'https://maven.fabric.io/public' }
|
||||
}
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion 23
|
||||
|
@ -33,4 +48,7 @@ dependencies {
|
|||
compile 'org.slf4j:slf4j-api:1.7.12'
|
||||
compile 'com.jjoe64:graphview:4.0.1'
|
||||
compile 'com.eclipsesource.j2v8:j2v8:3.1.6@aar'
|
||||
compile('com.crashlytics.sdk.android:crashlytics:2.5.7@aar') {
|
||||
transitive = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,9 @@
|
|||
android:exported="false" />
|
||||
|
||||
<activity android:name=".PreferencesActivity"></activity>
|
||||
<meta-data
|
||||
android:name="io.fabric.ApiKey"
|
||||
android:value="59d462666c664c57b29e1d79ea123e01f8057cfa" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -21,6 +21,7 @@ public class Config {
|
|||
public static final boolean logConfigBuilder = true;
|
||||
public static final boolean logConstraintsChanges = true;
|
||||
public static final boolean logTempBasalsCut = true;
|
||||
public static final boolean logNSUpload = true;
|
||||
|
||||
// Developing mode only - never turn on
|
||||
// TODO: remove fakeGlucoseData
|
||||
|
|
|
@ -7,8 +7,11 @@ public class Constants {
|
|||
public static final String MGDL = "mg/dl"; // This is Nightscout representation
|
||||
public static final String MMOL = "mmol";
|
||||
|
||||
public static final double MMOLL_TO_MGDL = 18.0182;
|
||||
public static final double MMOLL_TO_MGDL = 18; // 18.0182;
|
||||
public static final double MGDL_TO_MMOLL = 1 / MMOLL_TO_MGDL;
|
||||
|
||||
public static final double basalAbsoluteOnlyForCheckLimit = 10101010d;
|
||||
public static final Integer basalPercentOnlyForCheckLimit = 10101010;
|
||||
|
||||
public static final int hoursToKeepInDatabase = 24;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
||||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.ThreadEnforcer;
|
||||
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -18,6 +21,7 @@ public class MainApp extends Application {
|
|||
|
||||
private static Bus sBus;
|
||||
private static MainApp sInstance;
|
||||
public static Resources resources;
|
||||
|
||||
private static DatabaseHelper databaseHelper = null;
|
||||
private static ConfigBuilderFragment configBuilder = null;
|
||||
|
@ -25,9 +29,11 @@ public class MainApp extends Application {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Fabric.with(this, new Crashlytics());
|
||||
|
||||
sBus = new Bus(ThreadEnforcer.ANY);
|
||||
sInstance = this;
|
||||
resources = getResources();
|
||||
}
|
||||
|
||||
public static Bus bus() {
|
||||
|
|
|
@ -120,10 +120,10 @@ public class DataService extends IntentService {
|
|||
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
||||
bgReading.slope = bundle.getDouble(Intents.EXTRA_BG_SLOPE);
|
||||
bgReading.battery_level = bundle.getInt(Intents.EXTRA_SENSOR_BATTERY);
|
||||
bgReading.timestamp = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
||||
bgReading.timeIndex = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
||||
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
||||
|
||||
if (bgReading.timestamp < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||
if (Config.logIncommingBG)
|
||||
log.debug("Ignoring old XDRIPREC BG " + bgReading.toString());
|
||||
return;
|
||||
|
@ -320,7 +320,7 @@ public class DataService extends IntentService {
|
|||
JSONObject sgvJson = new JSONObject(sgvstring);
|
||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||
BgReading bgReading = new BgReading(nsSgv);
|
||||
if (bgReading.timestamp < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Ignoring old BG: " + bgReading.toString());
|
||||
return;
|
||||
|
@ -337,7 +337,7 @@ public class DataService extends IntentService {
|
|||
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||
BgReading bgReading = new BgReading(nsSgv);
|
||||
if (bgReading.timestamp < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||
if (Config.logIncommingData)
|
||||
log.debug("Ignoring old BG: " + bgReading.toString());
|
||||
} else {
|
||||
|
|
|
@ -3,7 +3,14 @@ package info.nightscout.androidaps.data;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class Result extends Object implements Parcelable{
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.Round;
|
||||
|
||||
public class PumpEnactResult extends Object implements Parcelable {
|
||||
public boolean success = false; // request was processed successfully (but possible no change was needed)
|
||||
public boolean enacted = false; // request was processed successfully and change has been made
|
||||
public String comment = "";
|
||||
|
@ -55,17 +62,17 @@ public class Result extends Object implements Parcelable{
|
|||
dest.writeInt(percent);
|
||||
}
|
||||
|
||||
public final Parcelable.Creator<Result> CREATOR = new Parcelable.Creator<Result>() {
|
||||
public Result createFromParcel(Parcel in) {
|
||||
return new Result(in);
|
||||
public final Parcelable.Creator<PumpEnactResult> CREATOR = new Parcelable.Creator<PumpEnactResult>() {
|
||||
public PumpEnactResult createFromParcel(Parcel in) {
|
||||
return new PumpEnactResult(in);
|
||||
}
|
||||
|
||||
public Result[] newArray(int size) {
|
||||
return new Result[size];
|
||||
public PumpEnactResult[] newArray(int size) {
|
||||
return new PumpEnactResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
protected Result(Parcel in) {
|
||||
protected PumpEnactResult(Parcel in) {
|
||||
success = in.readInt() == 1 ? true : false;
|
||||
enacted = in.readInt() == 1 ? true : false;
|
||||
isPercent = in.readInt() == 1 ? true : false;
|
||||
|
@ -76,6 +83,27 @@ public class Result extends Object implements Parcelable{
|
|||
|
||||
}
|
||||
|
||||
public Result() {}
|
||||
public PumpEnactResult() {
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject result = new JSONObject();
|
||||
try {
|
||||
if (isTempCancel) {
|
||||
result.put("rate", 0);
|
||||
result.put("duration", 0);
|
||||
} else if (isPercent) {
|
||||
// Nightscout is expecting absolute value
|
||||
Double abs = Round.roundTo(MainApp.getConfigBuilder().getActiveProfile().getProfile().getBasal(NSProfile.secondsFromMidnight()) * percent / 100, 0.01);
|
||||
result.put("rate", abs);
|
||||
result.put("duration", duration);
|
||||
} else {
|
||||
result.put("rate", absolute);
|
||||
result.put("duration", duration);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -22,19 +22,16 @@ public class BgReading implements DataPointInterface {
|
|||
public static final DecimalFormat mgdlFormat = new DecimalFormat("0");
|
||||
|
||||
public long getTimeIndex() {
|
||||
return (long) Math.ceil(timestamp / 60000d);
|
||||
return timeIndex;
|
||||
}
|
||||
|
||||
public void setTimeIndex(long timeIndex) {
|
||||
this.timestamp = timeIndex;
|
||||
this.timeIndex = timeIndex;
|
||||
}
|
||||
|
||||
@DatabaseField(id = true, useGetSet = true)
|
||||
public long timeIndex;
|
||||
|
||||
@DatabaseField
|
||||
public long timestamp;
|
||||
|
||||
@DatabaseField
|
||||
public double value;
|
||||
|
||||
|
@ -52,7 +49,7 @@ public class BgReading implements DataPointInterface {
|
|||
public BgReading() {}
|
||||
|
||||
public BgReading(NSSgv sgv) {
|
||||
timestamp = sgv.getMills();
|
||||
timeIndex = sgv.getMills();
|
||||
value = sgv.getMgdl();
|
||||
raw = sgv.getFiltered();
|
||||
}
|
||||
|
@ -73,8 +70,7 @@ public class BgReading implements DataPointInterface {
|
|||
public String toString() {
|
||||
return "BgReading{" +
|
||||
"timeIndex=" + timeIndex +
|
||||
", timestamp=" + timestamp +
|
||||
", date=" + new Date(timestamp) +
|
||||
", date=" + new Date(timeIndex) +
|
||||
", value=" + value +
|
||||
", slope=" + slope +
|
||||
", raw=" + raw +
|
||||
|
@ -84,7 +80,7 @@ public class BgReading implements DataPointInterface {
|
|||
|
||||
@Override
|
||||
public double getX() {
|
||||
return timestamp;
|
||||
return timeIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
public static final String DATABASE_NAME = "AndroidAPSDb";
|
||||
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
private static final int DATABASE_VERSION = 2;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
|
@ -83,15 +83,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void cleanUpDatabases() {
|
||||
// TODO: call it somewhere
|
||||
log.debug("Before BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings"));
|
||||
getWritableDatabase().delete("BgReadings", "timeIndex" + " < '" + Math.ceil((new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) / 60000d) + "'", null);
|
||||
getWritableDatabase().delete("BgReadings", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings"));
|
||||
|
||||
log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals"));
|
||||
getWritableDatabase().delete("TempBasals", "timeIndex" + " < '" + Math.ceil((new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) / 60000d) + "'", null);
|
||||
getWritableDatabase().delete("TempBasals", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals"));
|
||||
|
||||
log.debug("Before Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments"));
|
||||
getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + Math.ceil((new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) / 60000d) + "'", null);
|
||||
getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||
log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments"));
|
||||
}
|
||||
|
||||
|
@ -146,14 +146,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
|
||||
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
||||
queryBuilder.orderBy("timeIndex", false);
|
||||
queryBuilder.limit(1l);
|
||||
queryBuilder.limit(1L);
|
||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||
bgList = daoBgReadings.query(preparedQuery);
|
||||
|
||||
} catch (SQLException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
}
|
||||
if (bgList.size() > 0)
|
||||
if (bgList != null && bgList.size() > 0)
|
||||
return bgList.get(0);
|
||||
else
|
||||
return null;
|
||||
|
@ -170,7 +170,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
if (lastBg == null)
|
||||
return null;
|
||||
|
||||
if (lastBg.timestamp > new Date().getTime() - 9 * 60 * 1000)
|
||||
if (lastBg.timeIndex > new Date().getTime() - 9 * 60 * 1000)
|
||||
return lastBg;
|
||||
|
||||
return null;
|
||||
|
@ -271,9 +271,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
int sizeRecords = bgReadings.size();
|
||||
|
||||
if (sizeRecords < 4 || bgReadings.get(sizeRecords - 4).timestamp < new Date().getTime() - 7 * 60 * 1000l) {
|
||||
if (sizeRecords < 4 || bgReadings.get(sizeRecords - 4).timeIndex < new Date().getTime() - 7 * 60 * 1000L) {
|
||||
if (Config.fakeGlucoseData) {
|
||||
return new GlucoseStatus(Math.random() * 400, (Math. random() - 0.5)* 18, (Math. random() - 0.5)* 18);
|
||||
return new GlucoseStatus(Math.random() * 400 + 40, (Math. random() - 0.5)* 18, (Math. random() - 0.5)* 18);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class TempBasal {
|
|||
private static Logger log = LoggerFactory.getLogger(TempBasal.class);
|
||||
|
||||
public long getTimeIndex() {
|
||||
return (long) Math.ceil(timeStart.getTime() / 60000d);
|
||||
return timeStart.getTime();
|
||||
}
|
||||
|
||||
public void setTimeIndex(long timeIndex) {
|
||||
|
@ -34,7 +34,6 @@ public class TempBasal {
|
|||
@DatabaseField(id = true, useGetSet = true)
|
||||
public long timeIndex;
|
||||
|
||||
|
||||
@DatabaseField
|
||||
public Date timeStart;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
|
@ -27,7 +28,7 @@ public class Treatment {
|
|||
private static Logger log = LoggerFactory.getLogger(Treatment.class);
|
||||
|
||||
public long getTimeIndex() {
|
||||
return (long) Math.ceil(created_at.getTime() / 60000d);
|
||||
return created_at.getTime();
|
||||
}
|
||||
|
||||
public void setTimeIndex(long timeIndex) {
|
||||
|
@ -119,7 +120,8 @@ public class Treatment {
|
|||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBADD No receivers");
|
||||
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
}
|
||||
|
||||
public void updateToNSClient() {
|
||||
|
@ -146,6 +148,7 @@ public class Treatment {
|
|||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBUPDATE No receivers");
|
||||
} else log.debug("DBUPDATE dbUpdate " + q.size() + " receivers " + _id + " " + data.toString());
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBUPDATE dbUpdate " + q.size() + " receivers " + _id + " " + data.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ package info.nightscout.androidaps.interfaces;
|
|||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.plugins.APSResult;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
|
@ -25,15 +25,17 @@ public interface PumpInterface {
|
|||
double getTempBasalAbsoluteRate();
|
||||
double getTempBasalRemainingMinutes();
|
||||
TempBasal getTempBasal();
|
||||
TempBasal getExtendedBolus();
|
||||
|
||||
Result deliverTreatment(Double insulin, Integer carbs);
|
||||
Result setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
|
||||
Result setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
||||
Result setExtendedBolus(Double insulin, Integer durationInMinutes);
|
||||
Result cancelTempBasal();
|
||||
Result cancelExtendedBolus();
|
||||
Result applyAPSRequest(APSResult request);
|
||||
PumpEnactResult deliverTreatment(Double insulin, Integer carbs);
|
||||
PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes);
|
||||
PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes);
|
||||
PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes);
|
||||
PumpEnactResult cancelTempBasal();
|
||||
PumpEnactResult cancelExtendedBolus();
|
||||
PumpEnactResult applyAPSRequest(APSResult request);
|
||||
|
||||
// Status to be passed to NS
|
||||
JSONObject getJSONStatus();
|
||||
String deviceID();
|
||||
}
|
||||
|
|
|
@ -13,4 +13,5 @@ public interface TempBasalsInterface {
|
|||
IobTotal getLastCalculation();
|
||||
|
||||
TempBasal getTempBasal (Date time);
|
||||
TempBasal getExtendedBolus (Date time);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,9 @@ import android.content.Context;
|
|||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
|
@ -75,4 +78,17 @@ public class APSResult implements Parcelable {
|
|||
return newResult;
|
||||
}
|
||||
|
||||
public JSONObject json() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
if (changeRequested) {
|
||||
json.put("rate", rate);
|
||||
json.put("duration", duration);
|
||||
json.put("reason", reason);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -33,7 +32,7 @@ import info.nightscout.androidaps.MainActivity;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||
|
@ -47,6 +46,9 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
|||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.plugins.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResult;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
|
@ -81,6 +83,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
ProfileInterface activeProfile;
|
||||
TreatmentsInterface activeTreatments;
|
||||
TempBasalsInterface activeTempBasals;
|
||||
LoopFragment activeLoop;
|
||||
|
||||
ArrayList<PluginBase> pluginList;
|
||||
|
||||
|
@ -252,11 +255,16 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result deliverTreatment(Double insulin, Integer carbs) {
|
||||
public TempBasal getExtendedBolus() {
|
||||
return activePump.getExtendedBolus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
|
||||
insulin = applyBolusConstraints(insulin);
|
||||
carbs = applyCarbsConstraints(carbs);
|
||||
|
||||
Result result = activePump.deliverTreatment(insulin, carbs);
|
||||
PumpEnactResult result = activePump.deliverTreatment(insulin, carbs);
|
||||
|
||||
if (result.success) {
|
||||
Treatment t = new Treatment();
|
||||
|
@ -283,9 +291,9 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
Double rateAfterConstraints = applyBasalConstraints(absoluteRate);
|
||||
Result result = activePump.setTempBasalAbsolute(rateAfterConstraints, durationInMinutes);
|
||||
PumpEnactResult result = activePump.setTempBasalAbsolute(rateAfterConstraints, durationInMinutes);
|
||||
if (result.enacted) {
|
||||
uploadTempBasalStartAbsolute(result.absolute, result.duration);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
|
@ -301,9 +309,9 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
* @return result
|
||||
*/
|
||||
@Override
|
||||
public Result setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
Integer percentAfterConstraints = applyBasalConstraints(percent);
|
||||
Result result = activePump.setTempBasalPercent(percentAfterConstraints, durationInMinutes);
|
||||
PumpEnactResult result = activePump.setTempBasalPercent(percentAfterConstraints, durationInMinutes);
|
||||
if (result.enacted) {
|
||||
uploadTempBasalStartPercent(result.percent, result.duration);
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
|
@ -312,9 +320,9 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
Double rateAfterConstraints = applyBasalConstraints(insulin);
|
||||
Result result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
|
||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
Double rateAfterConstraints = applyBolusConstraints(insulin);
|
||||
PumpEnactResult result = activePump.setExtendedBolus(rateAfterConstraints, durationInMinutes);
|
||||
if (result.enacted) {
|
||||
uploadExtendedBolus(result.bolusDelivered, result.duration);
|
||||
MainApp.bus().post(new EventTreatmentChange());
|
||||
|
@ -323,8 +331,8 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result cancelTempBasal() {
|
||||
Result result = activePump.cancelTempBasal();
|
||||
public PumpEnactResult cancelTempBasal() {
|
||||
PumpEnactResult result = activePump.cancelTempBasal();
|
||||
if (result.enacted) {
|
||||
uploadTempBasalEnd();
|
||||
MainApp.bus().post(new EventTempBasalChange());
|
||||
|
@ -333,7 +341,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result cancelExtendedBolus() {
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
return activePump.cancelExtendedBolus();
|
||||
}
|
||||
|
||||
|
@ -344,10 +352,10 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Result applyAPSRequest(APSResult request) {
|
||||
public PumpEnactResult applyAPSRequest(APSResult request) {
|
||||
Double rateAfterConstraints = applyBasalConstraints(request.rate);
|
||||
request.rate = rateAfterConstraints;
|
||||
Result result = null;
|
||||
PumpEnactResult result = null;
|
||||
|
||||
if (request.rate == getBaseBasalRate()) {
|
||||
if (isTempBasalInProgress()) {
|
||||
|
@ -357,7 +365,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
MainApp.bus().post(new EventTempBasalChange());
|
||||
}
|
||||
} else {
|
||||
result = new Result();
|
||||
result = new PumpEnactResult();
|
||||
result.absolute = request.rate;
|
||||
result.duration = 0;
|
||||
result.enacted = false;
|
||||
|
@ -365,7 +373,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
result.success = true;
|
||||
}
|
||||
} else if (isTempBasalInProgress() && request.rate == getTempBasalAbsoluteRate()) {
|
||||
result = new Result();
|
||||
result = new PumpEnactResult();
|
||||
result.absolute = request.rate;
|
||||
result.duration = activePump.getTempBasal().getPlannedRemainingMinutes();
|
||||
result.enacted = false;
|
||||
|
@ -390,6 +398,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
return activePump.getJSONStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deviceID() {
|
||||
return activePump.deviceID();
|
||||
}
|
||||
|
||||
/*
|
||||
* ConfigBuilderFragment code
|
||||
*/
|
||||
|
@ -488,12 +501,10 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BgSourceInterface getActiveBgSource() {
|
||||
return activeBgSource;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PumpInterface getActivePump() {
|
||||
return this;
|
||||
}
|
||||
|
@ -503,16 +514,18 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
return activeProfile;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TreatmentsInterface getActiveTreatments() {
|
||||
return activeTreatments;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TempBasalsInterface getActiveTempBasals() {
|
||||
return activeTempBasals;
|
||||
}
|
||||
|
||||
public LoopFragment getActiveLoop() {
|
||||
return activeLoop;
|
||||
}
|
||||
|
||||
void onEnabledCategoryChanged(PluginBase changedPlugin) {
|
||||
int category = changedPlugin.getType();
|
||||
ArrayList<PluginBase> pluginsInCategory = MainActivity.getSpecificPluginsList(category);
|
||||
|
@ -588,11 +601,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
}
|
||||
break;
|
||||
case PluginBase.LOOP:
|
||||
PluginBase loop = getTheOneEnabledInArray(pluginsInCategory);
|
||||
activeLoop = (LoopFragment) getTheOneEnabledInArray(pluginsInCategory);
|
||||
if (Config.logConfigBuilder)
|
||||
log.debug("Selected loop interface: " + loop.getName());
|
||||
log.debug("Selected loop interface: " + activeLoop.getName());
|
||||
for (PluginBase p : pluginsInCategory) {
|
||||
if (!p.getName().equals(loop.getName())) {
|
||||
if (!p.getName().equals(activeLoop.getName())) {
|
||||
p.setFragmentVisible(false);
|
||||
}
|
||||
}
|
||||
|
@ -800,7 +813,8 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBADD No receivers");
|
||||
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
@ -825,7 +839,8 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBADD No receivers");
|
||||
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
@ -848,7 +863,8 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBADD No receivers");
|
||||
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
@ -876,9 +892,49 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
|
|||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBADD No receivers");
|
||||
} else log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + data.toString());
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadDeviceStatus() {
|
||||
DeviceStatus deviceStatus = new DeviceStatus();
|
||||
try {
|
||||
LoopFragment.LastRun lastRun = LoopFragment.lastRun;
|
||||
if (lastRun == null) return;
|
||||
if (lastRun.lastAPSRun.getTime() < new Date().getTime() - 60 * 1000L)
|
||||
return; // do not send if result is older than 1 min
|
||||
|
||||
String openapsmaPluginName = MainApp.resources.getString(R.string.openapsma);
|
||||
if (lastRun.source != null && lastRun.source.equals(openapsmaPluginName)) {
|
||||
DetermineBasalResult result = (DetermineBasalResult) lastRun.request;
|
||||
result.json.put("timestamp", DateUtil.toISOString(lastRun.lastAPSRun));
|
||||
deviceStatus.suggested = result.json;
|
||||
deviceStatus.iob = result.iob.json();
|
||||
deviceStatus.iob.put("time", DateUtil.toISOString(lastRun.lastAPSRun));
|
||||
}
|
||||
|
||||
if (lastRun.setByPump != null && lastRun.setByPump.enacted) { // enacted
|
||||
deviceStatus.enacted = lastRun.request.json();
|
||||
deviceStatus.enacted.put("rate", lastRun.setByPump.json().get("rate"));
|
||||
deviceStatus.enacted.put("duration", lastRun.setByPump.json().get("duration"));
|
||||
deviceStatus.enacted.put("recieved", true);
|
||||
JSONObject requested = new JSONObject();
|
||||
requested.put("duration", lastRun.request.duration);
|
||||
requested.put("rate", lastRun.request.rate);
|
||||
requested.put("temp", "absolute");
|
||||
deviceStatus.enacted.put("requested", requested);
|
||||
}
|
||||
|
||||
deviceStatus.device = "openaps://" + getActivePump().deviceID();
|
||||
deviceStatus.pump = getActivePump().getJSONStatus();
|
||||
|
||||
deviceStatus.created_at = DateUtil.toISOString(new Date());
|
||||
|
||||
deviceStatus.sendToNSClient();
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,426 @@
|
|||
package info.nightscout.androidaps.plugins.Loop;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.Bundle;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.Services.Intents;
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "576cfd15217b0bed77d63641",
|
||||
"device": "openaps://indy2",
|
||||
"pump": {
|
||||
"battery": {
|
||||
"status": "normal",
|
||||
"voltage": 1.56
|
||||
},
|
||||
"status": {
|
||||
"status": "normal",
|
||||
"timestamp": "2016-06-24T09:26:38.000Z",
|
||||
"bolusing": false,
|
||||
"suspended": false
|
||||
},
|
||||
"reservoir": 31.25,
|
||||
"clock": "2016-06-24T02:26:16-07:00"
|
||||
},
|
||||
"openaps": {
|
||||
"suggested": {
|
||||
"bg": 173,
|
||||
"temp": "absolute",
|
||||
"snoozeBG": 194,
|
||||
"timestamp": "2016-06-24T09:27:40.000Z",
|
||||
"predBGs": {
|
||||
"IOB": [173, 178, 183, 187, 191, 194, 196, 197, 198, 197, 197, 195, 192, 190, 187, 184, 181, 178, 175, 172, 169, 167, 164, 162, 160, 158, 156, 154, 152, 151, 149, 148, 147, 146, 146, 145]
|
||||
},
|
||||
"reason": "COB: 0, Dev: 46, BGI: -1.92, ISF: 80, Target: 115; Eventual BG 194>=115, adj. req. rate:2.7 to maxSafeBasal:2.3, temp 2.25 >~ req 2.3U/hr",
|
||||
"COB": 0,
|
||||
"eventualBG": 194,
|
||||
"tick": "+6",
|
||||
"IOB": 0.309
|
||||
},
|
||||
"iob": [{
|
||||
"netbasalinsulin": -0.3,
|
||||
"activity": 0.0048,
|
||||
"basaliob": 0.078,
|
||||
"time": "2016-06-24T09:26:16.000Z",
|
||||
"hightempinsulin": 0.25,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.309
|
||||
}, {
|
||||
"netbasalinsulin": -0.15,
|
||||
"activity": 0.0041,
|
||||
"basaliob": 0.238,
|
||||
"time": "2016-06-24T09:31:16.000Z",
|
||||
"hightempinsulin": 0.4,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.438
|
||||
}, {
|
||||
"netbasalinsulin": 0,
|
||||
"activity": 0.0036,
|
||||
"basaliob": 0.345,
|
||||
"time": "2016-06-24T09:36:16.000Z",
|
||||
"hightempinsulin": 0.5,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.52
|
||||
}, {
|
||||
"netbasalinsulin": 0.2,
|
||||
"activity": 0.0036,
|
||||
"basaliob": 0.5,
|
||||
"time": "2016-06-24T09:41:16.000Z",
|
||||
"hightempinsulin": 0.65,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.653
|
||||
}, {
|
||||
"netbasalinsulin": 0.35,
|
||||
"activity": 0.0038,
|
||||
"basaliob": 0.602,
|
||||
"time": "2016-06-24T09:46:16.000Z",
|
||||
"hightempinsulin": 0.75,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.734
|
||||
}, {
|
||||
"netbasalinsulin": 0.45,
|
||||
"activity": 0.0042,
|
||||
"basaliob": 0.651,
|
||||
"time": "2016-06-24T09:51:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.763
|
||||
}, {
|
||||
"netbasalinsulin": 0.45,
|
||||
"activity": 0.0045,
|
||||
"basaliob": 0.647,
|
||||
"time": "2016-06-24T09:56:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.74
|
||||
}, {
|
||||
"netbasalinsulin": 0.5,
|
||||
"activity": 0.0048,
|
||||
"basaliob": 0.639,
|
||||
"time": "2016-06-24T10:01:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.716
|
||||
}, {
|
||||
"netbasalinsulin": 0.5,
|
||||
"activity": 0.0052,
|
||||
"basaliob": 0.628,
|
||||
"time": "2016-06-24T10:06:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.691
|
||||
}, {
|
||||
"netbasalinsulin": 0.5,
|
||||
"activity": 0.0055,
|
||||
"basaliob": 0.614,
|
||||
"time": "2016-06-24T10:11:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.663
|
||||
}, {
|
||||
"netbasalinsulin": 0.5,
|
||||
"activity": 0.0059,
|
||||
"basaliob": 0.596,
|
||||
"time": "2016-06-24T10:16:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.633
|
||||
}, {
|
||||
"netbasalinsulin": 0.55,
|
||||
"activity": 0.0063,
|
||||
"basaliob": 0.575,
|
||||
"time": "2016-06-24T10:21:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.602
|
||||
}, {
|
||||
"netbasalinsulin": 0.55,
|
||||
"activity": 0.0067,
|
||||
"basaliob": 0.549,
|
||||
"time": "2016-06-24T10:26:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.568
|
||||
}, {
|
||||
"netbasalinsulin": 0.55,
|
||||
"activity": 0.0071,
|
||||
"basaliob": 0.521,
|
||||
"time": "2016-06-24T10:31:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.533
|
||||
}, {
|
||||
"netbasalinsulin": 0.6,
|
||||
"activity": 0.0074,
|
||||
"basaliob": 0.489,
|
||||
"time": "2016-06-24T10:36:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.496
|
||||
}, {
|
||||
"netbasalinsulin": 0.6,
|
||||
"activity": 0.0075,
|
||||
"basaliob": 0.456,
|
||||
"time": "2016-06-24T10:41:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.458
|
||||
}, {
|
||||
"netbasalinsulin": 0.6,
|
||||
"activity": 0.0075,
|
||||
"basaliob": 0.42,
|
||||
"time": "2016-06-24T10:46:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.421
|
||||
}, {
|
||||
"netbasalinsulin": 0.6,
|
||||
"activity": 0.0073,
|
||||
"basaliob": 0.384,
|
||||
"time": "2016-06-24T10:51:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.384
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0071,
|
||||
"basaliob": 0.349,
|
||||
"time": "2016-06-24T10:56:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.349
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0069,
|
||||
"basaliob": 0.314,
|
||||
"time": "2016-06-24T11:01:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.314
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0066,
|
||||
"basaliob": 0.281,
|
||||
"time": "2016-06-24T11:06:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.281
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0062,
|
||||
"basaliob": 0.25,
|
||||
"time": "2016-06-24T11:11:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.25
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0059,
|
||||
"basaliob": 0.221,
|
||||
"time": "2016-06-24T11:16:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.221
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0055,
|
||||
"basaliob": 0.193,
|
||||
"time": "2016-06-24T11:21:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.193
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0052,
|
||||
"basaliob": 0.167,
|
||||
"time": "2016-06-24T11:26:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.167
|
||||
}, {
|
||||
"netbasalinsulin": 0.7,
|
||||
"activity": 0.0049,
|
||||
"basaliob": 0.143,
|
||||
"time": "2016-06-24T11:31:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.143
|
||||
}, {
|
||||
"netbasalinsulin": 0.7,
|
||||
"activity": 0.0045,
|
||||
"basaliob": 0.12,
|
||||
"time": "2016-06-24T11:36:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.12
|
||||
}, {
|
||||
"netbasalinsulin": 0.7,
|
||||
"activity": 0.0041,
|
||||
"basaliob": 0.1,
|
||||
"time": "2016-06-24T11:41:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.1
|
||||
}, {
|
||||
"netbasalinsulin": 0.7,
|
||||
"activity": 0.0037,
|
||||
"basaliob": 0.081,
|
||||
"time": "2016-06-24T11:46:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.081
|
||||
}, {
|
||||
"netbasalinsulin": 0.75,
|
||||
"activity": 0.0034,
|
||||
"basaliob": 0.064,
|
||||
"time": "2016-06-24T11:51:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.064
|
||||
}, {
|
||||
"netbasalinsulin": 0.75,
|
||||
"activity": 0.003,
|
||||
"basaliob": 0.049,
|
||||
"time": "2016-06-24T11:56:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.049
|
||||
}, {
|
||||
"netbasalinsulin": 0.8,
|
||||
"activity": 0.0026,
|
||||
"basaliob": 0.036,
|
||||
"time": "2016-06-24T12:01:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.036
|
||||
}, {
|
||||
"netbasalinsulin": 0.8,
|
||||
"activity": 0.0021,
|
||||
"basaliob": 0.026,
|
||||
"time": "2016-06-24T12:06:16.000Z",
|
||||
"hightempinsulin": 0.8,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.026
|
||||
}, {
|
||||
"netbasalinsulin": 0.75,
|
||||
"activity": 0.0017,
|
||||
"basaliob": 0.017,
|
||||
"time": "2016-06-24T12:11:16.000Z",
|
||||
"hightempinsulin": 0.75,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.017
|
||||
}, {
|
||||
"netbasalinsulin": 0.75,
|
||||
"activity": 0.0013,
|
||||
"basaliob": 0.011,
|
||||
"time": "2016-06-24T12:16:16.000Z",
|
||||
"hightempinsulin": 0.75,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.011
|
||||
}, {
|
||||
"netbasalinsulin": 0.65,
|
||||
"activity": 0.0009,
|
||||
"basaliob": 0.006,
|
||||
"time": "2016-06-24T12:21:16.000Z",
|
||||
"hightempinsulin": 0.65,
|
||||
"bolussnooze": 0,
|
||||
"iob": 0.006
|
||||
}],
|
||||
"enacted": {
|
||||
"bg": 161,
|
||||
"temp": "absolute",
|
||||
"snoozeBG": 181,
|
||||
"recieved": true,
|
||||
"predBGs": {
|
||||
"IOB": [161, 164, 166, 168, 170, 172, 174, 175, 176, 177, 177, 176, 175, 175, 174, 173, 173, 172, 172, 171, 171, 171, 171, 170, 170, 170, 170, 170, 169, 169, 169, 169, 169, 168]
|
||||
},
|
||||
"reason": "COB: undefined, Dev: 33, BGI: -2.56, ISF: 80, Target: 115; Eventual BG 181>=115, adj. req. rate:2.4 to maxSafeBasal:2.3, temp 1<2.3U/hr",
|
||||
"rate": 2.25,
|
||||
"eventualBG": 181,
|
||||
"timestamp": "2016-06-24T09:19:06.000Z",
|
||||
"duration": 30,
|
||||
"tick": "+5",
|
||||
"IOB": 0.166
|
||||
}
|
||||
},
|
||||
"mmtune": {
|
||||
"scanDetails": [
|
||||
["916.564", 5, -78],
|
||||
["916.588", 3, -80],
|
||||
["916.612", 4, -68],
|
||||
["916.636", 5, -65],
|
||||
["916.660", 5, -60],
|
||||
["916.684", 5, -67],
|
||||
["916.708", 5, -71]
|
||||
],
|
||||
"setFreq": 916.66,
|
||||
"timestamp": "2016-06-24T09:26:22.000Z",
|
||||
"usedDefault": false
|
||||
},
|
||||
"created_at": "2016-06-24T09:27:49.230Z"
|
||||
}
|
||||
*/
|
||||
|
||||
public class DeviceStatus {
|
||||
private static Logger log = LoggerFactory.getLogger(DeviceStatus.class);
|
||||
public static DeviceStatus deviceStatus;
|
||||
|
||||
public static String device = null;
|
||||
public static JSONObject pump = null;
|
||||
public static JSONObject enacted = null;
|
||||
public static JSONObject suggested = null;
|
||||
public static JSONObject iob = null;
|
||||
public static String created_at = null;
|
||||
|
||||
public static JSONObject lowsuspend = null;
|
||||
|
||||
public static JSONObject mongoRecord () {
|
||||
JSONObject record = new JSONObject();
|
||||
|
||||
try {
|
||||
if (device != null) record.put("device" , device);
|
||||
if (pump != null) record.put("pump" , pump);
|
||||
if (suggested != null) {
|
||||
JSONObject openaps = new JSONObject();
|
||||
if (enacted != null) openaps.put("enacted", enacted);
|
||||
if (suggested != null) openaps.put("suggested", suggested);
|
||||
if (iob != null) openaps.put("iob", iob);
|
||||
record.put("openaps", openaps);
|
||||
}
|
||||
if (lowsuspend != null) record.put("lowsuspend" , lowsuspend);
|
||||
if (created_at != null) record.put("created_at" , created_at);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
public void sendToNSClient() {
|
||||
Context context = MainApp.instance().getApplicationContext();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("action", "dbAdd");
|
||||
bundle.putString("collection", "devicestatus");
|
||||
bundle.putString("data", mongoRecord().toString());
|
||||
Intent intent = new Intent(Intents.ACTION_DATABASE);
|
||||
intent.putExtras(bundle);
|
||||
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
||||
context.sendBroadcast(intent);
|
||||
List<ResolveInfo> q = context.getPackageManager().queryBroadcastReceivers(intent, 0);
|
||||
if (q.size() < 1) {
|
||||
log.error("DBADD No receivers");
|
||||
} else if (Config.logNSUpload)
|
||||
log.debug("DBADD dbAdd " + q.size() + " receivers " + mongoRecord().toString());
|
||||
}
|
||||
}
|
|
@ -23,7 +23,7 @@ import java.util.Date;
|
|||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||
|
@ -45,10 +45,10 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
|
||||
boolean confirmed;
|
||||
|
||||
class LastRun implements Parcelable {
|
||||
public class LastRun implements Parcelable {
|
||||
public APSResult request = null;
|
||||
public APSResult constraintsProcessed = null;
|
||||
public Result setByPump = null;
|
||||
public PumpEnactResult setByPump = null;
|
||||
public String source = null;
|
||||
public Date lastAPSRun = null;
|
||||
public Date lastEnact = null;
|
||||
|
@ -81,7 +81,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
private LastRun(Parcel in) {
|
||||
request = in.readParcelable(APSResult.class.getClassLoader());
|
||||
constraintsProcessed = in.readParcelable(APSResult.class.getClassLoader());
|
||||
setByPump = in.readParcelable(Result.class.getClassLoader());
|
||||
setByPump = in.readParcelable(PumpEnactResult.class.getClassLoader());
|
||||
source = in.readString();
|
||||
lastAPSRun = new Date(in.readLong());
|
||||
lastEnact = new Date(in.readLong());
|
||||
|
@ -91,7 +91,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
}
|
||||
}
|
||||
|
||||
static LastRun lastRun = null;
|
||||
static public LastRun lastRun = null;
|
||||
|
||||
private boolean fragmentEnabled = false;
|
||||
private boolean fragmentVisible = true;
|
||||
|
@ -160,9 +160,9 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
runNowButton = (Button) view.findViewById(R.id.loop_run);
|
||||
runNowButton.setOnClickListener(this);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
lastRun = savedInstanceState.getParcelable("lastrun");
|
||||
}
|
||||
//if (savedInstanceState != null) {
|
||||
// lastRun = savedInstanceState.getParcelable("lastrun");
|
||||
//}
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
|
||||
if (result.changeRequested) {
|
||||
constraintsInterface.applyBasalConstraints(resultAfterConstraints);
|
||||
Result applyResult = pumpInterface.applyAPSRequest(resultAfterConstraints);
|
||||
PumpEnactResult applyResult = pumpInterface.applyAPSRequest(resultAfterConstraints);
|
||||
Date lastEnact = lastRun != null ? lastRun.lastEnact : new Date(0, 0, 0);
|
||||
lastRun = new LastRun();
|
||||
lastRun.request = result;
|
||||
|
@ -281,6 +281,7 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
|
|||
lastRun.lastAPSRun = new Date();
|
||||
}
|
||||
updateGUI();
|
||||
MainApp.getConfigBuilder().uploadDeviceStatus();
|
||||
}
|
||||
|
||||
void updateGUI() {
|
||||
|
|
|
@ -41,7 +41,7 @@ public class DetermineBasalAdapterJS implements Parcelable {
|
|||
private final String PARAM_meal_data = "meal_data";
|
||||
|
||||
private String storedCurrentTemp = null;
|
||||
private String storedIobData = null;
|
||||
public String storedIobData = null;
|
||||
private String storedGlucoseStatus = null;
|
||||
private String storedProfile = null;
|
||||
private String storedMeal_data = null;
|
||||
|
@ -124,7 +124,6 @@ public class DetermineBasalAdapterJS implements Parcelable {
|
|||
mIobData = new V8Object(mV8rt);
|
||||
mIobData.add("iob", 0); //netIob
|
||||
mIobData.add("activity", 0); //netActivity
|
||||
mIobData.add("bolusiob", 0); // backward compatibility with master
|
||||
mIobData.add("bolussnooze", 0); //bolusIob
|
||||
mIobData.add("basaliob", 0);
|
||||
mIobData.add("netbasalinsulin", 0);
|
||||
|
@ -287,7 +286,6 @@ public class DetermineBasalAdapterJS implements Parcelable {
|
|||
|
||||
mIobData.add("iob", iobData.iob); //netIob
|
||||
mIobData.add("activity", iobData.activity); //netActivity
|
||||
mIobData.add("bolusiob", iobData.bolussnooze); // backward compatibility with master
|
||||
mIobData.add("bolussnooze", iobData.bolussnooze); //bolusIob
|
||||
mIobData.add("basaliob", iobData.basaliob);
|
||||
mIobData.add("netbasalinsulin", iobData.netbasalinsulin);
|
||||
|
|
|
@ -16,6 +16,7 @@ public class DetermineBasalResult extends APSResult {
|
|||
public double eventualBG;
|
||||
public double snoozeBG;
|
||||
public String mealAssist;
|
||||
public IobTotal iob;
|
||||
|
||||
public DetermineBasalResult(V8Object result, JSONObject j) {
|
||||
json = j;
|
||||
|
@ -75,11 +76,16 @@ public class DetermineBasalResult extends APSResult {
|
|||
mealAssist = in.readString();
|
||||
}
|
||||
|
||||
public DetermineBasalResult() {}
|
||||
public DetermineBasalResult() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DetermineBasalResult clone() {
|
||||
DetermineBasalResult newResult = new DetermineBasalResult();
|
||||
newResult.reason = new String(reason);
|
||||
newResult.rate = rate;
|
||||
newResult.duration = duration;
|
||||
newResult.changeRequested = changeRequested;
|
||||
newResult.rate = rate;
|
||||
newResult.duration = duration;
|
||||
newResult.changeRequested = changeRequested;
|
||||
|
@ -94,4 +100,16 @@ public class DetermineBasalResult extends APSResult {
|
|||
newResult.mealAssist = new String(mealAssist);
|
||||
return newResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject json() {
|
||||
try {
|
||||
JSONObject ret = new JSONObject(this.json.toString());
|
||||
return ret;
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,21 +65,11 @@ public class IobTotal {
|
|||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("iob", iob);
|
||||
json.put("activity", activity);
|
||||
json.put("bolusIob", bolussnooze);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public JSONObject nsJson() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("iob", bolussnooze);
|
||||
json.put("bolussnooze", bolussnooze);
|
||||
json.put("basaliob", iob);
|
||||
json.put("activity", activity);
|
||||
json.put("timestamp", DateUtil.toISOString(new Date()));
|
||||
json.put("hightempinsulin", hightempinsulin);
|
||||
json.put("netbasalinsulin", netbasalinsulin);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -277,6 +277,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
|
||||
|
||||
DetermineBasalResult determineBasalResult = determineBasalAdapterJS.invoke();
|
||||
determineBasalResult.iob = iobTotal;
|
||||
|
||||
determineBasalAdapterJS.release();
|
||||
|
||||
|
|
|
@ -11,10 +11,9 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
|
@ -74,7 +73,7 @@ public class NewExtendedBolusDialog extends DialogFragment implements View.OnCli
|
|||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes);
|
||||
PumpEnactResult result = pump.setExtendedBolus(finalInsulin, finalDurationInMinutes);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
|
||||
|
|
|
@ -11,10 +11,9 @@ import android.widget.Button;
|
|||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
|
@ -88,7 +87,7 @@ public class NewTempBasalDialog extends DialogFragment implements View.OnClickLi
|
|||
builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result;
|
||||
PumpEnactResult result;
|
||||
if (setAsPercent) {
|
||||
result = pump.setTempBasalPercent(finalBasalPercent, finalDurationInMinutes);
|
||||
} else {
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.view.*;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.animation.Interpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
|
@ -70,7 +66,7 @@ public class NewTreatmentDialog extends DialogFragment implements OnClickListene
|
|||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Editable;
|
||||
|
@ -17,10 +15,9 @@ import android.widget.TextView;
|
|||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
||||
|
@ -140,7 +137,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener {
|
|||
public void onClick(DialogInterface dialog, int id) {
|
||||
if (finalInsulinAfterConstraints > 0 || finalCarbsAfterConstraints > 0) {
|
||||
PumpInterface pump = MainApp.getConfigBuilder().getActivePump();
|
||||
Result result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
PumpEnactResult result = pump.deliverTreatment(finalInsulinAfterConstraints, finalCarbsAfterConstraints);
|
||||
if (!result.success) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
builder.setTitle(getContext().getString(R.string.treatmentdeliveryerror));
|
||||
|
|
|
@ -50,6 +50,7 @@ import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
|
|||
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTreatmentDialog;
|
||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.WizardDialog;
|
||||
import info.nightscout.client.data.NSProfile;
|
||||
import info.nightscout.utils.Round;
|
||||
|
||||
|
||||
public class OverviewFragment extends Fragment implements PluginBase {
|
||||
|
@ -317,7 +318,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
flag &= ~Paint.STRIKE_THRU_TEXT_FLAG;
|
||||
bgView.setPaintFlags(flag);
|
||||
|
||||
Long agoMsec = new Date().getTime() - lastBG.timestamp;
|
||||
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
|
||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||
timeAgoView.setText(agoMin + " " + getString(R.string.minago));
|
||||
|
||||
|
@ -326,17 +327,17 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
// allign to hours
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(new Date().getTime());
|
||||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.add(Calendar.HOUR, 1);
|
||||
|
||||
int hoursToFetch = 6;
|
||||
long toTime = calendar.getTimeInMillis();
|
||||
long toTime = calendar.getTimeInMillis() + 100000; // little bit more to avoid wrong rounding
|
||||
long fromTime = toTime - hoursToFetch * 60 * 60 * 1000l;
|
||||
|
||||
Double lowLine = NSProfile.toUnits(80d, 4d, units); // TODO: make this customisable
|
||||
Double highLine = NSProfile.toUnits(180d, 10d, units);
|
||||
Double maxY = NSProfile.toUnits(400d, 20d, units); // TODO: add some scale support
|
||||
|
||||
BarGraphSeries<DataPoint> basalsSeries = null;
|
||||
LineGraphSeries<DataPoint> seriesLow = null;
|
||||
|
@ -345,6 +346,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
PointsGraphSeries<BgReading> seriesInRage = null;
|
||||
PointsGraphSeries<BgReading> seriesOutOfRange = null;
|
||||
|
||||
// remove old data from graph
|
||||
bgGraph.removeAllSeries();
|
||||
|
||||
// **** TEMP BASALS graph ****
|
||||
|
@ -356,11 +358,11 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
public boolean isTempBasal = false;
|
||||
}
|
||||
|
||||
Double maxAllowedBasal = MainApp.getConfigBuilder().applyBasalConstraints(1000d);
|
||||
Double maxAllowedBasal = MainApp.getConfigBuilder().applyBasalConstraints(Constants.basalAbsoluteOnlyForCheckLimit);
|
||||
|
||||
long now = new Date().getTime();
|
||||
List<BarDataPoint> basalArray = new ArrayList<BarDataPoint>();
|
||||
for (long time = fromTime; time < now; time += 5 * 60 * 1000l) {
|
||||
for (long time = fromTime; time < now; time += 5 * 60 * 1000L) {
|
||||
TempBasal tb = MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date(time));
|
||||
if (tb != null)
|
||||
basalArray.add(new BarDataPoint(time, tb.tempBasalConvertedToAbsolute(), true));
|
||||
|
@ -368,7 +370,6 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
basalArray.add(new BarDataPoint(time, profile.getBasal(NSProfile.secondsFromMidnight(new Date(time))), false));
|
||||
}
|
||||
BarDataPoint[] basal = new BarDataPoint[basalArray.size()];
|
||||
log.debug("Bars: " + basalArray.size());
|
||||
basal = basalArray.toArray(basal);
|
||||
bgGraph.addSeries(basalsSeries = new BarGraphSeries<DataPoint>(basal));
|
||||
basalsSeries.setValueDependentColor(new ValueDependentColor<DataPoint>() {
|
||||
|
@ -384,7 +385,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
bgGraph.getSecondScale().addSeries(basalsSeries);
|
||||
bgGraph.getSecondScale().setMinY(0);
|
||||
bgGraph.getSecondScale().setMaxY(maxAllowedBasal * 4);
|
||||
bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark));
|
||||
bgGraph.getGridLabelRenderer().setVerticalLabelsSecondScaleColor(MainApp.instance().getResources().getColor(R.color.background_material_dark)); // same color as backround = hide
|
||||
|
||||
|
||||
// **** BG graph ****
|
||||
|
@ -396,13 +397,19 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
return;
|
||||
|
||||
Iterator<BgReading> it = bgReadingsArray.iterator();
|
||||
Double maxBgValue = 0d;
|
||||
while (it.hasNext()) {
|
||||
BgReading bg = it.next();
|
||||
if (bg.value > maxBgValue) maxBgValue = bg.value;
|
||||
if (bg.valueToUnits(units) < lowLine || bg.valueToUnits(units) > highLine)
|
||||
outOfRangeArray.add(bg);
|
||||
else
|
||||
inRangeArray.add(bg);
|
||||
}
|
||||
maxBgValue = NSProfile.fromMgdlToUnits(maxBgValue, units);
|
||||
maxBgValue = units.equals(Constants.MGDL) ? Round.roundTo(maxBgValue, 40d) + 80 : Round.roundTo(maxBgValue, 2d) + 4;
|
||||
Integer numOfHorizLines = units.equals(Constants.MGDL) ? (int) (maxBgValue / 40 + 1) : (int) (maxBgValue / 2 + 1);
|
||||
|
||||
BgReading[] inRange = new BgReading[inRangeArray.size()];
|
||||
BgReading[] outOfRange = new BgReading[outOfRangeArray.size()];
|
||||
inRange = inRangeArray.toArray(inRange);
|
||||
|
@ -441,7 +448,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
// **** NOW line ****
|
||||
DataPoint[] nowPoints = new DataPoint[]{
|
||||
new DataPoint(now, 0),
|
||||
new DataPoint(now, maxY)
|
||||
new DataPoint(now, maxBgValue)
|
||||
};
|
||||
bgGraph.addSeries(seriesNow = new LineGraphSeries<DataPoint>(nowPoints));
|
||||
seriesNow.setColor(Color.GREEN);
|
||||
|
@ -464,10 +471,10 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
|||
bgGraph.getGridLabelRenderer().setNumHorizontalLabels(7); // only 7 because of the space
|
||||
|
||||
// set manual y bounds to have nice steps
|
||||
bgGraph.getViewport().setMaxY(maxY);
|
||||
bgGraph.getViewport().setMaxY(maxBgValue);
|
||||
bgGraph.getViewport().setMinY(0);
|
||||
bgGraph.getViewport().setYAxisBoundsManual(true);
|
||||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(11);
|
||||
bgGraph.getGridLabelRenderer().setNumVerticalLabels(numOfHorizLines);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
|
@ -83,6 +83,7 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
|
||||
@Override
|
||||
public Double applyBasalConstraints(Double absoluteRate) {
|
||||
Double origAbsoluteRate = absoluteRate;
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
Double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
|
||||
|
||||
|
@ -95,17 +96,17 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
Double origRate = absoluteRate;
|
||||
if (absoluteRate > maxBasal) {
|
||||
absoluteRate = maxBasal;
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origRate + " by maxBasal preference to " + absoluteRate + "U/h");
|
||||
}
|
||||
if (absoluteRate > maxBasalMult * profile.getBasal(NSProfile.secondsFromMidnight())) {
|
||||
absoluteRate = Math.floor(maxBasalMult * profile.getBasal(NSProfile.secondsFromMidnight()) * 100) / 100;
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origRate + " by maxBasalMult to " + absoluteRate + "U/h");
|
||||
}
|
||||
if (absoluteRate > profile.getMaxDailyBasal() * maxBasalFromDaily) {
|
||||
absoluteRate = profile.getMaxDailyBasal() * maxBasalFromDaily;
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origAbsoluteRate != Constants.basalAbsoluteOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origRate + " by 3 * maxDailyBasal to " + absoluteRate + "U/h");
|
||||
}
|
||||
return absoluteRate;
|
||||
|
@ -113,6 +114,7 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
|
||||
@Override
|
||||
public Integer applyBasalConstraints(Integer percentRate) {
|
||||
Integer origPercentRate = percentRate;
|
||||
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
Double maxBasal = SafeParse.stringToDouble(SP.getString("openapsma_max_basal", "1"));
|
||||
|
||||
|
@ -132,17 +134,17 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
Double origRate = absoluteRate;
|
||||
if (absoluteRate > maxBasal) {
|
||||
absoluteRate = maxBasal;
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origRate + " by maxBasal preference to " + absoluteRate + "U/h");
|
||||
}
|
||||
if (absoluteRate > maxBasalMult * profile.getBasal(NSProfile.secondsFromMidnight())) {
|
||||
absoluteRate = Math.floor(maxBasalMult * profile.getBasal(NSProfile.secondsFromMidnight()) * 100) / 100;
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origRate + " by maxBasalMult to " + absoluteRate + "U/h");
|
||||
}
|
||||
if (absoluteRate > profile.getMaxDailyBasal() * maxBasalFromDaily) {
|
||||
absoluteRate = profile.getMaxDailyBasal() * maxBasalFromDaily;
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit)
|
||||
log.debug("Limiting rate " + origRate + " by 3 * maxDailyBasal to " + absoluteRate + "U/h");
|
||||
}
|
||||
|
||||
|
@ -150,7 +152,7 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
|
|||
if (percentRateAfterConst < 100) Round.ceilTo(absoluteRate, 10d).intValue();
|
||||
else Round.floorTo(absoluteRate, 10d).intValue();
|
||||
|
||||
if (Config.logConstraintsChanges)
|
||||
if (Config.logConstraintsChanges && origPercentRate != Constants.basalPercentOnlyForCheckLimit)
|
||||
log.debug("Recalculated percent rate " + percentRate + "% to " + percentRateAfterConst + "%");
|
||||
return percentRateAfterConst;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ import info.nightscout.androidaps.Config;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.events.EventNewBG;
|
||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
|
||||
|
@ -55,6 +54,7 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
|
|||
private static DecimalFormat formatNumber3decimalplaces = new DecimalFormat("0.000");
|
||||
|
||||
private List<TempBasal> tempBasals;
|
||||
private List<TempBasal> extendedBoluses;
|
||||
|
||||
boolean fragmentEnabled = true;
|
||||
boolean fragmentVisible = true;
|
||||
|
@ -114,49 +114,75 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
|
|||
queryBuilder.orderBy("timeIndex", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("isExtended", false);
|
||||
queryBuilder.limit(30l);
|
||||
queryBuilder.limit(30L);
|
||||
PreparedQuery<TempBasal> preparedQuery = queryBuilder.prepare();
|
||||
tempBasals = dao.query(preparedQuery);
|
||||
|
||||
// Update ended
|
||||
long now = new Date().getTime();
|
||||
for (int position = tempBasals.size() - 1; position >= 0; position--) {
|
||||
TempBasal t = tempBasals.get(position);
|
||||
boolean update = false;
|
||||
if (t.timeEnd == null && t.getPlannedTimeEnd().getTime() < now) {
|
||||
t.timeEnd = new Date(t.getPlannedTimeEnd().getTime());
|
||||
if (Config.logTempBasalsCut)
|
||||
log.debug("Add timeEnd to old record");
|
||||
update = true;
|
||||
}
|
||||
if (position > 0) {
|
||||
Date startofnewer = tempBasals.get(position - 1).timeStart;
|
||||
if (t.timeEnd == null) {
|
||||
t.timeEnd = new Date(Math.min(startofnewer.getTime(), t.getPlannedTimeEnd().getTime()));
|
||||
if (Config.logTempBasalsCut)
|
||||
log.debug("Add timeEnd to old record");
|
||||
update = true;
|
||||
} else if (t.timeEnd.getTime() > startofnewer.getTime()) {
|
||||
t.timeEnd = startofnewer;
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
if (update) {
|
||||
dao.update(t);
|
||||
if (Config.logTempBasalsCut) {
|
||||
log.debug("Fixing unfinished temp end: " + t.log());
|
||||
if (position > 0)
|
||||
log.debug("Previous: " + tempBasals.get(position - 1).log());
|
||||
}
|
||||
}
|
||||
QueryBuilder<TempBasal, Long> queryBuilderExt = dao.queryBuilder();
|
||||
queryBuilderExt.orderBy("timeIndex", false);
|
||||
Where whereExt = queryBuilderExt.where();
|
||||
whereExt.eq("isExtended", true);
|
||||
queryBuilderExt.limit(5L);
|
||||
PreparedQuery<TempBasal> preparedQueryExt = queryBuilderExt.prepare();
|
||||
extendedBoluses = dao.query(preparedQueryExt);
|
||||
|
||||
// Update ended
|
||||
checkForExpiredExtended();
|
||||
checkForExpiredTemps();
|
||||
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
log.debug(e.getMessage(), e);
|
||||
tempBasals = new ArrayList<TempBasal>();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkForExpiredTemps() {
|
||||
checkForExpired(tempBasals);
|
||||
}
|
||||
|
||||
public void checkForExpiredExtended() {
|
||||
checkForExpired(extendedBoluses);
|
||||
}
|
||||
|
||||
private void checkForExpired(List<TempBasal> list) {
|
||||
long now = new Date().getTime();
|
||||
for (int position = list.size() - 1; position >= 0; position--) {
|
||||
TempBasal t = list.get(position);
|
||||
boolean update = false;
|
||||
if (t.timeEnd == null && t.getPlannedTimeEnd().getTime() < now) {
|
||||
t.timeEnd = new Date(t.getPlannedTimeEnd().getTime());
|
||||
if (Config.logTempBasalsCut)
|
||||
log.debug("Add timeEnd to old record");
|
||||
update = true;
|
||||
}
|
||||
if (position > 0) {
|
||||
Date startofnewer = list.get(position - 1).timeStart;
|
||||
if (t.timeEnd == null) {
|
||||
t.timeEnd = new Date(Math.min(startofnewer.getTime(), t.getPlannedTimeEnd().getTime()));
|
||||
if (Config.logTempBasalsCut)
|
||||
log.debug("Add timeEnd to old record");
|
||||
update = true;
|
||||
} else if (t.timeEnd.getTime() > startofnewer.getTime()) {
|
||||
t.timeEnd = startofnewer;
|
||||
update = true;
|
||||
}
|
||||
}
|
||||
if (update) {
|
||||
try {
|
||||
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();
|
||||
dao.update(t);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Config.logTempBasalsCut) {
|
||||
log.debug("Fixing unfinished temp end: " + t.log());
|
||||
if (position > 0)
|
||||
log.debug("Previous: " + list.get(position - 1).log());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Recalculate IOB if value is older than 1 minute
|
||||
*/
|
||||
|
@ -173,6 +199,8 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
|
|||
|
||||
@Override
|
||||
public void updateTotalIOB() {
|
||||
checkForExpired(tempBasals);
|
||||
checkForExpired(extendedBoluses);
|
||||
Date now = new Date();
|
||||
IobTotal total = new IobTotal();
|
||||
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
||||
|
@ -198,7 +226,17 @@ public class TempBasalsFragment extends Fragment implements PluginBase, TempBasa
|
|||
@Nullable
|
||||
@Override
|
||||
public TempBasal getTempBasal(Date time) {
|
||||
for (TempBasal t: tempBasals) {
|
||||
checkForExpired(tempBasals);
|
||||
for (TempBasal t : tempBasals) {
|
||||
if (t.isInProgress(time)) return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TempBasal getExtendedBolus(Date time) {
|
||||
checkForExpired(extendedBoluses);
|
||||
for (TempBasal t : extendedBoluses) {
|
||||
if (t.isInProgress(time)) return t;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -18,15 +18,13 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.MainActivity;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.data.Result;
|
||||
import info.nightscout.androidaps.db.TempBasal;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.APSResult;
|
||||
|
@ -38,8 +36,6 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
|
||||
Double defaultBasalValue = 0.2d;
|
||||
|
||||
//TempBasal tempBasal = null;
|
||||
TempBasal extendedBolus = null;
|
||||
Integer batteryPercent = 50;
|
||||
Integer resevoirInUnits = 50;
|
||||
|
||||
|
@ -124,54 +120,14 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
return view;
|
||||
}
|
||||
|
||||
void checkForExpiredTempsAndExtended() {
|
||||
long now = new Date().getTime();
|
||||
if (isTempBasalInProgress()) {
|
||||
//long plannedTimeEnd = tempBasal.getPlannedTimeEnd().getTime();
|
||||
long plannedTimeEnd = getTempBasal().getPlannedTimeEnd().getTime();
|
||||
if (plannedTimeEnd < now) {
|
||||
//tempBasal.timeEnd = new Date(plannedTimeEnd);
|
||||
getTempBasal().timeEnd = new Date(plannedTimeEnd);
|
||||
try {
|
||||
//MainApp.instance().getDbHelper().getDaoTempBasals().update(tempBasal);
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(getTempBasal());
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (Config.logPumpComm)
|
||||
//log.debug("Canceling expired temp: " + tempBasal);
|
||||
log.debug("Canceling expired temp: " + getTempBasal());
|
||||
//tempBasal = null;
|
||||
MainApp.bus().post(new EventTreatmentChange());
|
||||
}
|
||||
}
|
||||
if (isExtendedBoluslInProgress()) {
|
||||
long plannedTimeEnd = extendedBolus.getPlannedTimeEnd().getTime();
|
||||
if (plannedTimeEnd < now) {
|
||||
extendedBolus.timeEnd = new Date(plannedTimeEnd);
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Canceling expired extended bolus: " + extendedBolus);
|
||||
extendedBolus = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTempBasalInProgress() {
|
||||
//return tempBasal != null;
|
||||
return getTempBasal() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExtendedBoluslInProgress() {
|
||||
return extendedBolus != null;
|
||||
return getExtendedBolus() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -201,16 +157,13 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
public double getTempBasalAbsoluteRate() {
|
||||
if (!isTempBasalInProgress())
|
||||
return 0;
|
||||
//if (tempBasal.isAbsolute) {
|
||||
if (getTempBasal().isAbsolute) {
|
||||
//return tempBasal.absolute;
|
||||
return getTempBasal().absolute;
|
||||
} else {
|
||||
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
|
||||
if (profile == null)
|
||||
return defaultBasalValue;
|
||||
Double baseRate = profile.getBasal(profile.secondsFromMidnight());
|
||||
//Double tempRate = baseRate * (tempBasal.percent / 100d);
|
||||
Double tempRate = baseRate * (getTempBasal().percent / 100d);
|
||||
return baseRate + tempRate;
|
||||
}
|
||||
|
@ -218,21 +171,24 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
|
||||
@Override
|
||||
public TempBasal getTempBasal() {
|
||||
//return tempBasal;
|
||||
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TempBasal getExtendedBolus() {
|
||||
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTempBasalRemainingMinutes() {
|
||||
if (!isTempBasalInProgress())
|
||||
return 0;
|
||||
//return tempBasal.getPlannedRemainingMinutes();
|
||||
return getTempBasal().getPlannedRemainingMinutes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result deliverTreatment(Double insulin, Integer carbs) {
|
||||
Result result = new Result();
|
||||
public PumpEnactResult deliverTreatment(Double insulin, Integer carbs) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.bolusDelivered = insulin;
|
||||
result.carbsDelivered = carbs;
|
||||
|
@ -245,12 +201,10 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
checkForExpiredTempsAndExtended();
|
||||
Result result = cancelTempBasal();
|
||||
public PumpEnactResult setTempBasalAbsolute(Double absoluteRate, Integer durationInMinutes) {
|
||||
PumpEnactResult result = cancelTempBasal();
|
||||
if (!result.success)
|
||||
return result;
|
||||
//tempBasal = new TempBasal();
|
||||
TempBasal tempBasal = new TempBasal();
|
||||
tempBasal.timeStart = new Date();
|
||||
tempBasal.isAbsolute = true;
|
||||
|
@ -258,6 +212,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
tempBasal.duration = durationInMinutes;
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.isTempCancel = false;
|
||||
result.absolute = absoluteRate;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
|
@ -275,15 +230,13 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
checkForExpiredTempsAndExtended();
|
||||
Result result = new Result();
|
||||
public PumpEnactResult setTempBasalPercent(Integer percent, Integer durationInMinutes) {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (isTempBasalInProgress()) {
|
||||
result = cancelTempBasal();
|
||||
if (!result.success)
|
||||
return result;
|
||||
}
|
||||
//tempBasal = new TempBasal();
|
||||
TempBasal tempBasal = new TempBasal();
|
||||
tempBasal.timeStart = new Date();
|
||||
tempBasal.isAbsolute = false;
|
||||
|
@ -293,6 +246,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
result.enacted = true;
|
||||
result.percent = percent;
|
||||
result.isPercent = true;
|
||||
result.isTempCancel = false;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
try {
|
||||
|
@ -309,12 +263,11 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
checkForExpiredTempsAndExtended();
|
||||
Result result = cancelExtendedBolus();
|
||||
public PumpEnactResult setExtendedBolus(Double insulin, Integer durationInMinutes) {
|
||||
PumpEnactResult result = cancelExtendedBolus();
|
||||
if (!result.success)
|
||||
return result;
|
||||
extendedBolus = new TempBasal();
|
||||
TempBasal extendedBolus = new TempBasal();
|
||||
extendedBolus.timeStart = new Date();
|
||||
extendedBolus.isExtended = true;
|
||||
extendedBolus.absolute = insulin * 60d / durationInMinutes;
|
||||
|
@ -323,6 +276,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.bolusDelivered = insulin;
|
||||
result.isTempCancel = false;
|
||||
result.duration = durationInMinutes;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
try {
|
||||
|
@ -340,18 +294,17 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result cancelTempBasal() {
|
||||
checkForExpiredTempsAndExtended();
|
||||
Result result = new Result();
|
||||
public PumpEnactResult cancelTempBasal() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
result.success = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
if (isTempBasalInProgress()) {
|
||||
result.enacted = true;
|
||||
//tempBasal.timeEnd = new Date();
|
||||
getTempBasal().timeEnd = new Date();
|
||||
TempBasal tb = getTempBasal();
|
||||
tb.timeEnd = new Date();
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(getTempBasal());
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(tb);
|
||||
//tempBasal = null;
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Canceling temp basal: " + result);
|
||||
|
@ -367,10 +320,10 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result cancelExtendedBolus() {
|
||||
checkForExpiredTempsAndExtended();
|
||||
Result result = new Result();
|
||||
public PumpEnactResult cancelExtendedBolus() {
|
||||
PumpEnactResult result = new PumpEnactResult();
|
||||
if (isExtendedBoluslInProgress()) {
|
||||
TempBasal extendedBolus = getExtendedBolus();
|
||||
extendedBolus.timeEnd = new Date();
|
||||
try {
|
||||
MainApp.instance().getDbHelper().getDaoTempBasals().update(extendedBolus);
|
||||
|
@ -382,8 +335,8 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
result.success = true;
|
||||
result.enacted = true;
|
||||
result.isTempCancel = true;
|
||||
result.comment = MainApp.instance().getString(R.string.virtualpump_resultok);
|
||||
extendedBolus = null;
|
||||
if (Config.logPumpComm)
|
||||
log.debug("Canceling extended basal: " + result);
|
||||
updateGUI();
|
||||
|
@ -391,7 +344,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result applyAPSRequest(APSResult request) {
|
||||
public PumpEnactResult applyAPSRequest(APSResult request) {
|
||||
// This should be implemented only on ConfigBuilder
|
||||
return null;
|
||||
}
|
||||
|
@ -405,9 +358,6 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
battery.put("percent", batteryPercent);
|
||||
status.put("status", "normal");
|
||||
if (isTempBasalInProgress()) {
|
||||
//status.put("tempbasalpct", tempBasal.percent);
|
||||
//status.put("tempbasalstart", DateUtil.toISOString(tempBasal.timeStart));
|
||||
//status.put("tempbasalremainmin", tempBasal.getPlannedRemainingMinutes());
|
||||
status.put("tempbasalpct", getTempBasal().percent);
|
||||
status.put("tempbasalstart", DateUtil.toISOString(getTempBasal().timeStart));
|
||||
status.put("tempbasalremainmin", getTempBasal().getPlannedRemainingMinutes());
|
||||
|
@ -423,6 +373,11 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
return pump;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String deviceID() {
|
||||
return "VirtualPump";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
|
@ -436,7 +391,6 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
}
|
||||
|
||||
public void updateGUI() {
|
||||
checkForExpiredTempsAndExtended();
|
||||
Activity activity = getActivity();
|
||||
if (activity != null && visibleNow && basaBasalRateView != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
|
@ -451,7 +405,7 @@ public class VirtualPumpFragment extends Fragment implements PluginBase, PumpInt
|
|||
tempBasalView.setText("");
|
||||
}
|
||||
if (isExtendedBoluslInProgress()) {
|
||||
extendedBolusView.setText(extendedBolus.toString());
|
||||
extendedBolusView.setText(getExtendedBolus().toString());
|
||||
} else {
|
||||
extendedBolusView.setText("");
|
||||
}
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_lastrun_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_lastrun"
|
||||
|
@ -45,7 +46,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_lastenact_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_lastenact"
|
||||
|
@ -68,7 +70,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/loop_aps_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_source"
|
||||
|
@ -97,7 +100,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/loop_constraintsprocessed_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_constraintsprocessed"
|
||||
|
@ -119,7 +123,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/loop_setbypump_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loop_setbypump"
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_lastrun_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lowsuspend_lastrun"
|
||||
|
@ -52,13 +53,15 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_inputparameters_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_glucosestatus_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lowsuspend_glucosestatus"
|
||||
|
@ -71,7 +74,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_minbg_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lowsuspend_minbg"
|
||||
|
@ -94,7 +98,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_result_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lowsuspend_result"
|
||||
|
@ -116,7 +121,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_request_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lowsuspend_request"
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_lastrun_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_lastrun"
|
||||
|
@ -60,13 +61,15 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_inputparameters_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_glucosestatus_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_glucosestatus"
|
||||
|
@ -79,7 +82,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_currenttemp_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_currenttemp"
|
||||
|
@ -92,7 +96,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_iobdata_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_iobdata"
|
||||
|
@ -105,7 +110,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_profile_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_profile"
|
||||
|
@ -118,7 +124,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_mealdata_label"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_mealdata"
|
||||
|
@ -140,7 +147,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_result_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_result"
|
||||
|
@ -163,7 +171,8 @@
|
|||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_request_label"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openapsma_request"
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
<com.jjoe64.graphview.GraphView
|
||||
android:id="@+id/overview_bggraph"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dip" />
|
||||
android:layout_height="160dip" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/overview_canceltemplayout"
|
||||
|
|
Loading…
Reference in a new issue