deviations graph

This commit is contained in:
Milos Kozak 2017-05-04 19:51:58 +02:00
parent 289ad394ce
commit 352a2a7475
6 changed files with 174 additions and 132 deletions

View file

@ -9,14 +9,16 @@ import java.util.Date;
public class AutosensData {
long time = 0L;
String pastSensitivity = "";
double deviation = 0d;
public double deviation = 0d;
boolean calculateWithDeviation = false;
double absorbed = 0d;
double carbsFromBolus = 0d;
public double cob = 0;
public double bgi = 0d;
public double delta = 0d;
public String log(long time) {
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob;
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob;
}
}

View file

@ -280,12 +280,11 @@ public class IobCobCalculatorPlugin implements PluginBase {
log.error("! value < 39");
continue;
}
avgDelta = (bg - bucketed_data.get(i + 3).value) / 3;
delta = (bg - bucketed_data.get(i + 1).value);
IobTotal iob = calulateFromTreatmentsAndTemps(bgTime);
double bgi = Math.round((-iob.activity * sens * 5) * 100) / 100d;
double bgi = -iob.activity * sens * 5;
double deviation = delta - bgi;
List<Treatment> recentTreatments = treatmentsInterface.getTreatments5MinBack(bgTime);
@ -304,6 +303,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
}
autosensData.cob += autosensData.carbsFromBolus;
autosensData.deviation = deviation;
autosensData.bgi = bgi;
autosensData.delta = delta;
// calculate autosens only without COB
if (autosensData.cob <= 0) {

View file

@ -39,7 +39,9 @@ import com.crashlytics.android.answers.Answers;
import com.crashlytics.android.answers.CustomEvent;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.LabelFormatter;
import com.jjoe64.graphview.ValueDependentColor;
import com.jjoe64.graphview.Viewport;
import com.jjoe64.graphview.series.BarGraphSeries;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.series.PointsGraphSeries;
@ -147,13 +149,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
LinearLayout pumpStatusLayout;
GraphView bgGraph;
GraphView iobGraph;
RelativeLayout iobGraphLayout;
ImageButton menuButton;
CheckBox showPredictionView;
CheckBox showBasalsView;
CheckBox showIobView;
CheckBox showCobView;
CheckBox showDeviationsView;
RecyclerView notificationsView;
LinearLayoutManager llm;
@ -223,7 +225,6 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
bgGraph = (GraphView) view.findViewById(R.id.overview_bggraph);
iobGraph = (GraphView) view.findViewById(R.id.overview_iobgraph);
iobGraphLayout = (RelativeLayout) view.findViewById(R.id.overview_iobgraphlayout);
menuButton = (ImageButton) view.findViewById(R.id.overview_menuButton);
menuButton.setOnClickListener(this);
@ -250,6 +251,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showBasalsView = (CheckBox) view.findViewById(R.id.overview_showbasals);
showIobView = (CheckBox) view.findViewById(R.id.overview_showiob);
showCobView = (CheckBox) view.findViewById(R.id.overview_showcob);
showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations);
showPredictionView.setChecked(SP.getBoolean("showprediction", false));
showBasalsView.setChecked(SP.getBoolean("showbasals", false));
showIobView.setChecked(SP.getBoolean("showiob", false));
@ -258,6 +260,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
showBasalsView.setOnCheckedChangeListener(this);
showIobView.setOnCheckedChangeListener(this);
showCobView.setOnCheckedChangeListener(this);
showDeviationsView.setOnCheckedChangeListener(this);
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
notificationsView.setHasFixedSize(true);
@ -320,9 +323,21 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
scheduleUpdateGUI("onIobCheckedChanged");
break;
case R.id.overview_showcob:
showDeviationsView.setOnCheckedChangeListener(null);
showDeviationsView.setChecked(false);
showDeviationsView.setOnCheckedChangeListener(this);
SP.putBoolean("showcob", showCobView.isChecked());
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
scheduleUpdateGUI("onCobCheckedChanged");
break;
case R.id.overview_showdeviations:
showCobView.setOnCheckedChangeListener(null);
showCobView.setChecked(false);
showCobView.setOnCheckedChangeListener(this);
SP.putBoolean("showcob", showCobView.isChecked());
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
scheduleUpdateGUI("onDeviationsCheckedChanged");
break;
}
}
@ -1185,25 +1200,32 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// **** IOB COB graph ****
FixedLineGraphSeries<DataPoint> iobSeries;
FixedLineGraphSeries<DataPoint> cobSeries;
BarGraphSeries<DataPoint> devSeries;
Double maxIobValueFound = 0d;
Double maxCobValueFound = 0d;
Double maxDevValueFound = 0d;
if (showIobView.isChecked() || showCobView.isChecked()) {
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked()) {
//Date start = new Date();
List<DataPoint> iobArray = new ArrayList<>();
List<DataPoint> cobArray = new ArrayList<>();
List<DataPoint> devArray = new ArrayList<>();
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
if (showIobView.isChecked()) {
IobTotal iob = IobCobCalculatorPlugin.calulateFromTreatmentsAndTemps(time);
iobArray.add(new DataPoint(time, iob.iob));
maxIobValueFound = Math.max(maxIobValueFound, Math.abs(iob.iob));
}
if (showCobView.isChecked()) {
if (showCobView.isChecked() || showDeviationsView.isChecked()) {
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
if (autosensData != null) {
if (autosensData != null && showCobView.isChecked()) {
cobArray.add(new DataPoint(time, autosensData.cob));
maxCobValueFound = Math.max(maxCobValueFound, autosensData.cob);
}
if (autosensData != null && showDeviationsView.isChecked()) {
devArray.add(new DataPoint(time, autosensData.deviation));
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
}
}
}
//Profiler.log(log, "IOB processed", start);
@ -1214,17 +1236,21 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
iobSeries.setBackgroundColor(0x80FFFFFF & MainApp.sResources.getColor(R.color.iob)); //50%
iobSeries.setColor(MainApp.sResources.getColor(R.color.iob));
iobSeries.setThickness(3);
iobSeries.setTitle("IOB");
iobGraph.getGridLabelRenderer().setVerticalLabelsAlign(Paint.Align.LEFT);
if (showIobView.isChecked() && showCobView.isChecked()) {
if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) {
List<DataPoint> cobArrayRescaled = new ArrayList<>();
List<DataPoint> devArrayRescaled = new ArrayList<>();
for (int ci = 0; ci < cobArray.size(); ci++) {
cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxIobValueFound / maxCobValueFound / 2));
}
for (int ci = 0; ci < devArray.size(); ci++) {
devArrayRescaled.add(new DataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxIobValueFound / maxDevValueFound));
}
cobArray = cobArrayRescaled;
devArray = devArrayRescaled;
}
// COB
DataPoint[] cobData = new DataPoint[cobArray.size()];
cobData = cobArray.toArray(cobData);
cobSeries = new FixedLineGraphSeries<>(cobData);
@ -1232,7 +1258,21 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
cobSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
cobSeries.setColor(MainApp.sResources.getColor(R.color.cob));
cobSeries.setThickness(3);
cobSeries.setTitle("COB");
// DEVIATIONS
DataPoint[] devData = new DataPoint[devArray.size()];
devData = devArray.toArray(devData);
devSeries = new BarGraphSeries<>(devData);
devSeries.setValueDependentColor(new ValueDependentColor<DataPoint>() {
@Override
public int get(DataPoint data) {
if (data.getY() < 0) return Color.RED;
else return Color.GREEN;
}
});
//devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
//devSeries.setColor(MainApp.sResources.getColor(R.color.cob));
//devSeries.setThickness(3);
iobGraph.removeAllSeries();
@ -1241,21 +1281,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
}
if (showCobView.isChecked() && cobData.length > 0) {
iobGraph.addSeries(cobSeries);
/* iobGraph.getSecondScale().setLabelFormatter(new LabelFormatter() {
@Override
public String formatLabel(double value, boolean isValueX) {
return "";
}
@Override
public void setViewport(Viewport viewport) {
}
});
*/
}
iobGraphLayout.setVisibility(View.VISIBLE);
if (showDeviationsView.isChecked() && devData.length > 0) {
iobGraph.addSeries(devSeries);
}
iobGraph.setVisibility(View.VISIBLE);
} else {
iobGraphLayout.setVisibility(View.GONE);
iobGraph.setVisibility(View.GONE);
}
// remove old data from graph

