BgReading after = null; final int chopResult = runBinarySearchIteratively(readings, timestamp, ascending); calculatedYpos = (float) (interpolateCalculatedValue(before, after, timestamp) * unitsScale);
static double interpolateCalculatedValue(BgReading first, BgReading second, long timestamp) { return interpolate(first.timestamp, first.getDg_mgdl(), second.timestamp, second.getDg_mgdl(), timestamp); } }
@Test public void interpolateCalculatedValueTest() { final long startTime = 1531124821000L; final long endTime = startTime + (Constants.MINUTE_IN_MS * 10); final BgReading first = new BgReading(); final BgReading second = new BgReading(); first.timestamp = startTime; first.calculated_value = 100; second.timestamp = endTime; second.calculated_value = 200; assertWithMessage("time at first matches first").that(interpolateCalculatedValue(first,second, startTime)).isEqualTo(100.0); assertWithMessage("time at second matches second").that(interpolateCalculatedValue(first,second, endTime)).isEqualTo(200.0); assertWithMessage("time point 1 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 150))).isEqualTo(125.0); assertWithMessage("time point 2 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 300))).isEqualTo(150.0); assertWithMessage("time point 3 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 400))).isWithin(0.1).of(166.6); } }
final Pair<Float, Float> yPositions = GraphTools.bestYPosition(bgReadings, treatment.timestamp, doMgdl, false, highMark, 10 + (100d * treatment.insulin)); if (yPositions.first > 0) { final PointValueExtended pv = new PointValueExtended(treatment.timestamp / FUZZER, yPositions.first); // TEST VALUES pv.setPlumbPos(GraphTools.yposRatio(yPositions.second, yPositions.first, 0.1f)); BitmapLoader.loadAndSetKey(pv, R.drawable.triangle, 180); pv.setBitmapTint(getCol(X.color_smb_icon)); consecutiveCloseIcons = 0; final Pair<Float, Float> yPositions = GraphTools.bestYPosition(bgReadings, treatment.timestamp, doMgdl, false, highMark, 27d + (18d * consecutiveCloseIcons)); pv.set(treatment.timestamp / FUZZER, yPositions.first);
@Test public void interpolateCalculatedValueTest() { final long startTime = 1531124821000L; final long endTime = startTime + (Constants.MINUTE_IN_MS * 10); final BgReading first = new BgReading(); final BgReading second = new BgReading(); first.timestamp = startTime; first.calculated_value = 100; second.timestamp = endTime; second.calculated_value = 200; assertWithMessage("time at first matches first").that(interpolateCalculatedValue(first,second, startTime)).isEqualTo(100.0); assertWithMessage("time at second matches second").that(interpolateCalculatedValue(first,second, endTime)).isEqualTo(200.0); assertWithMessage("time point 1 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 150))).isEqualTo(125.0); assertWithMessage("time point 2 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 300))).isEqualTo(150.0); assertWithMessage("time point 3 matches expected").that(interpolateCalculatedValue(first,second, startTime+(Constants.SECOND_IN_MS * 400))).isWithin(0.1).of(166.6); } }
final Pair<Float, Float> yPositions = GraphTools.bestYPosition(bgReadings, treatment.timestamp, doMgdl, false, highMark, 10 + (100d * treatment.insulin)); if (yPositions.first > 0) { final PointValueExtended pv = new PointValueExtended(treatment.timestamp / FUZZER, yPositions.first); // TEST VALUES pv.setPlumbPos(GraphTools.yposRatio(yPositions.second, yPositions.first, 0.1f)); BitmapLoader.loadAndSetKey(pv, R.drawable.triangle, 180); pv.setBitmapTint(getCol(X.color_smb_icon)); consecutiveCloseIcons = 0; final Pair<Float, Float> yPositions = GraphTools.bestYPosition(bgReadings, treatment.timestamp, doMgdl, false, highMark, 27d + (18d * consecutiveCloseIcons)); pv.set(treatment.timestamp / FUZZER, yPositions.first);
BgReading after = null; final int chopResult = runBinarySearchIteratively(readings, timestamp, ascending); calculatedYpos = (float) (interpolateCalculatedValue(before, after, timestamp) * unitsScale);
static double interpolateCalculatedValue(BgReading first, BgReading second, long timestamp) { return interpolate(first.timestamp, first.getDg_mgdl(), second.timestamp, second.getDg_mgdl(), timestamp); } }