2017-01-13 22:36:47 +01:00
|
|
|
package info.nightscout.androidaps.db;
|
|
|
|
|
|
|
|
import com.j256.ormlite.field.DatabaseField;
|
|
|
|
import com.j256.ormlite.table.DatabaseTable;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
2017-01-13 23:43:17 +01:00
|
|
|
import info.nightscout.androidaps.Constants;
|
2017-01-13 22:36:47 +01:00
|
|
|
import info.nightscout.androidaps.MainApp;
|
2017-01-13 23:43:17 +01:00
|
|
|
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
|
|
|
|
import info.nightscout.utils.DecimalFormatter;
|
2017-01-13 22:36:47 +01:00
|
|
|
|
|
|
|
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPTARGETS)
|
|
|
|
public class TempTarget {
|
|
|
|
private static Logger log = LoggerFactory.getLogger(TempTarget.class);
|
|
|
|
|
|
|
|
public long getTimeIndex() {
|
|
|
|
return timeStart.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTimeIndex(long timeIndex) {
|
|
|
|
this.timeIndex = timeIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
@DatabaseField(id = true, useGetSet = true)
|
|
|
|
public long timeIndex;
|
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public Date timeStart;
|
|
|
|
|
|
|
|
@DatabaseField
|
2017-01-13 23:43:17 +01:00
|
|
|
public double low; // in mgdl
|
2017-01-13 22:36:47 +01:00
|
|
|
|
|
|
|
@DatabaseField
|
2017-01-13 23:43:17 +01:00
|
|
|
public double high; // in mgdl
|
2017-01-13 22:36:47 +01:00
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public String reason;
|
|
|
|
|
|
|
|
@DatabaseField
|
|
|
|
public int duration; // in minutes
|
|
|
|
|
2017-01-14 00:37:35 +01:00
|
|
|
@DatabaseField
|
|
|
|
public String _id; // NS _id
|
|
|
|
|
2017-01-13 22:36:47 +01:00
|
|
|
public Date getPlannedTimeEnd() {
|
|
|
|
return new Date(timeStart.getTime() + 60 * 1_000 * duration);
|
|
|
|
}
|
|
|
|
|
2017-01-13 23:43:17 +01:00
|
|
|
public String lowValueToUnitsToString(String units) {
|
|
|
|
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(low);
|
|
|
|
else return DecimalFormatter.to1Decimal(low * Constants.MGDL_TO_MMOLL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String highValueToUnitsToString(String units) {
|
|
|
|
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(high);
|
|
|
|
else return DecimalFormatter.to1Decimal(low * Constants.MGDL_TO_MMOLL);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isInProgress() {
|
|
|
|
return ((TempTargetRangePlugin) MainApp.getSpecificPlugin(TempTargetRangePlugin.class)).getTempTargetInProgress(new Date().getTime()) == this;
|
|
|
|
}
|
|
|
|
|
2017-01-13 22:36:47 +01:00
|
|
|
public String log() {
|
|
|
|
return "TempTarget{" +
|
|
|
|
"timeIndex=" + timeIndex +
|
|
|
|
", timeStart=" + timeStart +
|
|
|
|
", duration=" + duration +
|
|
|
|
", reason=" + reason +
|
|
|
|
", low=" + low +
|
|
|
|
", high=" + high +
|
|
|
|
'}';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|