insulincurves - rapid and ultra both with adjustable dia
This commit is contained in:
parent
8adff150f7
commit
a538160e76
9 changed files with 345 additions and 146 deletions
|
@ -32,7 +32,8 @@ import info.nightscout.androidaps.plugins.ConstraintsObjectives.ObjectivesFragme
|
||||||
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
import info.nightscout.androidaps.plugins.ConstraintsSafety.SafetyPlugin;
|
||||||
import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment;
|
import info.nightscout.androidaps.plugins.InsulinFastacting.InsulinFastactingFragment;
|
||||||
import info.nightscout.androidaps.plugins.InsulinFastactingProlonged.InsulinFastactingProlongedFragment;
|
import info.nightscout.androidaps.plugins.InsulinFastactingProlonged.InsulinFastactingProlongedFragment;
|
||||||
import info.nightscout.androidaps.plugins.InsulinRapidActingOref.InsulinRapidActingOrefFragment;
|
import info.nightscout.androidaps.plugins.InsulinOrefCurves.InsulinOrefRapidActingFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.InsulinOrefCurves.InsulinOrefUltraRapidActingFragment;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
import info.nightscout.androidaps.plugins.Loop.LoopFragment;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment;
|
import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalFragment;
|
||||||
|
@ -114,7 +115,8 @@ public class MainApp extends Application {
|
||||||
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
if (Config.ACTION) pluginsList.add(ActionsFragment.getPlugin());
|
||||||
pluginsList.add(InsulinFastactingFragment.getPlugin());
|
pluginsList.add(InsulinFastactingFragment.getPlugin());
|
||||||
pluginsList.add(InsulinFastactingProlongedFragment.getPlugin());
|
pluginsList.add(InsulinFastactingProlongedFragment.getPlugin());
|
||||||
pluginsList.add(InsulinRapidActingOrefFragment.getPlugin());
|
pluginsList.add(InsulinOrefRapidActingFragment.getPlugin());
|
||||||
|
pluginsList.add(InsulinOrefUltraRapidActingFragment.getPlugin());
|
||||||
pluginsList.add(SensitivityOref0Plugin.getPlugin());
|
pluginsList.add(SensitivityOref0Plugin.getPlugin());
|
||||||
pluginsList.add(SensitivityAAPSPlugin.getPlugin());
|
pluginsList.add(SensitivityAAPSPlugin.getPlugin());
|
||||||
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
pluginsList.add(SensitivityWeightedAveragePlugin.getPlugin());
|
||||||
|
|
|
@ -12,6 +12,10 @@ import info.nightscout.androidaps.db.Treatment;
|
||||||
public interface InsulinInterface {
|
public interface InsulinInterface {
|
||||||
final int FASTACTINGINSULIN = 0;
|
final int FASTACTINGINSULIN = 0;
|
||||||
final int FASTACTINGINSULINPROLONGED = 1;
|
final int FASTACTINGINSULINPROLONGED = 1;
|
||||||
|
final int OREF_RAPID_ACTING = 2;
|
||||||
|
final int OREF_ULTRA_RAPID_ACTING = 3;
|
||||||
|
final int OREF_FREE_PEAK = 4;
|
||||||
|
|
||||||
|
|
||||||
int getId();
|
int getId();
|
||||||
String getFriendlyName();
|
String getFriendlyName();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.plugins.InsulinRapidActingOref;
|
package info.nightscout.androidaps.plugins.InsulinOrefCurves;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -15,12 +15,9 @@ import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph;
|
||||||
* Created by mike on 17.04.2017.
|
* Created by mike on 17.04.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class InsulinRapidActingOrefFragment extends Fragment {
|
public abstract class InsulinOrefBaseFragment extends Fragment {
|
||||||
static InsulinRapidActingOrefPlugin insulinRapidActingOrefPlugin = new InsulinRapidActingOrefPlugin();
|
|
||||||
|
|
||||||
static public InsulinRapidActingOrefPlugin getPlugin() {
|
static InsulinOrefBasePlugin insulinPlugin = null;
|
||||||
return insulinRapidActingOrefPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextView insulinName;
|
TextView insulinName;
|
||||||
TextView insulinComment;
|
TextView insulinComment;
|
||||||
|
@ -48,10 +45,10 @@ public class InsulinRapidActingOrefFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateGUI() {
|
private void updateGUI() {
|
||||||
insulinName.setText(insulinRapidActingOrefPlugin.getFriendlyName());
|
insulinName.setText(insulinPlugin.getFriendlyName());
|
||||||
insulinComment.setText(insulinRapidActingOrefPlugin.getComment());
|
insulinComment.setText(insulinPlugin.getComment());
|
||||||
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinRapidActingOrefPlugin.getDia()).toString() + "h");
|
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinPlugin.getDia()).toString() + "h");
|
||||||
insulinGraph.show(insulinRapidActingOrefPlugin);
|
insulinGraph.show(insulinPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
package info.nightscout.androidaps.plugins.InsulinOrefCurves;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Constants;
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.data.Iob;
|
||||||
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrian on 13.08.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public abstract class InsulinOrefBasePlugin implements PluginBase, InsulinInterface {
|
||||||
|
|
||||||
|
public static double MIN_DIA = 5;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getType() {
|
||||||
|
return INSULIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getNameShort() {
|
||||||
|
return MainApp.sResources.getString(R.string.insulin_shortname);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBeHidden(int type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasFragment() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean showInList(int type) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getDia() {
|
||||||
|
double dia = MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : Constants.defaultDIA;
|
||||||
|
return Math.max(MIN_DIA, dia);
|
||||||
|
//TODO: show on chart if restriction applied
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
|
||||||
|
Iob result = new Iob();
|
||||||
|
|
||||||
|
|
||||||
|
//curveDefaults
|
||||||
|
|
||||||
|
int peak = getPeak();
|
||||||
|
|
||||||
|
|
||||||
|
if (treatment.insulin != 0d) {
|
||||||
|
|
||||||
|
long bolusTime = treatment.date;
|
||||||
|
double t = (time - bolusTime) / 1000d / 60d;
|
||||||
|
|
||||||
|
double td = getDia()*60; //getDIA() always > 5
|
||||||
|
double tp = peak;
|
||||||
|
|
||||||
|
// force the IOB to 0 if over DIA hours have passed
|
||||||
|
if (t < td) {
|
||||||
|
double tau = tp * (1 - tp / td) / (1 - 2 * tp / td);
|
||||||
|
double a = 2 * tau / td;
|
||||||
|
double S = 1 / (1 - a + (1 + a) * Math.exp(-td / tau));
|
||||||
|
result.activityContrib = treatment.insulin * (S / Math.pow(tau, 2)) * t * (1 - t / td) * Math.exp(-t / tau);
|
||||||
|
result.iobContrib = treatment.insulin * (1 - S * (1 - a) * ((Math.pow(t, 2) / (tau * td * (1 - a)) - t / tau - 1) * Math.exp(-t / tau) + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract int getPeak();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package info.nightscout.androidaps.plugins.InsulinOrefCurves;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrian on 14/08/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class InsulinOrefRapidActingFragment extends Fragment {
|
||||||
|
|
||||||
|
static InsulinOrefRapidActingPlugin insulinPlugin = new InsulinOrefRapidActingPlugin();
|
||||||
|
|
||||||
|
static public InsulinOrefRapidActingPlugin getPlugin() {
|
||||||
|
return insulinPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView insulinName;
|
||||||
|
TextView insulinComment;
|
||||||
|
TextView insulinDia;
|
||||||
|
ActivityGraph insulinGraph;
|
||||||
|
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.insulin_fragment, container, false);
|
||||||
|
|
||||||
|
insulinName = (TextView) view.findViewById(R.id.insulin_name);
|
||||||
|
insulinComment = (TextView) view.findViewById(R.id.insulin_comment);
|
||||||
|
insulinDia = (TextView) view.findViewById(R.id.insulin_dia);
|
||||||
|
insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph);
|
||||||
|
|
||||||
|
updateGUI();
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateGUI() {
|
||||||
|
insulinName.setText(insulinPlugin.getFriendlyName());
|
||||||
|
insulinComment.setText(insulinPlugin.getComment());
|
||||||
|
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinPlugin.getDia()).toString() + "h");
|
||||||
|
insulinGraph.show(insulinPlugin);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package info.nightscout.androidaps.plugins.InsulinOrefCurves;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrian on 14/08/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class InsulinOrefRapidActingPlugin extends InsulinOrefBasePlugin {
|
||||||
|
|
||||||
|
private static boolean fragmentEnabled = false;
|
||||||
|
private static boolean fragmentVisible = false;
|
||||||
|
|
||||||
|
public static final int PEAK = 75;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return OREF_RAPID_ACTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Rapid-Acting Oref";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFragmentClass() {
|
||||||
|
return InsulinOrefRapidActingFragment.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFriendlyName() {
|
||||||
|
return "Rapid-Acting Oref";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getComment() {
|
||||||
|
return MainApp.sResources.getString(R.string.fastactinginsulincomment);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int type) {
|
||||||
|
return type == INSULIN && fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisibleInTabs(int type) {
|
||||||
|
return type == INSULIN && fragmentVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
|
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getPeak() {
|
||||||
|
return PEAK;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package info.nightscout.androidaps.plugins.InsulinOrefCurves;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrian on 14/08/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class InsulinOrefUltraRapidActingFragment extends Fragment {
|
||||||
|
|
||||||
|
static InsulinOrefUltraRapidActingPlugin insulinPlugin = new InsulinOrefUltraRapidActingPlugin();
|
||||||
|
|
||||||
|
static public InsulinOrefUltraRapidActingPlugin getPlugin() {
|
||||||
|
return insulinPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextView insulinName;
|
||||||
|
TextView insulinComment;
|
||||||
|
TextView insulinDia;
|
||||||
|
ActivityGraph insulinGraph;
|
||||||
|
|
||||||
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.insulin_fragment, container, false);
|
||||||
|
|
||||||
|
insulinName = (TextView) view.findViewById(R.id.insulin_name);
|
||||||
|
insulinComment = (TextView) view.findViewById(R.id.insulin_comment);
|
||||||
|
insulinDia = (TextView) view.findViewById(R.id.insulin_dia);
|
||||||
|
insulinGraph = (ActivityGraph) view.findViewById(R.id.insuling_graph);
|
||||||
|
|
||||||
|
updateGUI();
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateGUI() {
|
||||||
|
insulinName.setText(insulinPlugin.getFriendlyName());
|
||||||
|
insulinComment.setText(insulinPlugin.getComment());
|
||||||
|
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinPlugin.getDia()).toString() + "h");
|
||||||
|
insulinGraph.show(insulinPlugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
package info.nightscout.androidaps.plugins.InsulinOrefCurves;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by adrian on 14/08/17.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class InsulinOrefUltraRapidActingPlugin extends InsulinOrefBasePlugin {
|
||||||
|
|
||||||
|
private static boolean fragmentEnabled = false;
|
||||||
|
private static boolean fragmentVisible = false;
|
||||||
|
|
||||||
|
public static final int PEAK = 55;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getId() {
|
||||||
|
return OREF_ULTRA_RAPID_ACTING;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Ultra-Rapid-Acting Oref";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFragmentClass() {
|
||||||
|
return InsulinOrefUltraRapidActingFragment.class.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFriendlyName() {
|
||||||
|
return "Ultra-Rapid-Acting Oref";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getComment() {
|
||||||
|
return "Fiasp";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled(int type) {
|
||||||
|
return type == INSULIN && fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVisibleInTabs(int type) {
|
||||||
|
return type == INSULIN && fragmentVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
||||||
|
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
||||||
|
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int getPeak() {
|
||||||
|
return PEAK;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,134 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.InsulinRapidActingOref;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.Iob;
|
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 17.04.2017.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class InsulinRapidActingOrefPlugin implements PluginBase, InsulinInterface {
|
|
||||||
|
|
||||||
private static boolean fragmentEnabled = false;
|
|
||||||
private static boolean fragmentVisible = false;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getType() {
|
|
||||||
return INSULIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFragmentClass() {
|
|
||||||
return InsulinRapidActingOrefFragment.class.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "Rapid-Acting Oref";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNameShort() {
|
|
||||||
return MainApp.sResources.getString(R.string.insulin_shortname);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled(int type) {
|
|
||||||
return type == INSULIN && fragmentEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisibleInTabs(int type) {
|
|
||||||
return type == INSULIN && fragmentVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeHidden(int type) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasFragment() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean showInList(int type) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
|
||||||
if (type == INSULIN) this.fragmentEnabled = fragmentEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
|
||||||
if (type == INSULIN) this.fragmentVisible = fragmentVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insulin interface
|
|
||||||
@Override
|
|
||||||
public int getId() {
|
|
||||||
return FASTACTINGINSULINPROLONGED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFriendlyName() {
|
|
||||||
return "Rapid-Acting Oref";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getComment() {
|
|
||||||
return MainApp.sResources.getString(R.string.fastactinginsulincomment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getDia() {
|
|
||||||
//TODO: dynamic dia fetching
|
|
||||||
return 6d;
|
|
||||||
//return MainApp.getConfigBuilder().getProfile() != null ? MainApp.getConfigBuilder().getProfile().getDia() : Constants.defaultDIA;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
|
|
||||||
Iob result = new Iob();
|
|
||||||
|
|
||||||
|
|
||||||
//curveDefaults
|
|
||||||
|
|
||||||
int peak= 75;
|
|
||||||
|
|
||||||
|
|
||||||
if (treatment.insulin != 0d) {
|
|
||||||
|
|
||||||
long bolusTime = treatment.date;
|
|
||||||
double t = (time - bolusTime) / 1000d / 60d;
|
|
||||||
|
|
||||||
double td = getDia()*60;
|
|
||||||
|
|
||||||
if(getDia() < 5){
|
|
||||||
//TODO: Check that DIA is > 5 hours for this plugin!
|
|
||||||
td = 300;
|
|
||||||
}
|
|
||||||
|
|
||||||
double tp = peak;
|
|
||||||
|
|
||||||
|
|
||||||
// force the IOB to 0 if over 5 hours have passed
|
|
||||||
if (t < td) {
|
|
||||||
double tau = tp * (1 - tp / td) / (1 - 2 * tp / td);
|
|
||||||
double a = 2 * tau / td;
|
|
||||||
double S = 1 / (1 - a + (1 + a) * Math.exp(-td / tau));
|
|
||||||
result.activityContrib = treatment.insulin * (S / Math.pow(tau, 2)) * t * (1 - t / td) * Math.exp(-t / tau);
|
|
||||||
result.iobContrib = treatment.insulin * (1 - S * (1 - a) * ((Math.pow(t, 2) / (tau * td * (1 - a)) - t / tau - 1) * Math.exp(-t / tau) + 1));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue