objectives fragment complete

This commit is contained in:
Milos Kozak 2016-06-27 18:48:48 +02:00
parent 6ebbfdc339
commit a3d32fcb44
13 changed files with 359 additions and 75 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" /> <ConfirmationsSetting value="0" id="Remove" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View file

@ -160,6 +160,18 @@ public class MainActivity extends AppCompatActivity {
return newList; return newList;
} }
public static ArrayList<PluginBase> getSpecificPluginsListByInterface(Class interfaceClass) {
ArrayList<PluginBase> newList = new ArrayList<PluginBase>();
Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) {
PluginBase p = it.next();
if (p.getClass() != ConfigBuilderFragment.class && interfaceClass.isAssignableFrom(p.getClass()))
newList.add(p);
}
return newList;
}
public static PluginBase getSpecificPlugin(Class pluginClass) { public static PluginBase getSpecificPlugin(Class pluginClass) {
Iterator<PluginBase> it = pluginsList.iterator(); Iterator<PluginBase> it = pluginsList.iterator();
while (it.hasNext()) { while (it.hasNext()) {

View file

@ -157,6 +157,7 @@ public class DataService extends IntentService {
log.debug("Received status: " + bundles); log.debug("Received status: " + bundles);
if (bundles.containsKey("nsclientversioncode")) { if (bundles.containsKey("nsclientversioncode")) {
ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder(); ConfigBuilderFragment configBuilderFragment = MainApp.getConfigBuilder();
if (configBuilderFragment != null) {
configBuilderFragment.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203 configBuilderFragment.nightscoutVersionCode = bundles.getInt("nightscoutversioncode"); // for ver 1.2.3 contains 10203
configBuilderFragment.nightscoutVersionName = bundles.getString("nightscoutversionname"); configBuilderFragment.nightscoutVersionName = bundles.getString("nightscoutversionname");
configBuilderFragment.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117 configBuilderFragment.nsClientVersionCode = bundles.getInt("nsclientversioncode"); // for ver 1.17 contains 117
@ -164,10 +165,34 @@ public class DataService extends IntentService {
log.debug("Got versions: NSClient: " + configBuilderFragment.nsClientVersionName + " Nightscout: " + configBuilderFragment.nightscoutVersionName); log.debug("Got versions: NSClient: " + configBuilderFragment.nsClientVersionName + " Nightscout: " + configBuilderFragment.nightscoutVersionName);
if (configBuilderFragment.nsClientVersionCode < 117) if (configBuilderFragment.nsClientVersionCode < 117)
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver)); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
}
} else { } else {
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver)); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), MainApp.resources.getString(R.string.unsupportedclientver));
} }
} }
if (intent.getAction().equals(Intents.ACTION_NEW_DEVICESTATUS)) {
if (nsClientEnabled) {
try {
if (bundles.containsKey("devicestatuses")) {
String devicestatusesstring = bundles.getString("devicestatuses");
JSONArray jsonArray = new JSONArray(devicestatusesstring);
if (jsonArray.length() > 0) {
JSONObject devicestatusJson = jsonArray.getJSONObject(0);
if (devicestatusJson.has("pump")) {
// Objectives 0
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) {
objectivesFragment.pumpStatusIsAvailableInNS = true;
objectivesFragment.saveProgress();
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
// Handle profile // Handle profile
if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) { if (intent.getAction().equals(Intents.ACTION_NEW_PROFILE)) {
try { try {
@ -242,10 +267,8 @@ public class DataService extends IntentService {
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
} }
} catch (JSONException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
} }
} }
@ -301,10 +324,8 @@ public class DataService extends IntentService {
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
} }
} catch (JSONException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
} }
} }
@ -328,10 +349,8 @@ public class DataService extends IntentService {
} }
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
} catch (JSONException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
} }
} }
@ -370,16 +389,17 @@ public class DataService extends IntentService {
} }
} }
} }
} catch (JSONException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} catch (Exception e1) {
e1.printStackTrace();
} }
MainApp.bus().post(new EventNewBG()); MainApp.bus().post(new EventNewBG());
} }
// Objectives 0 // Objectives 0
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class); ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) objectivesFragment.bgIsAvailableInNS = true; if (objectivesFragment != null) {
objectivesFragment.bgIsAvailableInNS = true;
objectivesFragment.saveProgress();
}
} }
} }

View file