View file

@ -205,112 +205,6 @@
android:layout_gravity="center_horizontal"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content"
android:layout_height="160dip" />
<RelativeLayout
android:id="@+id/overview_iobgraphlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_iobgraph"
android:layout_width="wrap_content"
android:layout_height="80dip" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/predictionshortlabel"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/prediction"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showprediction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/prediction" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/basalshortlabel"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/basal"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showbasals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/basal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/iob"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/iob"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showiob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/iob" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cob"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/cob"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showcob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/cob" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/overview_accepttemplayout"
android:layout_width="match_parent"
@ -418,6 +312,117 @@
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:paddingTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/predictionshortlabel"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/prediction"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showprediction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/prediction" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/basalshortlabel"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/basal"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showbasals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/basal" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/iob"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/iob"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showiob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/iob" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/cob"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/cob"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showcob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/cob" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="@string/dev"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/deviations"
android:textStyle="bold" />
<CheckBox
android:id="@+id/overview_showdeviations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="-5dp"
android:layout_marginTop="-9dp"
app:buttonTint="@color/deviations" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_bggraph"
android:layout_width="wrap_content"
android:layout_height="160dip" />
<com.jjoe64.graphview.GraphView
android:id="@+id/overview_iobgraph"
android:layout_width="wrap_content"
android:layout_height="100dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -9,6 +9,7 @@
<color name="high">#FFFF00</color>
<color name="listdelimiter">#505050</color>
<color name="tabBgColor">#f0003f59</color>
<color name="deviations">#FF0000</color>
<color name="tempTargetBackground">#77dd77</color>
<color name="tempTargetDisabledBackground">#303F9F</color>

View file

@ -599,4 +599,5 @@
<string name="danar_bluetooth_status">Bluetooh status</string>
<string name="nav_about">About</string>
<string name="smscommunicator_missingsmspermission">Missing SMS permission</string>
<string name="dev">DEV</string>
</resources>