Merge pull request #20 from jotomo/combo-scripter-v2

jan 21 - 2
This commit is contained in:
Simon Pauwels 2018-01-21 22:36:44 +01:00 committed by GitHub
commit ddd1f6be30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 304 additions and 109 deletions

View file

@ -47,7 +47,7 @@ import info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
import info.nightscout.androidaps.plugins.ProfileCircadianPercentage.CircadianPercentageProfileFragment;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfileFragment;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.ProfileSimple.SimpleProfilePlugin;
import info.nightscout.androidaps.plugins.PumpCombo.ComboPlugin;
@ -138,7 +138,7 @@ public class MainApp extends Application {
if (Config.APS) pluginsList.add(OpenAPSAMAPlugin.getPlugin());
pluginsList.add(NSProfilePlugin.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(SimpleProfilePlugin.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(LocalProfileFragment.getPlugin());
if (Config.OTHERPROFILES) pluginsList.add(LocalProfilePlugin.getPlugin());
if (Config.OTHERPROFILES)
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
pluginsList.add(TreatmentsPlugin.getPlugin());

View file

@ -20,9 +20,9 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.ToastUtils;
@ -48,6 +48,9 @@ public class Profile {
private int percentage = 100;
private int timeshift = 0;
private boolean isValid = true;
private boolean isValidated = false;
public Profile(JSONObject json, String units) {
this(json, 100, 0);
if (this.units == null) {
@ -121,6 +124,8 @@ public class Profile {
} catch (JSONException e) {
log.error("Unhandled exception", e);
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.gs(R.string.invalidprofile));
isValid = false;
isValidated = true;
}
}
@ -174,10 +179,6 @@ public class Profile {
}
double value = o.getDouble("value") * multiplier;
sparse.put(tas, value);
if (value == 0) {
Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, MainApp.sResources.getString(R.string.zerovalueinprofile), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
log.error(json.toString());
@ -192,6 +193,71 @@ public class Profile {
return sparse;
}
public synchronized boolean isValid(String from) {
if (!isValid)
return false;
if (!isValidated) {
if (basal_v == null)
basal_v = convertToSparseArray(basal);
validate(basal_v);
if (isf_v == null)
isf_v = convertToSparseArray(isf);
validate(isf_v);
if (ic_v == null)
ic_v = convertToSparseArray(ic);
validate(ic_v);
if (targetLow_v == null)
targetLow_v = convertToSparseArray(targetLow);
validate(targetLow_v);
if (targetHigh_v == null)
targetHigh_v = convertToSparseArray(targetHigh);
validate(targetHigh_v);
isValidated = true;
}
if (isValid) {
// Check for hours alignment
for (int index = 0; index < basal_v.size(); index++) {
long secondsFromMidnight = basal_v.keyAt(index);
if (secondsFromMidnight % 3600 != 0) {
Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, String.format(MainApp.gs(R.string.basalprofilenotaligned), from), Notification.NORMAL);
MainApp.bus().post(new EventNewNotification(notification));
}
}
// Check for minimal basal value
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (pump != null) {
PumpDescription description = pump.getPumpDescription();
for (int i = 0; i < basal_v.size(); i++) {
if (basal_v.valueAt(i) < description.basalMinimumRate) {
basal_v.setValueAt(i, description.basalMinimumRate);
MainApp.bus().post(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, String.format(MainApp.gs(R.string.minimalbasalvaluereplaced), from), Notification.NORMAL)));
}
}
} else {
// if pump not available (at start)
// do not store converted array
basal_v = null;
}
}
return isValid;
}
private void validate(LongSparseArray array) {
if (array.size() == 0) {
isValid = false;
return;
}
for (int index = 0; index < array.size(); index++) {
if (array.valueAt(index).equals(0d)) {
isValid = false;
return;
}
}
}
private Double getValueToTime(JSONArray array, Integer timeAsSeconds) {
Double lastValue = null;
@ -338,35 +404,9 @@ public class Profile {
return getBasal(secondsFromMidnight(time));
}
public Double getBasal(Integer timeAsSeconds) {
public synchronized Double getBasal(Integer timeAsSeconds) {
if (basal_v == null) {
basal_v = convertToSparseArray(basal);
for (int index = 0; index < basal_v.size(); index++) {
long secondsFromMidnight = basal_v.keyAt(index);
if (secondsFromMidnight % 3600 != 0) {
Notification notification = new Notification(Notification.BASAL_PROFILE_NOT_ALIGNED_TO_HOURS, MainApp.sResources.getString(R.string.basalprofilenotaligned), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
}
}
// Check for minimal basal value
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
if (pump != null) {
PumpDescription description = pump.getPumpDescription();
for (int i = 0; i < basal_v.size(); i++) {
if (basal_v.valueAt(i) < description.basalMinimumRate) {
basal_v.setValueAt(i, description.basalMinimumRate);
MainApp.bus().post(new EventNewNotification(new Notification(Notification.MINIMAL_BASAL_VALUE_REPLACED, MainApp.sResources.getString(R.string.minimalbasalvaluereplaced), Notification.NORMAL)));
}
}
return getValueToTime(basal_v, timeAsSeconds);
} else {
// if pump not available (at start)
// do not store converted array
Double value = getValueToTime(basal_v, timeAsSeconds);
basal_v = null;
return value;
}
}
return getValueToTime(basal_v, timeAsSeconds);
}
@ -385,7 +425,7 @@ public class Profile {
public Double value;
}
public BasalValue[] getBasalValues() {
public synchronized BasalValue[] getBasalValues() {
if (basal_v == null)
basal_v = convertToSparseArray(basal);
BasalValue[] ret = new BasalValue[basal_v.size()];

View file

@ -31,6 +31,7 @@ public class ProfileIntervals<T extends Interval> {
public synchronized void add(List<T> list) {
for (T interval : list) {
if (interval.isValid())
rawData.put(interval.start(), interval);
}
merge();

View file

@ -51,6 +51,8 @@ import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.NSUpload;
import info.nightscout.utils.PercentageSplitter;
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
@ -1720,10 +1722,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
if (profile != null) {
profileSwitch.profileJson = profile.getData().toString();
log.debug("Profile switch prefilled with JSON from local store");
// Update data in NS
NSUpload.updateProfileSwitch(profileSwitch);
} else {
Notification notification = new Notification(Notification.NO_LOCALE_PROFILE_FOUND, MainApp.sResources.getString(R.string.nolocaleprofilefound), Notification.URGENT);
MainApp.bus().post(new EventNewNotification(notification));
log.debug("JSON for profile switch doesn't exist. Ignoring ...");
log.debug("JSON for profile switch doesn't exist. Ignoring: " + trJson.toString());
return;
}
}

View file

@ -147,6 +147,11 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
return durationInMinutes == 0;
}
@Override
public boolean isValid() {
return true;
}
// -------- Interval interface end ---------
public String log() {

View file

@ -1,6 +1,7 @@
package info.nightscout.androidaps.db;
import android.graphics.Color;
import android.support.annotation.Nullable;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
@ -12,10 +13,14 @@ import org.slf4j.LoggerFactory;
import java.util.Objects;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -56,12 +61,14 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
private Profile profile = null;
@Nullable
public Profile getProfileObject() {
if (profile == null)
try {
profile = new Profile(new JSONObject(profileJson), percentage, timeshift);
} catch (JSONException e) {
} catch (Exception e) {
log.error("Unhandled exception", e);
log.error("Unhandled exception", profileJson);
}
return profile;
}
@ -171,6 +178,20 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
return durationInMinutes == 0;
}
@Override
public boolean isValid() {
boolean isValid = getProfileObject() != null && getProfileObject().isValid(DateUtil.dateAndTimeString(date));
if (!isValid)
createNotificationInvalidProfile(DateUtil.dateAndTimeString(date));
return isValid;
}
public void createNotificationInvalidProfile(String detail) {
Notification notification = new Notification(Notification.ZERO_VALUE_IN_PROFILE, String.format(MainApp.gs(R.string.zerovalueinprofile), detail), Notification.LOW, 5);
MainApp.bus().post(new EventNewNotification(notification));
}
// -------- Interval interface end ---------
// ----------------- DataPointInterface --------------------

View file

@ -123,6 +123,11 @@ public class TempTarget implements Interval {
return durationInMinutes == 0;
}
@Override
public boolean isValid() {
return true;
}
// -------- Interval interface end ---------
public String lowValueToUnitsToString(String units) {

View file

@ -182,6 +182,11 @@ public class TemporaryBasal implements Interval {
return durationInMinutes == 0;
}
@Override
public boolean isValid() {
return true;
}
// -------- Interval interface end ---------
public IobTotal iobCalc(long time) {

View file

@ -21,4 +21,6 @@ public interface Interval {
boolean isInProgress();
boolean isEndingEvent();
boolean isValid();
}

View file

@ -13,6 +13,7 @@ import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.DetailedBolusInfo;
@ -758,14 +759,17 @@ public class ConfigBuilderPlugin implements PluginBase, ConstraintsInterface, Tr
return "Default";
}
@Nullable
public Profile getProfile() {
return getProfile(System.currentTimeMillis());
}
public String getProfileUnits() {
return getProfile().getUnits();
Profile profile = getProfile();
return profile != null ? profile.getUnits() : Constants.MGDL;
}
@Nullable
public Profile getProfile(long time) {
if (activeTreatments == null)
return null; //app not initialized

View file

@ -79,6 +79,11 @@ public class DBAccessReceiver extends BroadcastReceiver {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id);
UploadQueue.add(dbr);
}
} else if (action.equals("dbUpdate")) {
if (shouldUpload()) {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), _id, data);
UploadQueue.add(dbr);
}
} else {
DbRequest dbr = new DbRequest(action, collection, nsclientid.toString(), data);
// this is not used as mongo _id but only for searching in UploadQueue database

View file

@ -60,7 +60,6 @@ public class Notification {
public static final int MINIMAL_BASAL_VALUE_REPLACED = 29;
public static final int BASAL_PROFILE_NOT_ALIGNED_TO_HOURS = 30;
public static final int ZERO_VALUE_IN_PROFILE = 31;
public static final int NO_LOCALE_PROFILE_FOUND = 32;
public int id;
public Date date;

View file

@ -11,6 +11,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.squareup.otto.Subscribe;
@ -22,6 +23,8 @@ import java.text.DecimalFormat;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
@ -37,12 +40,6 @@ import info.nightscout.utils.TimeListEdit;
public class LocalProfileFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(LocalProfileFragment.class);
private static LocalProfilePlugin localProfilePlugin = new LocalProfilePlugin();
public static LocalProfilePlugin getPlugin() {
return localProfilePlugin;
}
NumberPicker diaView;
RadioButton mgdlView;
RadioButton mmolView;
@ -51,6 +48,7 @@ public class LocalProfileFragment extends SubscriberFragment {
TimeListEdit basalView;
TimeListEdit targetView;
Button profileswitchButton;
TextView invalidProfile;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -59,10 +57,11 @@ public class LocalProfileFragment extends SubscriberFragment {
Runnable save = new Runnable() {
@Override
public void run() {
localProfilePlugin.storeSettings();
LocalProfilePlugin.getPlugin().storeSettings();
if (basalView != null) {
basalView.updateLabel(MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel());
}
updateGUI();
}
};
@ -80,8 +79,9 @@ public class LocalProfileFragment extends SubscriberFragment {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
localProfilePlugin.dia = SafeParse.stringToDouble(diaView.getText().toString());
localProfilePlugin.storeSettings();
LocalProfilePlugin.getPlugin().dia = SafeParse.stringToDouble(diaView.getText().toString());
LocalProfilePlugin.getPlugin().storeSettings();
updateGUI();
}
};
@ -89,40 +89,39 @@ public class LocalProfileFragment extends SubscriberFragment {
View layout = inflater.inflate(R.layout.localprofile_fragment, container, false);
diaView = (NumberPicker) layout.findViewById(R.id.localprofile_dia);
diaView.setParams(localProfilePlugin.dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch);
diaView.setParams(LocalProfilePlugin.getPlugin().dia, 2d, 48d, 0.1d, new DecimalFormat("0.0"), false, textWatch);
mgdlView = (RadioButton) layout.findViewById(R.id.localprofile_mgdl);
mmolView = (RadioButton) layout.findViewById(R.id.localprofile_mmol);
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", getPlugin().targetLow, getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
icView = new TimeListEdit(getContext(), layout, R.id.localprofile_ic, MainApp.sResources.getString(R.string.nsprofileview_ic_label) + ":", LocalProfilePlugin.getPlugin().ic, null, 0.5, 50d, 0.1d, new DecimalFormat("0.0"), save);
isfView = new TimeListEdit(getContext(), layout, R.id.localprofile_isf, MainApp.sResources.getString(R.string.nsprofileview_isf_label) + ":", LocalProfilePlugin.getPlugin().isf, null, 0.5, 500d, 0.1d, new DecimalFormat("0.0"), save);
basalView = new TimeListEdit(getContext(), layout, R.id.localprofile_basal, MainApp.sResources.getString(R.string.nsprofileview_basal_label) + ": " + getSumLabel(), LocalProfilePlugin.getPlugin().basal, null, pumpDescription.basalMinimumRate, 10, 0.01d, new DecimalFormat("0.00"), save);
targetView = new TimeListEdit(getContext(), layout, R.id.localprofile_target, MainApp.sResources.getString(R.string.nsprofileview_target_label) + ":", LocalProfilePlugin.getPlugin().targetLow, LocalProfilePlugin.getPlugin().targetHigh, 3d, 200, 0.1d, new DecimalFormat("0.0"), save);
profileswitchButton = (Button) layout.findViewById(R.id.localprofile_profileswitch);
invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile);
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
layout.findViewById(R.id.localprofile_basal).setVisibility(View.GONE);
}
updateGUI();
mgdlView.setChecked(localProfilePlugin.mgdl);
mmolView.setChecked(localProfilePlugin.mmol);
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
mgdlView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
localProfilePlugin.mgdl = mgdlView.isChecked();
localProfilePlugin.mmol = !localProfilePlugin.mgdl;
mmolView.setChecked(localProfilePlugin.mmol);
localProfilePlugin.storeSettings();
LocalProfilePlugin.getPlugin().mgdl = mgdlView.isChecked();
LocalProfilePlugin.getPlugin().mmol = !LocalProfilePlugin.getPlugin().mgdl;
mmolView.setChecked(LocalProfilePlugin.getPlugin().mmol);
LocalProfilePlugin.getPlugin().storeSettings();
}
});
mmolView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
localProfilePlugin.mmol = mmolView.isChecked();
localProfilePlugin.mgdl = !localProfilePlugin.mmol;
mgdlView.setChecked(localProfilePlugin.mgdl);
localProfilePlugin.storeSettings();
LocalProfilePlugin.getPlugin().mmol = mmolView.isChecked();
LocalProfilePlugin.getPlugin().mgdl = !LocalProfilePlugin.getPlugin().mmol;
mgdlView.setChecked(LocalProfilePlugin.getPlugin().mgdl);
LocalProfilePlugin.getPlugin().storeSettings();
}
});
@ -138,7 +137,6 @@ public class LocalProfileFragment extends SubscriberFragment {
});
updateGUI();
return layout;
} catch (Exception e) {
log.error("Unhandled exception: ", e);
@ -150,7 +148,11 @@ public class LocalProfileFragment extends SubscriberFragment {
@NonNull
public String getSumLabel() {
return "" + DecimalFormatter.to2Decimal(localProfilePlugin.getProfile().getDefaultProfile().baseBasalSum()) + "U";
ProfileStore profile = LocalProfilePlugin.getPlugin().getProfile();
if (profile != null)
return "" + DecimalFormatter.to2Decimal(profile.getDefaultProfile().baseBasalSum()) + "U";
else
return MainApp.gs(R.string.localprofile);
}
@Subscribe
@ -165,11 +167,16 @@ public class LocalProfileFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended()) {
boolean isValid = LocalProfilePlugin.getPlugin().getProfile() != null && LocalProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.localprofile));
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended() || !isValid) {
profileswitchButton.setVisibility(View.GONE);
} else {
profileswitchButton.setVisibility(View.VISIBLE);
}
if (isValid)
invalidProfile.setVisibility(View.GONE);
else
invalidProfile.setVisibility(View.VISIBLE);
}
});
}