@ -7,11 +7,24 @@ import info.nightscout.androidaps.plugins.APSResult;
*/ */
public interface ConstraintsInterface { public interface ConstraintsInterface {
boolean isLoopEnabled();
boolean isClosedModeEnabled(); boolean isClosedModeEnabled();
boolean isAutosensModeEnabled();
boolean isAMAModeEnabled();
APSResult applyBasalConstraints(APSResult request); APSResult applyBasalConstraints(APSResult request);
Double applyBasalConstraints(Double absoluteRate); Double applyBasalConstraints(Double absoluteRate);
Integer applyBasalConstraints(Integer percentRate); Integer applyBasalConstraints(Integer percentRate);
Double applyBolusConstraints(Double insulin); Double applyBolusConstraints(Double insulin);
Integer applyCarbsConstraints(Integer carbs); Integer applyCarbsConstraints(Integer carbs);
Double applyMaxIOBConstraints(Double maxIob);
} }

View file

@ -722,11 +722,24 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
/** /**
* Constraints interface * Constraints interface
**/ **/
@Override
public boolean isLoopEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue;
result = result && constrain.isLoopEnabled();
}
return result;
}
@Override @Override
public boolean isClosedModeEnabled() { public boolean isClosedModeEnabled() {
boolean result = true; boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue; if (!p.isEnabled()) continue;
@ -735,9 +748,35 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
return result; return result;
} }
@Override
public boolean isAutosensModeEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue;
result = result && constrain.isAutosensModeEnabled();
}
return result;
}
@Override
public boolean isAMAModeEnabled() {
boolean result = true;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue;
result = result && constrain.isAMAModeEnabled();
}
return result;
}
@Override @Override
public APSResult applyBasalConstraints(APSResult result) { public APSResult applyBasalConstraints(APSResult result) {
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue; if (!p.isEnabled()) continue;
@ -749,11 +788,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override @Override
public Double applyBasalConstraints(Double absoluteRate) { public Double applyBasalConstraints(Double absoluteRate) {
Double rateAfterConstrain = absoluteRate; Double rateAfterConstrain = absoluteRate;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue; if (!p.isEnabled()) continue;
rateAfterConstrain = constrain.applyBasalConstraints(rateAfterConstrain); rateAfterConstrain = Math.min(constrain.applyBasalConstraints(rateAfterConstrain), rateAfterConstrain);
} }
return rateAfterConstrain; return rateAfterConstrain;
} }
@ -761,11 +800,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override @Override
public Integer applyBasalConstraints(Integer percentRate) { public Integer applyBasalConstraints(Integer percentRate) {
Integer rateAfterConstrain = percentRate; Integer rateAfterConstrain = percentRate;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue; if (!p.isEnabled()) continue;
rateAfterConstrain = constrain.applyBasalConstraints(rateAfterConstrain); rateAfterConstrain = Math.min(constrain.applyBasalConstraints(rateAfterConstrain), rateAfterConstrain);
} }
return rateAfterConstrain; return rateAfterConstrain;
} }
@ -773,11 +812,11 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override @Override
public Double applyBolusConstraints(Double insulin) { public Double applyBolusConstraints(Double insulin) {
Double insulinAfterConstrain = insulin; Double insulinAfterConstrain = insulin;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue; if (!p.isEnabled()) continue;
insulinAfterConstrain = constrain.applyBolusConstraints(insulinAfterConstrain); insulinAfterConstrain = Math.min(constrain.applyBolusConstraints(insulinAfterConstrain), insulinAfterConstrain);
} }
return insulinAfterConstrain; return insulinAfterConstrain;
} }
@ -785,15 +824,27 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
@Override @Override
public Integer applyCarbsConstraints(Integer carbs) { public Integer applyCarbsConstraints(Integer carbs) {
Integer carbsAfterConstrain = carbs; Integer carbsAfterConstrain = carbs;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsList(PluginBase.CONSTRAINTS); ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) { for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p; ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue; if (!p.isEnabled()) continue;
carbsAfterConstrain = constrain.applyCarbsConstraints(carbsAfterConstrain); carbsAfterConstrain = Math.min(constrain.applyCarbsConstraints(carbsAfterConstrain), carbsAfterConstrain);
} }
return carbsAfterConstrain; return carbsAfterConstrain;
} }
@Override
public Double applyMaxIOBConstraints(Double maxIob) {
Double maxIobAfterConstrain = maxIob;
ArrayList<PluginBase> constraintsPlugins = MainActivity.getSpecificPluginsListByInterface(ConstraintsInterface.class);
for (PluginBase p : constraintsPlugins) {
ConstraintsInterface constrain = (ConstraintsInterface) p;
if (!p.isEnabled()) continue;
maxIobAfterConstrain = Math.min(constrain.applyMaxIOBConstraints(maxIobAfterConstrain), maxIobAfterConstrain);
}
return maxIobAfterConstrain;
}
public static void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) { public static void uploadTempBasalStartAbsolute(Double absolute, double durationInMinutes) {
try { try {
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();

View file

@ -215,6 +215,18 @@ public class LoopFragment extends Fragment implements View.OnClickListener, Plug
public void invoke(boolean allowNotification) { public void invoke(boolean allowNotification) {
ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder(); ConstraintsInterface constraintsInterface = MainApp.getConfigBuilder();
if (!constraintsInterface.isLoopEnabled()) {
clearGUI();
final Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
lastRunView.setText(activity.getString(R.string.loopdisabled));
}
});
return;
}
PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump(); PumpInterface pumpInterface = MainApp.getConfigBuilder().getActivePump();
APSResult result = null; APSResult result = null;

View file

@ -1,5 +1,6 @@
package info.nightscout.androidaps.plugins.Objectives; package info.nightscout.androidaps.plugins.Objectives;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
@ -15,6 +16,8 @@ import android.widget.CheckBox;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -23,8 +26,10 @@ import java.util.Date;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.interfaces.ConstraintsInterface; import info.nightscout.androidaps.interfaces.ConstraintsInterface;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.APSResult; import info.nightscout.androidaps.plugins.APSResult;
@ -34,7 +39,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
RecyclerView recyclerView; RecyclerView recyclerView;
LinearLayoutManager llm; LinearLayoutManager llm;
CheckBox enableFakeTime; CheckBox enableFake; // TODO: remove faking
boolean fragmentVisible = true; boolean fragmentVisible = true;
@ -84,13 +89,15 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
} }
class Objective { class Objective {
Integer num;
String objective; String objective;
String gate; String gate;
Date started; Date started;
Integer durationInDays; Integer durationInDays;
Date accomplished; Date accomplished;
Objective(String objective, String gate, Date started, Integer durationInDays, Date accomplished) { Objective(Integer num, String objective, String gate, Date started, Integer durationInDays, Date accomplished) {
this.num = num;
this.objective = objective; this.objective = objective;
this.gate = gate; this.gate = gate;
this.started = started; this.started = started;
@ -102,36 +109,91 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
// Objective 0 // Objective 0
public boolean bgIsAvailableInNS = false; public boolean bgIsAvailableInNS = false;
public boolean pumpStatusIsAvailableInNS = false; public boolean pumpStatusIsAvailableInNS = false;
// Objective 1
public Integer manualEnacts = 0;
public final Integer manualEnactsNeeded = 20;
class RequirementResult {
boolean done = false;
String comment = "";
public RequirementResult(boolean done, String comment) {
this.done = done;
this.comment = comment;
}
}
private String yesOrNo(boolean yes) {
if (yes) return "";
else return "---";
}
private RequirementResult requirementsMet(Integer objNum) {
switch (objNum) {
case 0:
return new RequirementResult(bgIsAvailableInNS && pumpStatusIsAvailableInNS,
getString(R.string.bgavailableinns) + ": " + yesOrNo(bgIsAvailableInNS)
+ " " + getString(R.string.pumpstatusavailableinns) + ": " + yesOrNo(pumpStatusIsAvailableInNS));
case 1:
return new RequirementResult(manualEnacts >= manualEnactsNeeded,
getString(R.string.manualenacts) + ": " + manualEnacts + "/" + manualEnactsNeeded);
case 2:
return new RequirementResult(true, "");
default:
return new RequirementResult(false, "");
}
}
private List<Objective> objectives; private List<Objective> objectives;
private void initializeData() { private void initializeData() {
objectives = new ArrayList<>(); objectives = new ArrayList<>();
objectives.add(new Objective("Setting up visualization and monitoring, and analyzing basals and ratios", objectives.add(new Objective(0,
"Setting up visualization and monitoring, and analyzing basals and ratios",
"Verify that BG is available in Nightscout, and pump insulin data is being uploaded", "Verify that BG is available in Nightscout, and pump insulin data is being uploaded",
new Date(0, 0, 0), 1, new Date(0, 0, 0))); new Date(0, 0, 0),
objectives.add(new Objective("Starting on an open loop", 1, // 1 day
new Date(0, 0, 0)));
objectives.add(new Objective(1,
"Starting on an open loop",
"Run in Open Loop mode for a few days, and manually enact lots of temp basals", "Run in Open Loop mode for a few days, and manually enact lots of temp basals",
new Date(0, 0, 0), 1, new Date(0, 0, 0))); new Date(0, 0, 0),
objectives.add(new Objective("Understanding your open loop, including its temp basal recommendations", 7, // 7 days
"Based on that experience, decide what max basal should be, and set it on the pump", new Date(0, 0, 0)));
new Date(0, 0, 0), 1, new Date(0, 0, 0))); objectives.add(new Objective(2,
objectives.add(new Objective("Starting to close the loop with Low Glucose Suspend", "Understanding your open loop, including its temp basal recommendations",
"Based on that experience, decide what max basal should be, and set it on the pump and preferences",
new Date(0, 0, 0),
0, // 0 days
new Date(0, 0, 0)));
objectives.add(new Objective(3,
"Starting to close the loop with Low Glucose Suspend",
"Run in closed loop with max IOB = 0 for a few days without too many LGS events", "Run in closed loop with max IOB = 0 for a few days without too many LGS events",
new Date(0, 0, 0), 1, new Date(0, 0, 0))); new Date(0, 0, 0),
objectives.add(new Objective("Tuning the closed loop, raising max IOB above 0 and gradually lowering BG targets", 5, // 5 days
new Date(0, 0, 0)));
objectives.add(new Objective(4,
"Tuning the closed loop, raising max IOB above 0 and gradually lowering BG targets",
"Run for a few days, and at least one night with no low BG alarms, before dropping BG", "Run for a few days, and at least one night with no low BG alarms, before dropping BG",
new Date(0, 0, 0), 1, new Date(0, 0, 0))); new Date(0, 0, 0),
objectives.add(new Objective("Adjust basals and ratios if needed, and then enable auto-sens", 1,
new Date(0, 0, 0)));
objectives.add(new Objective(5,
"Adjust basals and ratios if needed, and then enable auto-sens",
"1 week successful daytime looping with regular carb entry", "1 week successful daytime looping with regular carb entry",
new Date(0, 0, 0), 7, new Date(0, 0, 0))); new Date(0, 0, 0),
objectives.add(new Objective("Enabling additional features for daytime use, such as advanced meal assist", 7,
new Date(0, 0, 0)));
objectives.add(new Objective(6,
"Enabling additional features for daytime use, such as advanced meal assist",
"", "",
new Date(0, 0, 0), 1, new Date(0, 0, 0))); new Date(0, 0, 0),
1,
new Date(0, 0, 0)));
} }
void saveProgress() { public void saveProgress() {
SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0); SharedPreferences settings = MainApp.instance().getApplicationContext().getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit(); SharedPreferences.Editor editor = settings.edit();
for (int num = 0; num < objectives.size(); num++) { for (int num = 0; num < objectives.size(); num++) {
@ -139,6 +201,9 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
editor.putLong(num + "started", o.started.getTime()); editor.putLong(num + "started", o.started.getTime());
editor.putLong(num + "accomplished", o.accomplished.getTime()); editor.putLong(num + "accomplished", o.accomplished.getTime());
} }
editor.putBoolean("bgIsAvailableInNS", bgIsAvailableInNS);
editor.putBoolean("pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
editor.putInt("manualEnacts", manualEnacts);
editor.commit(); editor.commit();
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Objectives stored"); log.debug("Objectives stored");
@ -151,14 +216,13 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
o.started = new Date(settings.getLong(num + "started", 0)); o.started = new Date(settings.getLong(num + "started", 0));
o.accomplished = new Date(settings.getLong(num + "accomplished", 0)); o.accomplished = new Date(settings.getLong(num + "accomplished", 0));
} }
bgIsAvailableInNS = settings.getBoolean("bgIsAvailableInNS", false);
pumpStatusIsAvailableInNS = settings.getBoolean("pumpStatusIsAvailableInNS", false);
manualEnacts = settings.getInt("manualEnacts", 0);
if (Config.logPrefsChange) if (Config.logPrefsChange)
log.debug("Objectives loaded"); log.debug("Objectives loaded");
} }
boolean isAPSEnabledAtAll() {
return true;
}
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ObjectiveViewHolder> { public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ObjectiveViewHolder> {
List<Objective> objectives; List<Objective> objectives;
@ -177,11 +241,13 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
@Override @Override
public void onBindViewHolder(ObjectiveViewHolder holder, int position) { public void onBindViewHolder(ObjectiveViewHolder holder, int position) {
Objective o = objectives.get(position); Objective o = objectives.get(position);
RequirementResult requirementsMet = requirementsMet(position);
Context context = MainApp.instance().getApplicationContext(); Context context = MainApp.instance().getApplicationContext();
holder.position.setText(String.valueOf(position + 1)); holder.position.setText(String.valueOf(position + 1));
holder.objective.setText(o.objective); holder.objective.setText(o.objective);
holder.gate.setText(o.gate); holder.gate.setText(o.gate);
holder.duration.setText(context.getString(R.string.minimalduration) + " " + o.durationInDays + " " + context.getString(R.string.days)); holder.duration.setText(context.getString(R.string.minimalduration) + " " + o.durationInDays + " " + context.getString(R.string.days));
holder.progress.setText(requirementsMet.comment);
holder.started.setText(o.started.toLocaleString()); holder.started.setText(o.started.toLocaleString());
holder.accomplished.setText(o.accomplished.toLocaleString()); holder.accomplished.setText(o.accomplished.toLocaleString());
@ -192,16 +258,18 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
public void onClick(View v) { public void onClick(View v) {
Objective o = (Objective) v.getTag(); Objective o = (Objective) v.getTag();
o.started = new Date(); o.started = new Date();
updateView(); updateGUI();
//saveProgress(); saveProgress();
} }
}); });
holder.verifyButton.setOnClickListener(new View.OnClickListener() { holder.verifyButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
Objective o = (Objective) v.getTag(); Objective o = (Objective) v.getTag();
if (requirementsMet(o.num).done || enableFake.isChecked()) {
o.accomplished = new Date(); o.accomplished = new Date();
updateView(); updateGUI();
//saveProgress(); saveProgress();
}
} }
}); });
@ -210,18 +278,20 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
// Phase 0: previous not completed // Phase 0: previous not completed
holder.startedLayout.setVisibility(View.GONE); holder.startedLayout.setVisibility(View.GONE);
holder.durationLayout.setVisibility(View.GONE); holder.durationLayout.setVisibility(View.GONE);
holder.progressLayout.setVisibility(View.GONE);
holder.verifyLayout.setVisibility(View.GONE); holder.verifyLayout.setVisibility(View.GONE);
} else if (o.started.getTime() == 0) { } else if (o.started.getTime() == 0) {
// Phase 1: not started // Phase 1: not started
holder.durationLayout.setVisibility(View.GONE); holder.durationLayout.setVisibility(View.GONE);
holder.progressLayout.setVisibility(View.GONE);
holder.verifyLayout.setVisibility(View.GONE); holder.verifyLayout.setVisibility(View.GONE);
holder.started.setVisibility(View.GONE); holder.started.setVisibility(View.GONE);
} else if (o.started.getTime() > 0 && !enableFakeTime.isChecked() && o.accomplished.getTime() == 0 && o.started.getTime() + o.durationInDays * 24 * 60 * 60 * 1000 > now) { } else if (o.started.getTime() > 0 && !enableFake.isChecked() && o.accomplished.getTime() == 0 && o.started.getTime() + o.durationInDays * 24 * 60 * 60 * 1000 > now && !requirementsMet.done) {
// Phase 2: started, waiting for duration // Phase 2: started, waiting for duration and met requirements
holder.startButton.setEnabled(false); holder.startButton.setEnabled(false);
holder.verifyLayout.setVisibility(View.GONE); holder.verifyLayout.setVisibility(View.GONE);
} else if (o.accomplished.getTime() == 0) { } else if (o.accomplished.getTime() == 0) {
// Phase 3: started, after duration // Phase 3: started, after duration, requirements met
holder.startButton.setEnabled(false); holder.startButton.setEnabled(false);
holder.accomplished.setVisibility(View.INVISIBLE); holder.accomplished.setVisibility(View.INVISIBLE);
} else { } else {
@ -229,6 +299,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
holder.gateLayout.setVisibility(View.GONE); holder.gateLayout.setVisibility(View.GONE);
holder.startedLayout.setVisibility(View.GONE); holder.startedLayout.setVisibility(View.GONE);
holder.durationLayout.setVisibility(View.GONE); holder.durationLayout.setVisibility(View.GONE);
holder.progressLayout.setVisibility(View.GONE);
holder.verifyButton.setVisibility(View.INVISIBLE); holder.verifyButton.setVisibility(View.INVISIBLE);
} }
} }
@ -251,6 +322,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
TextView gate; TextView gate;
TextView duration; TextView duration;
LinearLayout durationLayout; LinearLayout durationLayout;
TextView progress;
LinearLayout progressLayout;
TextView started; TextView started;
Button startButton; Button startButton;
LinearLayout startedLayout; LinearLayout startedLayout;
@ -265,6 +338,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
objective = (TextView) itemView.findViewById(R.id.objectives_objective); objective = (TextView) itemView.findViewById(R.id.objectives_objective);
durationLayout = (LinearLayout) itemView.findViewById(R.id.objectives_duration_linearlayout); durationLayout = (LinearLayout) itemView.findViewById(R.id.objectives_duration_linearlayout);
duration = (TextView) itemView.findViewById(R.id.objectives_duration); duration = (TextView) itemView.findViewById(R.id.objectives_duration);
progressLayout = (LinearLayout) itemView.findViewById(R.id.objectives_progresslayout);
progress = (TextView) itemView.findViewById(R.id.objectives_progress);
gateLayout = (LinearLayout) itemView.findViewById(R.id.objectives_gate_linearlayout); gateLayout = (LinearLayout) itemView.findViewById(R.id.objectives_gate_linearlayout);
gate = (TextView) itemView.findViewById(R.id.objectives_gate); gate = (TextView) itemView.findViewById(R.id.objectives_gate);
startedLayout = (LinearLayout) itemView.findViewById(R.id.objectives_start_linearlayout); startedLayout = (LinearLayout) itemView.findViewById(R.id.objectives_start_linearlayout);
@ -281,6 +356,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
super(); super();
initializeData(); initializeData();
loadProgress(); loadProgress();
registerBus();
} }
public static ObjectivesFragment newInstance() { public static ObjectivesFragment newInstance() {
@ -302,29 +378,84 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
recyclerView.setHasFixedSize(true); recyclerView.setHasFixedSize(true);
llm = new LinearLayoutManager(view.getContext()); llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm); recyclerView.setLayoutManager(llm);
enableFakeTime = (CheckBox) view.findViewById(R.id.objectives_faketime); enableFake = (CheckBox) view.findViewById(R.id.objectives_fake);
enableFakeTime.setOnClickListener(new View.OnClickListener() { enableFake.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) { public void onClick(View v) {
updateView(); updateGUI();
} }
}); });
updateView(); updateGUI();
return view; return view;
} }
void updateView() { private void registerBus() {
try {
MainApp.bus().unregister(this);
} catch (RuntimeException x) {
// Ignore
}
MainApp.bus().register(this);
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
updateGUI();
}
});
else
log.debug("EventNewBG: Activity is null");
}
void updateGUI() {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectives); RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectives);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
} }
});
}
/** /**
* Constraints interface * Constraints interface
**/ **/
@Override
public boolean isLoopEnabled() {
return objectives.get(1).started.getTime() > 0;
}
@Override @Override
public boolean isClosedModeEnabled() { public boolean isClosedModeEnabled() {
return true; // TODO: revert back return objectives.get(3).started.getTime() > 0;
//return objectives.get(3).started.getTime() > 0; }
@Override
public boolean isAutosensModeEnabled() {
return objectives.get(5).started.getTime() > 0;
}
@Override
public boolean isAMAModeEnabled() {
return objectives.get(6).started.getTime() > 0;
}
@Override
public Double applyMaxIOBConstraints(Double maxIob) {
if (objectives.get(4).started.getTime() > 0)
return maxIob;
else {
if (Config.logConstraintsChanges)
log.debug("Limiting maxIOB " + maxIob + " to " + 0 + "U");
return 0d;
}
} }
@Override @Override

View file

@ -273,6 +273,8 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
TreatmentsFragment.MealData mealData = treatments.getMealData(); TreatmentsFragment.MealData mealData = treatments.getMealData();
maxIob = MainApp.getConfigBuilder().applyMaxIOBConstraints(maxIob);
determineBasalAdapterJS.setData(profile, maxIob, maxBasal, minBg, maxBg, pump, iobTotal, glucoseStatus, mealData); determineBasalAdapterJS.setData(profile, maxIob, maxBasal, minBg, maxBg, pump, iobTotal, glucoseStatus, mealData);

View file

@ -37,6 +37,7 @@ import java.util.List;
import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainActivity;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult; import info.nightscout.androidaps.data.PumpEnactResult;
@ -52,6 +53,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.Loop.LoopFragment; import info.nightscout.androidaps.plugins.Loop.LoopFragment;
import info.nightscout.androidaps.plugins.Objectives.ObjectivesFragment;
import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal; import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewExtendedBolusDialog;
import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog; import info.nightscout.androidaps.plugins.Overview.Dialogs.NewTempBasalDialog;
@ -241,6 +243,11 @@ public class OverviewFragment extends Fragment implements PluginBase {
finalLastRun.lastEnact = new Date(); finalLastRun.lastEnact = new Date();
finalLastRun.lastOpenModeAccept = new Date(); finalLastRun.lastOpenModeAccept = new Date();
MainApp.getConfigBuilder().uploadDeviceStatus(); MainApp.getConfigBuilder().uploadDeviceStatus();
ObjectivesFragment objectivesFragment = (ObjectivesFragment) MainActivity.getSpecificPlugin(ObjectivesFragment.class);
if (objectivesFragment != null) {
objectivesFragment.manualEnacts++;
objectivesFragment.saveProgress();
}
} }
updateGUI(); updateGUI();
} }

