AndroidAPS/app/src/main/java/info/nightscout/androidaps/db/BgReading.java

124 lines
3.5 KiB
Java
Raw Normal View History

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;
2017-02-17 13:18:36 +01:00
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
2016-07-11 18:07:54 +02:00
import info.nightscout.utils.DecimalFormatter;
2016-06-07 21:48:17 +02:00
2016-07-21 15:10:42 +02:00
@DatabaseTable(tableName = DatabaseHelper.DATABASE_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
2016-12-27 20:41:28 +01:00
public String direction;
2016-06-07 21:48:17 +02:00
@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();
2017-03-18 23:35:43 +01:00
raw = sgv.getFiltered() != null ? sgv.getFiltered() : value;
2016-12-27 20:41:28 +01:00
direction = sgv.getDirection();
2016-06-07 21:48:17 +02:00
}
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
}
2016-12-27 20:41:28 +01:00
public String directionToSymbol() {
String symbol = "";
if (direction.compareTo("DoubleDown") == 0) {
symbol = "\u21ca";
} else if (direction.compareTo("SingleDown") == 0) {
symbol = "\u2193";
} else if (direction.compareTo("FortyFiveDown") == 0) {
symbol = "\u2198";
} else if (direction.compareTo("Flat") == 0) {
symbol = "\u2192";
} else if (direction.compareTo("FortyFiveUp") == 0) {
symbol = "\u2197";
} else if (direction.compareTo("SingleUp") == 0) {
symbol = "\u2191";
} else if (direction.compareTo("DoubleUp") == 0) {
symbol = "\u21c8";
} else if (isSlopeNameInvalid(direction)) {
symbol = "??";
}
return symbol;
}
public static boolean isSlopeNameInvalid(String direction) {
if (direction.compareTo("NOT_COMPUTABLE") == 0 ||
direction.compareTo("NOT COMPUTABLE") == 0 ||
direction.compareTo("OUT_OF_RANGE") == 0 ||
direction.compareTo("OUT OF RANGE") == 0 ||
direction.compareTo("NONE") == 0) {
return true;
} else {
return false;
}
}
2016-06-07 21:48:17 +02:00
@Override
public String toString() {
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 +
2016-12-27 20:41:28 +01:00
", direction=" + direction +
2016-06-07 21:48:17 +02:00
", 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-07-17 15:04:33 +02:00
2016-06-07 21:48:17 +02:00
}