View file

@ -13,9 +13,9 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.SP;
@ -26,6 +26,14 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
public static final String LOCAL_PROFILE = "LocalProfile";
private static Logger log = LoggerFactory.getLogger(LocalProfilePlugin.class);
private static LocalProfilePlugin localProfilePlugin;
public static LocalProfilePlugin getPlugin() {
if (localProfilePlugin == null)
localProfilePlugin = new LocalProfilePlugin();
return localProfilePlugin;
}
private boolean fragmentEnabled = false;
private boolean fragmentVisible = false;
@ -128,7 +136,7 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
editor.apply();
createConvertedProfile();
if (Config.logPrefsChange)
log.debug("Storing settings: " + getProfile().getData().toString());
log.debug("Storing settings: " + getRawProfile().getData().toString());
}
public void loadSettings() {
@ -243,6 +251,14 @@ public class LocalProfilePlugin implements PluginBase, ProfileInterface {
@Override
public ProfileStore getProfile() {
if (convertedProfile == null)
createConvertedProfile();
if (!convertedProfile.getDefaultProfile().isValid(MainApp.gs(R.string.localprofile)))
return null;
return convertedProfile;
}
public ProfileStore getRawProfile() {
if (convertedProfile == null)
createConvertedProfile();
return convertedProfile;

View file

@ -84,6 +84,7 @@ public class NSProfileFragment extends SubscriberFragment implements AdapterView
}
ProfileStore profileStore = NSProfilePlugin.getPlugin().getProfile();
if (profileStore != null) {
ArrayList<CharSequence> profileList = profileStore.getProfileList();
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<>(getContext(),
R.layout.spinner_centered, profileList);
@ -93,14 +94,17 @@ public class NSProfileFragment extends SubscriberFragment implements AdapterView
if (profileList.get(p).equals(MainApp.getConfigBuilder().getProfileName()))
profileSpinner.setSelection(p);
}
}
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String name = parent.getItemAtPosition(position).toString();
Profile profile = NSProfilePlugin.getPlugin().getProfile().getSpecificProfile(name);
ProfileStore store = NSProfilePlugin.getPlugin().getProfile();
if (store != null) {
Profile profile = store.getSpecificProfile(name);
if (profile != null) {
units.setText(profile.getUnits());
dia.setText(DecimalFormatter.to2Decimal(profile.getDia()) + " h");
activeProfile.setText(name);
@ -109,6 +113,8 @@ public class NSProfileFragment extends SubscriberFragment implements AdapterView
basal.setText(profile.getBasalList());
target.setText(profile.getTargetList());
}
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {

View file

@ -11,6 +11,7 @@ import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import com.crashlytics.android.Crashlytics;
import com.squareup.otto.Subscribe;
@ -18,6 +19,7 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.plugins.Careportal.CareportalFragment;
@ -39,6 +41,7 @@ public class SimpleProfileFragment extends SubscriberFragment {
EditText targetlowView;
EditText targethighView;
Button profileswitchButton;
TextView invalidProfile;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -54,14 +57,13 @@ public class SimpleProfileFragment extends SubscriberFragment {
targetlowView = (EditText) layout.findViewById(R.id.simpleprofile_targetlow);
targethighView = (EditText) layout.findViewById(R.id.simpleprofile_targethigh);
profileswitchButton = (Button) layout.findViewById(R.id.simpleprofile_profileswitch);
invalidProfile = (TextView) layout.findViewById(R.id.invalidprofile);
if (!ConfigBuilderPlugin.getActivePump().getPumpDescription().isTempBasalCapable) {
layout.findViewById(R.id.simpleprofile_basalrate).setVisibility(View.GONE);
layout.findViewById(R.id.simpleprofile_basalrate_label).setVisibility(View.GONE);
}
updateGUI();
mgdlView.setChecked(SimpleProfilePlugin.getPlugin().mgdl);
mmolView.setChecked(SimpleProfilePlugin.getPlugin().mmol);
diaView.setText(SimpleProfilePlugin.getPlugin().dia.toString());
@ -122,6 +124,7 @@ public class SimpleProfileFragment extends SubscriberFragment {
SimpleProfilePlugin.getPlugin().targetLow = SafeParse.stringToDouble(targetlowView.getText().toString());
SimpleProfilePlugin.getPlugin().targetHigh = SafeParse.stringToDouble(targethighView.getText().toString());
SimpleProfilePlugin.getPlugin().storeSettings();
updateGUI();
}
};
@ -132,8 +135,6 @@ public class SimpleProfileFragment extends SubscriberFragment {
targetlowView.addTextChangedListener(textWatch);
targethighView.addTextChangedListener(textWatch);
updateGUI();
return layout;
} catch (Exception e) {
Crashlytics.logException(e);
@ -154,11 +155,16 @@ public class SimpleProfileFragment extends SubscriberFragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended()) {
boolean isValid = SimpleProfilePlugin.getPlugin().getProfile() != null && SimpleProfilePlugin.getPlugin().getProfile().getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile));
if (!ConfigBuilderPlugin.getActivePump().isInitialized() || ConfigBuilderPlugin.getActivePump().isSuspended() || !isValid) {
profileswitchButton.setVisibility(View.GONE);
} else {
profileswitchButton.setVisibility(View.VISIBLE);
}
if (isValid)
invalidProfile.setVisibility(View.GONE);
else
invalidProfile.setVisibility(View.VISIBLE);
}
});
}

