ActivityGraph -> kt
This commit is contained in:
parent
e1c7963c98
commit
bbcc813474
2 changed files with 56 additions and 78 deletions
|
@ -1,78 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.insulin;
|
|
||||||
|
|
||||||
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.List;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.Iob;
|
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
|
||||||
removeAllSeries();
|
|
||||||
mSecondScale = null;
|
|
||||||
double dia = insulin.getDia();
|
|
||||||
int hours = (int) Math.floor(dia + 1);
|
|
||||||
|
|
||||||
Treatment t = new Treatment();
|
|
||||||
t.date = 0;
|
|
||||||
t.insulin = 1d;
|
|
||||||
|
|
||||||
LineGraphSeries<DataPoint> activitySeries = null;
|
|
||||||
LineGraphSeries<DataPoint> iobSeries = null;
|
|
||||||
List<DataPoint> activityArray = new ArrayList<>();
|
|
||||||
List<DataPoint> iobArray = new ArrayList<>();
|
|
||||||
|
|
||||||
for (long time = 0; time <= hours * 60 * 60 * 1000; time += 5 * 60 * 1000L) {
|
|
||||||
Iob iob = t.iobCalc(time, dia);
|
|
||||||
activityArray.add(new DataPoint(time / 60.0 / 1000, iob.activityContrib));
|
|
||||||
iobArray.add(new DataPoint(time / 60.0 / 1000, iob.iobContrib));
|
|
||||||
}
|
|
||||||
|
|
||||||
DataPoint[] activityDataPoints = new DataPoint[activityArray.size()];
|
|
||||||
activityDataPoints = activityArray.toArray(activityDataPoints);
|
|
||||||
addSeries(activitySeries = new LineGraphSeries<>(activityDataPoints));
|
|
||||||
activitySeries.setThickness(8);
|
|
||||||
|
|
||||||
getViewport().setXAxisBoundsManual(true);
|
|
||||||
getViewport().setMinX(0);
|
|
||||||
getViewport().setMaxX(hours * 60);
|
|
||||||
getGridLabelRenderer().setNumHorizontalLabels(hours + 1);
|
|
||||||
getGridLabelRenderer().setHorizontalAxisTitle("[min]");
|
|
||||||
getGridLabelRenderer().setVerticalLabelsColor(activitySeries.getColor());
|
|
||||||
|
|
||||||
DataPoint[] iobDataPoints = new DataPoint[iobArray.size()];
|
|
||||||
iobDataPoints = iobArray.toArray(iobDataPoints);
|
|
||||||
getSecondScale().addSeries(iobSeries = new LineGraphSeries<>(iobDataPoints));
|
|
||||||
iobSeries.setDrawBackground(true);
|
|
||||||
iobSeries.setColor(Color.MAGENTA);
|
|
||||||
iobSeries.setBackgroundColor(Color.argb(70, 255, 0, 255));
|
|
||||||
getSecondScale().setMinY(0);
|
|
||||||
getSecondScale().setMaxY(1);
|
|
||||||
getGridLabelRenderer().setVerticalLabelsSecondScaleColor(Color.MAGENTA);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package info.nightscout.androidaps.plugins.insulin
|
||||||
|
|
||||||
|
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 info.nightscout.androidaps.db.Treatment
|
||||||
|
import info.nightscout.androidaps.interfaces.InsulinInterface
|
||||||
|
import info.nightscout.androidaps.utils.T
|
||||||
|
import java.util.*
|
||||||
|
import kotlin.math.floor
|
||||||
|
|
||||||
|
class ActivityGraph : GraphView {
|
||||||
|
|
||||||
|
constructor(context: Context) : super(context)
|
||||||
|
|
||||||
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||||
|
|
||||||
|
fun show(insulin: InsulinInterface) {
|
||||||
|
removeAllSeries()
|
||||||
|
mSecondScale = null
|
||||||
|
val hours = floor(insulin.dia + 1).toLong()
|
||||||
|
val t = Treatment().also {
|
||||||
|
it.date = 0
|
||||||
|
it.insulin = 1.0
|
||||||
|
}
|
||||||
|
val activityArray: MutableList<DataPoint> = ArrayList()
|
||||||
|
val iobArray: MutableList<DataPoint> = ArrayList()
|
||||||
|
var time: Long = 0
|
||||||
|
while (time <= T.hours(hours).msecs()) {
|
||||||
|
val iob = t.iobCalc(time, insulin.dia)
|
||||||
|
activityArray.add(DataPoint(T.msecs(time).mins().toDouble(), iob.activityContrib))
|
||||||
|
iobArray.add(DataPoint(T.msecs(time).mins().toDouble(), iob.iobContrib))
|
||||||
|
time += T.mins(5).msecs()
|
||||||
|
}
|
||||||
|
addSeries(LineGraphSeries(Array(activityArray.size) { i -> activityArray[i] }).also {
|
||||||
|
it.thickness = 8
|
||||||
|
gridLabelRenderer.verticalLabelsColor = it.color
|
||||||
|
})
|
||||||
|
viewport.isXAxisBoundsManual = true
|
||||||
|
viewport.setMinX(0.0)
|
||||||
|
viewport.setMaxX((hours * 60).toDouble())
|
||||||
|
gridLabelRenderer.numHorizontalLabels = (hours + 1).toInt()
|
||||||
|
gridLabelRenderer.horizontalAxisTitle = "[min]"
|
||||||
|
secondScale.addSeries(LineGraphSeries(Array(iobArray.size) { i -> iobArray[i] }).also {
|
||||||
|
it.isDrawBackground = true
|
||||||
|
it.color = Color.MAGENTA
|
||||||
|
it.backgroundColor = Color.argb(70, 255, 0, 255)
|
||||||
|
})
|
||||||
|
secondScale.minY = 0.0
|
||||||
|
secondScale.maxY = 1.0
|
||||||
|
gridLabelRenderer.verticalLabelsSecondScaleColor = Color.MAGENTA
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue