Merge pull request #7 from MilosKozak/master

dev
This commit is contained in:
LadyViktoria 2016-06-11 22:30:12 +02:00 committed by GitHub
commit 0aa46556f5
5 changed files with 202 additions and 17 deletions

View file

@ -1,11 +1,12 @@
<configuration>
<!-- Create a file appender for a log in the application's data directory -->
<property name="EXT_FILES_DIR" value="${EXT_DIR:-/sdcard}/Android/data/${PACKAGE_NAME}/files"/>
<appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/storage/sdcard0/AndroidAPS/AndroidAPS.log</file>
<file>${EXT_FILES_DIR}/AndroidAPS.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover. Make sure the path matches the one in the file element or else
the rollover logs are placed in the working directory. -->
<fileNamePattern>/storage/sdcard0/AndroidAPS/AndroidAPS._%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<fileNamePattern>${EXT_FILES_DIR}/AndroidAPS._%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>5MB</maxFileSize>
@ -32,4 +33,4 @@
<appender-ref ref="file" />
<appender-ref ref="logcat" />
</root>
</configuration>
</configuration>

View file

@ -96,10 +96,11 @@ public class DetermineBasalAdapterJS {
mV8rt.executeVoidScript(
"console.error(\"determine_basal(\"+\n" +
"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_currentTemp + ")+ \", \" +\n" +
"JSON.stringify(" + PARAM_iobData + ")+ \", \" +\n" +
"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" +

View file

@ -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 {

View file

@ -4,16 +4,146 @@
android:layout_height="match_parent"
tools:context="info.nightscout.androidaps.plugins.OpenAPSMA.OpenAPSMAFragment">
<LinearLayout
android:orientation="vertical"
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content" >
<Button
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/openapsma_run"
android:id="@+id/openapsma_run" />
</LinearLayout>
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
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>

View file

@ -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>