View file

@ -62,6 +62,11 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
return fragment; return fragment;
} }
@Override
public boolean isLoopEnabled() {
return true;
}
/** /**
* Constraints interface * Constraints interface
**/ **/
@ -72,9 +77,19 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
return mode.equals("closed"); return mode.equals("closed");
} }
@Override
public boolean isAutosensModeEnabled() {
return true;
}
@Override
public boolean isAMAModeEnabled() {
return true;
}
@Override @Override
public APSResult applyBasalConstraints(APSResult result) { public APSResult applyBasalConstraints(APSResult result) {
result.rate = applyBasalConstraints(result.rate); result.rate = Math.min(applyBasalConstraints(result.rate), result.rate);
return result; return result;
} }
@ -182,4 +197,9 @@ public class SafetyFragment extends Fragment implements PluginBase, ConstraintsI
return carbs; return carbs;
} }
@Override
public Double applyMaxIOBConstraints(Double maxIob) {
return maxIob;
}
} }

View file

@ -12,8 +12,8 @@
<CheckBox <CheckBox
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Enable fake time" android:text="Enable fake time and progress"
android:id="@+id/objectives_faketime" /> android:id="@+id/objectives_fake" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/objectives_recyclerview" android:id="@+id/objectives_recyclerview"

View file

@ -124,6 +124,18 @@
android:id="@+id/objectives_duration" /> android:id="@+id/objectives_duration" />
</LinearLayout> </LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/objectives_progresslayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/objectives_progress" />
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"

View file

@ -112,7 +112,7 @@
<string name="loop_constraintsprocessed_label">After processed constraints</string> <string name="loop_constraintsprocessed_label">After processed constraints</string>
<string name="loop_setbypump_label">Set by pump</string> <string name="loop_setbypump_label">Set by pump</string>
<string name="openapsma_lastenact_label">Last enacted</string> <string name="openapsma_lastenact_label">Last enacted</string>
<string name="dialog">Dialog</string> <string name="dialog">Confirmation</string>
<string name="alert">Alert</string> <string name="alert">Alert</string>
<string name="refreshfromnightscout">Do you want to refresh treatments from Nightscout</string> <string name="refreshfromnightscout">Do you want to refresh treatments from Nightscout</string>
<string name="ok">OK</string> <string name="ok">OK</string>
@ -150,5 +150,9 @@
<string name="openloop">Open Loop</string> <string name="openloop">Open Loop</string>
<string name="openloop_newsuggestion">New suggestion available</string> <string name="openloop_newsuggestion">New suggestion available</string>
<string name="unsupportedclientver">Unsupported version of NSClient</string> <string name="unsupportedclientver">Unsupported version of NSClient</string>
<string name="bgavailableinns">BG available in NS</string>
<string name="pumpstatusavailableinns">Pump status available in NS</string>
<string name="manualenacts">Manual enacts</string>
<string name="loopdisabled">LOOP DISABLED BY CONSTRAINTS</string>
</resources> </resources>