2016-06-07 21:48:17 +02:00
|
|
|
package info.nightscout.androidaps.db;
|
|
|
|
|
|
|
|
import com.j256.ormlite.field.DatabaseField;
|
|
|
|
import com.j256.ormlite.table.DatabaseTable;
|
2016-06-09 00:01:28 +02:00
|
|
|
import com.jjoe64.graphview.series.DataPointInterface;
|
2016-06-07 21:48:17 +02:00
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import info.nightscout.androidaps.Constants;
|
|
|
|
import info.nightscout.client.data.NSSgv;
|
2016-07-11 18:07:54 +02:00
|
|
|
import info.nightscout.utils.DecimalFormatter;
|
2016-06-07 21:48:17 +02:00
|
|
|
|
|
|
|
@DatabaseTable(tableName = "BgReadings")
|
2016-06-09 00:01:28 +02:00
|
|
|
public class BgReading implements DataPointInterface {
|
2016-06-07 21:48:17 +02:00
|
|
|
private static Logger log = LoggerFactory.getLogger(BgReading.class);
|
|
|
|
|
|
|
|
public long getTimeIndex() {
|
2016-06-24 17:30:25 +02:00
|
|
|
return timeIndex;
|
2016-06-07 21:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setTimeIndex(long timeIndex) {
|
2016-06-24 17:30:25 +02:00
|
|
|
this.timeIndex = timeIndex;
|
2016-06-07 21:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@DatabaseField(id = true, useGetSet = true)
|
|
|
|
public long timeIndex;
|
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public double value;
|
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public double slope;
|
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public double raw;
|
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public int battery_level;
|
|
|
|
|
2016-06-09 00:01:28 +02:00
|
|
|
public static String units = Constants.MGDL;
|
|
|
|
|
2016-06-07 21:48:17 +02:00
|
|
|
public BgReading() {}
|
|
|
|
|
|
|
|
public BgReading(NSSgv sgv) {
|
2016-06-24 17:30:25 +02:00
|
|
|
timeIndex = sgv.getMills();
|
2016-06-07 21:48:17 +02:00
|
|
|
value = sgv.getMgdl();
|
|
|
|
raw = sgv.getFiltered();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Double valueToUnits(String units) {
|
|
|
|
if (units.equals(Constants.MGDL))
|
|
|
|
return value;
|
|
|
|
else
|
|
|
|
return value * Constants.MGDL_TO_MMOLL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String valueToUnitsToString(String units) {
|
2016-07-11 18:07:54 +02:00
|
|
|
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(value);
|
2016-07-11 18:42:14 +02:00
|
|
|
else return DecimalFormatter.to1Decimal(value * Constants.MGDL_TO_MMOLL);
|
2016-06-07 21:48:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
2016-06-07 23:36:22 +02:00
|
|
|
return "BgReading{" +
|
2016-06-07 21:48:17 +02:00
|
|
|
"timeIndex=" + timeIndex +
|
2016-06-24 17:30:25 +02:00
|
|
|
", date=" + new Date(timeIndex) +
|
2016-06-07 21:48:17 +02:00
|
|
|
", value=" + value +
|
|
|
|
", slope=" + slope +
|
|
|
|
", raw=" + raw +
|
|
|
|
", battery_level=" + battery_level +
|
|
|
|
'}';
|
|
|
|
}
|
2016-06-09 00:01:28 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getX() {
|
2016-06-24 17:30:25 +02:00
|
|
|
return timeIndex;
|
2016-06-09 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getY() {
|
|
|
|
return valueToUnits(units);
|
|
|
|
}
|
2016-06-07 21:48:17 +02:00
|
|
|
}
|