View file

@ -132,6 +132,8 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
editor.apply();
createConvertedProfile();
if (Config.logPrefsChange)
log.debug("Storing settings: " + getRawProfile().getData().toString());
}
private void loadSettings() {
@ -141,11 +143,11 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
mgdl = SP.getBoolean("SimpleProfile" + "mgdl", true);
mmol = SP.getBoolean("SimpleProfile" + "mmol", false);
dia = SP.getDouble("SimpleProfile" + "dia", Constants.defaultDIA);
ic = SP.getDouble("SimpleProfile" + "ic", 20d);
isf = SP.getDouble("SimpleProfile" + "isf", 200d);
basal = SP.getDouble("SimpleProfile" + "basal", 1d);
targetLow = SP.getDouble("SimpleProfile" + "targetlow", 80d);
targetHigh = SP.getDouble("SimpleProfile" + "targethigh", 120d);
ic = SP.getDouble("SimpleProfile" + "ic", 0d);
isf = SP.getDouble("SimpleProfile" + "isf", 0d);
basal = SP.getDouble("SimpleProfile" + "basal", 0d);
targetLow = SP.getDouble("SimpleProfile" + "targetlow", 0d);
targetHigh = SP.getDouble("SimpleProfile" + "targethigh", 0d);
}
/*
@ -210,6 +212,14 @@ public class SimpleProfilePlugin implements PluginBase, ProfileInterface {
@Override
public ProfileStore getProfile() {
if (convertedProfile == null)
createConvertedProfile();
if (!convertedProfile.getDefaultProfile().isValid(MainApp.gs(R.string.simpleprofile)))
return null;
return convertedProfile;
}
public ProfileStore getRawProfile() {
if (convertedProfile == null)
createConvertedProfile();
return convertedProfile;

View file

@ -83,6 +83,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
holder.remove.setTag(profileSwitch);
holder.name.setTag(profileSwitch);
holder.date.setTag(profileSwitch);
holder.invalid.setVisibility(profileSwitch.isValid() ? View.GONE : View.VISIBLE);
}
@ -104,6 +105,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
TextView remove;
TextView ph;
TextView ns;
TextView invalid;
ProfileSwitchViewHolder(View itemView) {
super(itemView);
@ -113,6 +115,7 @@ public class TreatmentsProfileSwitchFragment extends SubscriberFragment implemen
name = (TextView) itemView.findViewById(R.id.profileswitch_name);
ph = (TextView) itemView.findViewById(R.id.pump_sign);
ns = (TextView) itemView.findViewById(R.id.ns_sign);
invalid = (TextView) itemView.findViewById(R.id.invalid_sign);
remove = (TextView) itemView.findViewById(R.id.profileswitch_remove);
remove.setOnClickListener(this);
remove.setPaintFlags(remove.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);

View file

@ -296,6 +296,39 @@ public class NSUpload {
}
}
public static void updateProfileSwitch(ProfileSwitch profileSwitch) {
try {
JSONObject data = new JSONObject();
data.put("eventType", CareportalEvent.PROFILESWITCH);
data.put("duration", profileSwitch.durationInMinutes);
data.put("profile", profileSwitch.getCustomizedName());
data.put("profileJson", profileSwitch.profileJson);
data.put("profilePlugin", profileSwitch.profilePlugin);
if (profileSwitch.isCPP) {
data.put("CircadianPercentageProfile", true);
data.put("timeshift", profileSwitch.timeshift);
data.put("percentage", profileSwitch.percentage);
}
data.put("created_at", DateUtil.toISOString(profileSwitch.date));
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
if (profileSwitch._id != null) {
Context context = MainApp.instance().getApplicationContext();
Bundle bundle = new Bundle();
bundle.putString("action", "dbUpdate");
bundle.putString("collection", "treatments");
bundle.putString("data", data.toString());
bundle.putString("_id", profileSwitch._id);
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString());
}
} catch (JSONException e) {
log.error("Unhandled exception", e);
}
}
public static void uploadCareportalEntryToNS(JSONObject data) {
try {
if (data.has("preBolus") && data.has("carbs")) {

View file

@ -13,6 +13,16 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/invalidprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/invalidprofile"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_light"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -13,6 +13,16 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/invalidprofile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/invalidprofile"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@android:color/holo_red_light"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -62,6 +62,14 @@
android:text="60 min"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/invalid_sign"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:paddingEnd="10dp"
android:text="@string/invalid"
android:textColor="@android:color/holo_red_light" />
<TextView
android:id="@+id/pump_sign"
android:layout_width="0dp"

View file

@ -727,7 +727,6 @@
<string name="alert_dialog_storage_permission_text">Bitte starte dein Telefon neu oder starte AndroidAPS in den System-Einstellungen neu. Andernfalls wird AndroidAPS nicht protokolliert (wichtig zum Nachverfolgen und Verifizieren, dass der Algorithmus korrekt funktioniert)</string>
<string name="pump_tempbasal_label">TBR</string>
<string name="combo_last_bolus">%.1f IE (%s, %s)</string>
<string name="raise_urgent_alarms_as_android_notification">Nutze System-Benachrichtigungen für Alarme</string>
<string name="bolus_frequency_exceeded">Ein gleich großer Bolus wurde in der letzten Minute angefordert. Dies ist nicht zulässig, um ungewollte Doppelboli zu verhindern und vor eventuellen Bugs zu schützen.</string>
<string name="combo_activity_reading_pump_history">Historie wird gelesen</string>
<string name="combo_activity_setting_basal_profile">Basalratenprofil wird aktualisiert</string>

View file

@ -685,7 +685,6 @@
<string name="bolusstopping">estopt Bolus toediening wordt</string>
<string name="shortfat">Vet</string>
<string name="bolusstopped">Bolus toediening gestopt</string>
<string name="raise_urgent_alarms_as_android_notification">Gebruik systeem notificaties voor waarschuwingen</string>
<string name="wear_detailed_delta_title">Toon gedetaillieerde delta</string>
<string name="unsupportedfirmware">Niet ondersteune pomp firmware</string>
<string name="DexcomG5">DexcomG5 App (aangepast)</string>
@ -733,13 +732,11 @@
<string name="active"><![CDATA[<Huidig>]]></string>
<string name="none"><![CDATA[<geen>]]></string>
<string name="app_name">AndroidAPS</string>
<string name="zerovalueinprofile">Nul waarde in basaal profiel</string>
<string name="hasbgdata">BG beschikbaar op gekozen bron</string>
<string name="positiveonly">Enkel positief</string>
<string name="negativeonly">Enkel negatief</string>
<string name="maxiobset">Maximum IOB juist ingesteld</string>
<string name="overview_editquickwizard_usetrend">Trend berekening</string>
<string name="nolocaleprofilefound">Profiel wissel ontvangen via NS maar dit profiel bestaat niet op gsm</string>
<string name="combo_programming_bolus">"Bolus in pomp programmeren "</string>
<string name="combo_refresh">Vernieuw</string>
<string name="combo_pump_state_label">Status</string>
@ -767,7 +764,7 @@
<string name="combo_pump_state_suspended_by_user">Gestopt door de gebruiker</string>
<string name="combo_pump_state_running">Actief</string>
<string name="combo_pump_cartridge_low_warrning">Insuline ampul is bijna leeg</string>
<string name="combo_is_in_error_state">Pomp is in storing, controleer op de pomp</string>
<string name="combo_is_in_error_state">Pomp is in storing, controleer op de pomp: E%d %s</string>
<string name="combo_pump_action_bolusing">Bolus (%.1f E)</string>
<string name="combo_tdd_minimum">Minimum: %3.1f E</string>
<string name="combo_tdd_average">Gemiddelde: %3.1f E</string>

View file

@ -297,6 +297,8 @@
<string name="pumpbusy">Pump is busy</string>
<string name="overview_bolusprogress_delivered">Delivered</string>
<string name="overview_bolusprogress_stoped">Stopped</string>
<string name="bolusstopped">Bolus stopped</string>
<string name="bolusstopping">Stopping bolus</string>
<string name="occlusion">Occlusion</string>
<string name="overview_bolusprogress_stop">Stop</string>
<string name="overview_bolusprogress_stoppressed">STOP PRESSED</string>
@ -809,9 +811,8 @@
<string name="closedmodeenabled">Closed mode enabled</string>
<string name="maxiobset">Maximal IOB set properly</string>
<string name="hasbgdata">BG available from selected source</string>
<string name="basalprofilenotaligned">Basal values not aligned to hours</string>
<string name="zerovalueinprofile">Zero value in profile</string>
<string name="nolocaleprofilefound">Received profile switch from NS but profile doesn\'t exist localy</string>
<string name="basalprofilenotaligned" formatted="false">Basal values not aligned to hours: %s</string>
<string name="zerovalueinprofile" formatted="false">Invalid profile: %s</string>
<string name="combo_programming_bolus">Programming pump for bolusing</string>
<string name="combo_refresh">Refresh</string>
<string name="combo_tdds">TDDS</string>