OpenApsMA invoke
This commit is contained in:
parent
73ebf3ffeb
commit
a8ab671d78
4 changed files with 198 additions and 14 deletions
|
@ -98,8 +98,9 @@ public class DetermineBasalAdapterJS {
|
|||
"JSON.stringify(" + PARAM_glucoseStatus + ")+ \", \" +\n" +
|
||||
"JSON.stringify(" + PARAM_currentTemp + ")+ \", \" +\n" +
|
||||
"JSON.stringify(" + PARAM_iobData + ")+ \", \" +\n" +
|
||||
"JSON.stringify(" + PARAM_meal_data + ")+ \", \" +\n" +
|
||||
"JSON.stringify(" + PARAM_profile + ")+ \") \");");
|
||||
"JSON.stringify(" + PARAM_profile + ")+ \", \" +\n" +
|
||||
"JSON.stringify(" + PARAM_meal_data + ")+ \") \");"
|
||||
);
|
||||
mV8rt.executeVoidScript(
|
||||
"var rT = determine_basal(" +
|
||||
PARAM_glucoseStatus + ", " +
|
||||
|
@ -127,13 +128,32 @@ public class DetermineBasalAdapterJS {
|
|||
return result;
|
||||
}
|
||||
|
||||
String getGlucoseStatusParam() {
|
||||
return mV8rt.executeStringScript("JSON.stringify(" + PARAM_glucoseStatus + ");");
|
||||
}
|
||||
|
||||
String getCurrentTempParam() {
|
||||
return mV8rt.executeStringScript("JSON.stringify(" + PARAM_currentTemp + ");");
|
||||
}
|
||||
|
||||
String getIobDataParam() {
|
||||
return mV8rt.executeStringScript("JSON.stringify(" + PARAM_iobData + ");");
|
||||
}
|
||||
|
||||
String getProfileParam() {
|
||||
return mV8rt.executeStringScript("JSON.stringify(" + PARAM_profile + ");");
|
||||
}
|
||||
|
||||
String getMealDataParam() {
|
||||
return mV8rt.executeStringScript("JSON.stringify(" + PARAM_meal_data + ");");
|
||||
}
|
||||
|
||||
private void loadScript() throws IOException {
|
||||
mV8rt.executeVoidScript(
|
||||
readFile("OpenAPSMA/determine-basal.js"),
|
||||
"OpenAPSMA/bin/oref0-determine-basal.js",
|
||||
0);
|
||||
mV8rt.executeVoidScript("var determine_basal = module.exports;");
|
||||
// TODO: convert to variable too
|
||||
mV8rt.executeVoidScript(
|
||||
"var setTempBasal = function (rate, duration, profile, rT, offline) {" +
|
||||
"rT.duration = duration;\n" +
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
|
@ -41,6 +42,13 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class);
|
||||
|
||||
Button run;
|
||||
TextView lastRunView;
|
||||
TextView glucoseStatusView;
|
||||
TextView currentTempView;
|
||||
TextView iobDataView;
|
||||
TextView profileView;
|
||||
TextView mealDataView;
|
||||
TextView resultView;
|
||||
|
||||
Date lastAPSRun = null;
|
||||
APSResult lastAPSResult = null;
|
||||
|
@ -83,6 +91,13 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
|
||||
run = (Button) view.findViewById(R.id.openapsma_run);
|
||||
run.setOnClickListener(this);
|
||||
lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun);
|
||||
glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus);
|
||||
currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp);
|
||||
iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata);
|
||||
profileView = (TextView) view.findViewById(R.id.openapsma_profile);
|
||||
mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata);
|
||||
resultView = (TextView) view.findViewById(R.id.openapsma_result);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -127,7 +142,7 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
run();
|
||||
invoke();
|
||||
}
|
||||
});
|
||||
else
|
||||
|
@ -192,7 +207,18 @@ public class OpenAPSMAFragment extends Fragment implements View.OnClickListener,
|
|||
TreatmentsFragment.MealData mealData = MainActivity.treatmentsFragment.getMealData();
|
||||
|
||||
determineBasalAdapterJS.setData(profile, maxIob, maxBasal, minBg, maxBg, pump, iobTotal, glucoseStatus, mealData);
|
||||
|
||||
glucoseStatusView.setText(determineBasalAdapterJS.getGlucoseStatusParam());
|
||||
currentTempView.setText(determineBasalAdapterJS.getCurrentTempParam());
|
||||
iobDataView.setText(determineBasalAdapterJS.getIobDataParam());
|
||||
profileView.setText(determineBasalAdapterJS.getProfileParam());
|
||||
mealDataView.setText(determineBasalAdapterJS.getMealDataParam());
|
||||
|
||||
DetermineBasalResult determineBasalResult = determineBasalAdapterJS.invoke();
|
||||
|
||||
resultView.setText(determineBasalResult.json.toString());
|
||||
lastRunView.setText(new Date().toLocaleString());
|
||||
|
||||
determineBasalAdapterJS.release();
|
||||
|
||||
try {
|
||||
|
|
|
@ -4,6 +4,10 @@
|
|||
android:layout_height="match_parent"
|
||||
tools:context="info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -14,6 +18,132 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="@string/openapsma_run"
|
||||
android:id="@+id/openapsma_run" />
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_margin="10dp"
|
||||
android:background="#3e3d3d">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/openapsma_lastrun_label" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_lastrun"
|
||||
android:layout_marginLeft="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="#3e3d3d"
|
||||
android:layout_margin="10dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/openapsma_inputparameters_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/openapsma_glucosestatus_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_glucosestatus"
|
||||
android:layout_marginLeft="10dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/openapsma_currenttemp_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_currenttemp"
|
||||
android:layout_marginLeft="10dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/openapsma_iobdata_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_iobdata"
|
||||
android:layout_marginLeft="10dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/openapsma_profile_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_profile"
|
||||
android:layout_marginLeft="10dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/openapsma_mealdata_label" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_mealdata"
|
||||
android:layout_marginLeft="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_margin="10dp"
|
||||
android:background="#3e3d3d">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="@string/openapsma_result_label" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:text="Small Text"
|
||||
android:id="@+id/openapsma_result"
|
||||
android:layout_marginLeft="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
@ -61,5 +61,13 @@
|
|||
<string name="virtualpump_reservoir_label">Reservoir:</string>
|
||||
<string name="virtualpump_resultok">OK</string>
|
||||
<string name="virtualpump_sqlerror">SQL Error</string>
|
||||
<string name="openapsma_lastrun_label">Last run</string>
|
||||
<string name="openapsma_inputparameters_label">Input parameters</string>
|
||||
<string name="openapsma_glucosestatus_label">Glucose status</string>
|
||||
<string name="openapsma_currenttemp_label">Current temp</string>
|
||||
<string name="openapsma_iobdata_label">IOB data</string>
|
||||
<string name="openapsma_profile_label">Profile</string>
|
||||
<string name="openapsma_mealdata_label">Meal data</string>
|
||||
<string name="openapsma_result_label">Result</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue