insulin activity graph
This commit is contained in:
parent
7f122f7497
commit
55a2df470e
9 changed files with 89 additions and 21 deletions
|
@ -16,7 +16,6 @@ public interface InsulinInterface {
|
|||
int getId();
|
||||
String getFriendlyName();
|
||||
String getComment();
|
||||
int getResourcePicture();
|
||||
double getDia();
|
||||
public Iob iobCalc(Treatment treatment, Date time, Double dia);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -33,8 +33,8 @@ public class InsulinFastactingFragment extends Fragment implements FragmentBase
|
|||
TextView insulinComment;
|
||||
@BindView(R.id.insulin_dia)
|
||||
TextView insulinDia;
|
||||
@BindView(R.id.insulin_activity)
|
||||
ImageView insulinActivity;
|
||||
@BindView(R.id.insuling_graph)
|
||||
ActivityGraph insulinGraph;
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@ -45,7 +45,7 @@ public class InsulinFastactingFragment extends Fragment implements FragmentBase
|
|||
insulinName.setText(insulinFastactingPlugin.getFriendlyName());
|
||||
insulinComment.setText(insulinFastactingPlugin.getComment());
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -81,11 +81,6 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
|
|||
return MainApp.sResources.getString(R.string.fastactinginsulincomment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResourcePicture() {
|
||||
return R.drawable.insulin0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDia() {
|
||||
ProfileInterface profileInterface = MainApp.getConfigBuilder().getActiveProfile();
|
||||
|
|
|
@ -14,6 +14,7 @@ import butterknife.Unbinder;
|
|||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.FragmentBase;
|
||||
import info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph;
|
||||
|
||||
/**
|
||||
* Created by mike on 17.04.2017.
|
||||
|
@ -33,8 +34,8 @@ public class InsulinFastactingProlongedFragment extends Fragment implements Frag
|
|||
TextView insulinComment;
|
||||
@BindView(R.id.insulin_dia)
|
||||
TextView insulinDia;
|
||||
@BindView(R.id.insulin_activity)
|
||||
ImageView insulinActivity;
|
||||
@BindView(R.id.insuling_graph)
|
||||
ActivityGraph insulinGraph;
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
@ -45,7 +46,7 @@ public class InsulinFastactingProlongedFragment extends Fragment implements Frag
|
|||
insulinName.setText(insulinFastactingProlongedPlugin.getFriendlyName());
|
||||
insulinComment.setText(insulinFastactingProlongedPlugin.getComment());
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -81,11 +81,6 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
|
|||
return MainApp.sResources.getString(R.string.fastactinginsulincomment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getResourcePicture() {
|
||||
return R.drawable.insulin1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDia() {
|
||||
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 |
|
@ -35,12 +35,12 @@
|
|||
android:layout_margin="10dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/insulin_activity"
|
||||
<info.nightscout.androidaps.plugins.InsulinFastacting.ActivityGraph
|
||||
android:id="@+id/insuling_graph"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="20dp"
|
||||
app:srcCompat="@drawable/insulin0" />
|
||||
android:layout_height="200dip" />
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
|
|
Loading…
Reference in a new issue