insulin activity graph

This commit is contained in:
Milos Kozak 2017-04-21 18:34:40 +02:00
parent 7f122f7497
commit 55a2df470e
9 changed files with 89 additions and 21 deletions

View file

@ -16,7 +16,6 @@ public interface InsulinInterface {
int getId(); int getId();
String getFriendlyName(); String getFriendlyName();
String getComment(); String getComment();
int getResourcePicture();
double getDia(); double getDia();
public Iob iobCalc(Treatment treatment, Date time, Double dia); public Iob iobCalc(Treatment treatment, Date time, Double dia);
} }

View file

@ -0,0 +1,78 @@
package info.nightscout.androidaps.plugins.InsulinFastacting;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
/**
* Created by mike on 21.04.2017.
*/
public class ActivityGraph extends GraphView {
Context context;
public ActivityGraph(Context context) {
super(context);
this.context = context;
}
public ActivityGraph(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
public void show(InsulinInterface insulin) {
double dia = insulin.getDia();
int hours = (int) Math.floor(dia + 1);
Treatment t = new Treatment(insulin);
t.created_at = new Date(0);
t.timeIndex = 0;
t.insulin = 1d;
LineGraphSeries<DataPoint> activitySeries = null;
LineGraphSeries<DataPoint> iobSeries = null;
List<DataPoint> activityArray = new ArrayList<DataPoint>();
List<DataPoint> iobArray = new ArrayList<DataPoint>();
for (long time = 0; time <= hours * 60 * 60 * 1000; time += 5 * 60 * 1000L) {
Iob iob = insulin.iobCalc(t, new Date(time), dia);
activityArray.add(new DataPoint(time / 60 / 1000, iob.activityContrib));
iobArray.add(new DataPoint(time / 60 / 1000, iob.iobContrib));
}
DataPoint[] activityDataPoints = new DataPoint[activityArray.size()];
activityDataPoints = activityArray.toArray(activityDataPoints);
addSeries(activitySeries = new LineGraphSeries<DataPoint>(activityDataPoints));
activitySeries.setThickness(8);
getViewport().setXAxisBoundsManual(true);
getViewport().setMinX(0);
getViewport().setMaxX(hours * 60);
getGridLabelRenderer().setNumHorizontalLabels(hours + 1);
getGridLabelRenderer().setHorizontalAxisTitle("[min]");
DataPoint[] iobDataPoints = new DataPoint[iobArray.size()];
iobDataPoints = iobArray.toArray(iobDataPoints);
getSecondScale().addSeries(iobSeries = new LineGraphSeries<DataPoint>(iobDataPoints));
iobSeries.setDrawBackground(true);
iobSeries.setColor(Color.MAGENTA);
iobSeries.setBackgroundColor(Color.argb(70, 255, 0, 255));
getSecondScale().setMinY(0);
getSecondScale().setMaxY(1);
}
}

View file

@ -33,8 +33,8 @@ public class InsulinFastactingFragment extends Fragment implements FragmentBase
TextView insulinComment; TextView insulinComment;
@BindView(R.id.insulin_dia) @BindView(R.id.insulin_dia)
TextView insulinDia; TextView insulinDia;
@BindView(R.id.insulin_activity) @BindView(R.id.insuling_graph)
ImageView insulinActivity; ActivityGraph insulinGraph;
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -45,7 +45,7 @@ public class InsulinFastactingFragment extends Fragment implements FragmentBase
insulinName.setText(insulinFastactingPlugin.getFriendlyName()); insulinName.setText(insulinFastactingPlugin.getFriendlyName());
insulinComment.setText(insulinFastactingPlugin.getComment()); insulinComment.setText(insulinFastactingPlugin.getComment());
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinFastactingPlugin.getDia()).toString() + "h"); insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinFastactingPlugin.getDia()).toString() + "h");
insulinActivity.setImageDrawable(MainApp.sResources.getDrawable(insulinFastactingPlugin.getResourcePicture())); insulinGraph.show(insulinFastactingPlugin);
return view; return view;
} }

View file

@ -81,11 +81,6 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
return MainApp.sResources.getString(R.string.fastactinginsulincomment); return MainApp.sResources.getString(R.string.fastactinginsulincomment);
} }
@Override
public int getResourcePicture() {
return R.drawable.insulin0;
}
@Override @Override
public double getDia() { public double getDia() {
ProfileInterface profileInterface = MainApp.getConfigBuilder().getActiveProfile(); ProfileInterface profileInterface = MainApp.getConfigBuilder().getActiveProfile();

View file

@ -14,6 +14,7 @@ import butterknife.Unbinder;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.interfaces.FragmentBase; import info.nightscout.androidaps.interfaces.FragmentBase;
import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph;
/** /**
* Created by mike on 17.04.2017. * Created by mike on 17.04.2017.
@ -33,8 +34,8 @@ public class InsulinFastactingProlongedFragment extends Fragment implements Frag
TextView insulinComment; TextView insulinComment;
@BindView(R.id.insulin_dia) @BindView(R.id.insulin_dia)
TextView insulinDia; TextView insulinDia;
@BindView(R.id.insulin_activity) @BindView(R.id.insuling_graph)
ImageView insulinActivity; ActivityGraph insulinGraph;
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
@ -45,7 +46,7 @@ public class InsulinFastactingProlongedFragment extends Fragment implements Frag
insulinName.setText(insulinFastactingProlongedPlugin.getFriendlyName()); insulinName.setText(insulinFastactingProlongedPlugin.getFriendlyName());
insulinComment.setText(insulinFastactingProlongedPlugin.getComment()); insulinComment.setText(insulinFastactingProlongedPlugin.getComment());
insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinFastactingProlongedPlugin.getDia()).toString() + "h"); insulinDia.setText(MainApp.sResources.getText(R.string.dia) + " " + new Double(insulinFastactingProlongedPlugin.getDia()).toString() + "h");
insulinActivity.setImageDrawable(MainApp.sResources.getDrawable(insulinFastactingProlongedPlugin.getResourcePicture())); insulinGraph.show(insulinFastactingProlongedPlugin);
return view; return view;
} }

View file

@ -81,11 +81,6 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
return MainApp.sResources.getString(R.string.fastactinginsulincomment); return MainApp.sResources.getString(R.string.fastactinginsulincomment);
} }
@Override
public int getResourcePicture() {
return R.drawable.insulin1;
}
@Override @Override
public double getDia() { public double getDia() {
ProfileInterface profileInterface = MainApp.getConfigBuilder().getActiveProfile(); ProfileInterface profileInterface = MainApp.getConfigBuilder().getActiveProfile();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

View file

@ -35,12 +35,12 @@
android:layout_margin="10dp" android:layout_margin="10dp"
android:textAppearance="?android:attr/textAppearanceMedium" /> android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView <info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph
android:id="@+id/insulin_activity" android:id="@+id/insuling_graph"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp" android:layout_margin="20dp"
app:srcCompat="@drawable/insulin0" /> android:layout_height="200dip" />
</LinearLayout> </LinearLayout>
</ScrollView> </ScrollView>