unify trend arrow AAPS <-> watch

This commit is contained in:
Milos Kozak 2021-09-21 16:46:12 +02:00
parent ce59c3afd4
commit d43393e2af
2 changed files with 64 additions and 80 deletions

View file

@ -29,12 +29,9 @@ import java.util.stream.Collectors;
import javax.inject.Inject;
import dagger.android.AndroidInjection;
import info.nightscout.androidaps.interfaces.Config;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.interfaces.GlucoseUnit;
import info.nightscout.androidaps.interfaces.Profile;
import info.nightscout.androidaps.database.AppRepository;
import info.nightscout.androidaps.database.entities.Bolus;
import info.nightscout.androidaps.database.entities.GlucoseValue;
@ -42,8 +39,11 @@ import info.nightscout.androidaps.database.entities.TemporaryBasal;
import info.nightscout.androidaps.extensions.GlucoseValueExtensionKt;
import info.nightscout.androidaps.extensions.TemporaryBasalExtensionKt;
import info.nightscout.androidaps.interfaces.ActivePlugin;
import info.nightscout.androidaps.interfaces.Config;
import info.nightscout.androidaps.interfaces.GlucoseUnit;
import info.nightscout.androidaps.interfaces.IobCobCalculator;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.Profile;
import info.nightscout.androidaps.interfaces.ProfileFunction;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
@ -59,7 +59,7 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProv
import info.nightscout.androidaps.receivers.ReceiverStatusStore;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.DefaultValueHelper;
import info.nightscout.androidaps.utils.ToastUtils;
import info.nightscout.androidaps.utils.TrendCalculator;
import info.nightscout.androidaps.utils.resources.ResourceHelper;
import info.nightscout.androidaps.utils.sharedPreferences.SP;
@ -79,6 +79,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
@Inject public AppRepository repository;
@Inject ReceiverStatusStore receiverStatusStore;
@Inject Config config;
@Inject public TrendCalculator trendCalculator;
public static final String ACTION_RESEND = WatchUpdaterService.class.getName().concat(".Resend");
public static final String ACTION_OPEN_SETTINGS = WatchUpdaterService.class.getName().concat(".OpenSettings");
@ -322,7 +323,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
dataMap.putString("delta", "--");
dataMap.putString("avgDelta", "--");
} else {
dataMap.putString("slopeArrow", slopeArrow(glucoseStatus.getDelta()));
dataMap.putString("slopeArrow", trendCalculator.getTrendArrow(lastBG).getSymbol());
dataMap.putString("delta", deltastring(glucoseStatus.getDelta(), glucoseStatus.getDelta() * Constants.MGDL_TO_MMOLL, units));
dataMap.putString("avgDelta", deltastring(glucoseStatus.getShortAvgDelta(), glucoseStatus.getShortAvgDelta() * Constants.MGDL_TO_MMOLL, units));
}
@ -358,25 +359,6 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
return deltastring;
}
private String slopeArrow(double delta) {
if (delta <= (-3.5 * 5)) {
return "\u21ca";
} else if (delta <= (-2 * 5)) {
return "\u2193";
} else if (delta <= (-1 * 5)) {
return "\u2198";
} else if (delta <= (1 * 5)) {
return "\u2192";
} else if (delta <= (2 * 5)) {
return "\u2197";
} else if (delta <= (3.5 * 5)) {
return "\u2191";
} else {
return "\u21c8";
}
}
private void resendData() {
if (googleApiClient != null && !googleApiClient.isConnected() && !googleApiClient.isConnecting()) {
googleApiConnect();
@ -391,16 +373,10 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
if (!graph_bgs.isEmpty()) {
DataMap entries = dataMapSingleBG(last_bg, glucoseStatus);
if (entries == null) {
ToastUtils.showToastInUiThread(this, resourceHelper.gs(R.string.noprofile));
return;
}
final ArrayList<DataMap> dataMaps = new ArrayList<>(graph_bgs.size());
for (GlucoseValue bg : graph_bgs) {
DataMap dataMap = dataMapSingleBG(bg, glucoseStatus);
if (dataMap != null) {
dataMaps.add(dataMap);
}
dataMaps.add(dataMap);
}
entries.putDataMapArrayList("entries", dataMaps);
(new SendToDataLayerThread(WEARABLE_DATA_PATH, googleApiClient)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, entries);
@ -505,7 +481,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
tb2 = iobCobCalculator.getTempBasalIncludingConvertedExtended(now); //use "now" to express current situation
if (tb2 == null) {
//express the cancelled temp by painting it down one minute early
temps.add(tempDatamap(tb_start, tb_before, now - 1 * 60 * 1000, endBasalValue, tb_amount));
temps.add(tempDatamap(tb_start, tb_before, now - 60 * 1000, endBasalValue, tb_amount));
} else {
//express currently running temp by painting it a bit into the future
Profile profileNow = profileFunction.getProfile(now);
@ -523,7 +499,7 @@ public class WatchUpdaterService extends WearableListenerService implements Goog
//onset at the end
Profile profileTB = profileFunction.getProfile(runningTime);
double currentAmount = TemporaryBasalExtensionKt.convertedToAbsolute(tb2, runningTime, profileTB);
temps.add(tempDatamap(now - 1 * 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
temps.add(tempDatamap(now - 60 * 1000, endBasalValue, runningTime + 5 * 60 * 1000, currentAmount, currentAmount));
}
}

View file

@ -1,25 +1,31 @@
package info.nightscout.androidaps.database.entities
import com.google.gson.annotations.SerializedName
import androidx.room.*
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.Index
import androidx.room.PrimaryKey
import info.nightscout.androidaps.database.TABLE_GLUCOSE_VALUES
import info.nightscout.androidaps.database.embedments.InterfaceIDs
import info.nightscout.androidaps.database.interfaces.DBEntryWithTime
import info.nightscout.androidaps.database.interfaces.TraceableDBEntry
import java.util.TimeZone
import java.util.*
@Entity(tableName = TABLE_GLUCOSE_VALUES,
@Entity(
tableName = TABLE_GLUCOSE_VALUES,
foreignKeys = [ForeignKey(
entity = GlucoseValue::class,
parentColumns = ["id"],
childColumns = ["referenceId"])],
childColumns = ["referenceId"]
)],
indices = [
Index("id"),
Index("nightscoutId"),
Index("sourceSensor"),
Index("referenceId"),
Index("timestamp")
])
]
)
data class GlucoseValue(
@PrimaryKey(autoGenerate = true)
override var id: Long = 0,
@ -51,53 +57,55 @@ data class GlucoseValue(
fun isRecordDeleted(other: GlucoseValue): Boolean =
isValid && !other.isValid
enum class TrendArrow (val text:String, val symbol:String){
@SerializedName("NONE") NONE("NONE", "??"),
@SerializedName("TripleUp")TRIPLE_UP("TripleUp", "X"),
@SerializedName("DoubleUp")DOUBLE_UP("DoubleUp", "\u21c8"),
@SerializedName("SingleUp")SINGLE_UP("SingleUp", "\u2191"),
@SerializedName("FortyFiveUp")FORTY_FIVE_UP("FortyFiveUp", "\u2197"),
@SerializedName("Flat")FLAT("Flat", "\u2192"),
@SerializedName("FortyFiveDown")FORTY_FIVE_DOWN("FortyFiveDown", "\u2198"),
@SerializedName("SingleDown")SINGLE_DOWN("SingleDown", "\u2193"),
@SerializedName("DoubleDown")DOUBLE_DOWN("DoubleDown", "\u21ca"),
@SerializedName("TripleDown")TRIPLE_DOWN("TripleDown", "X")
enum class TrendArrow(val text: String, val symbol: String) {
NONE("NONE", "??"),
TRIPLE_UP("TripleUp", "X"),
DOUBLE_UP("DoubleUp", "\u21c8"),
SINGLE_UP("SingleUp", "\u2191"),
FORTY_FIVE_UP("FortyFiveUp", "\u2197"),
FLAT("Flat", "\u2192"),
FORTY_FIVE_DOWN("FortyFiveDown", "\u2198"),
SINGLE_DOWN("SingleDown", "\u2193"),
DOUBLE_DOWN("DoubleDown", "\u21ca"),
TRIPLE_DOWN("TripleDown", "X")
;
companion object {
fun fromString(direction : String?) = values().firstOrNull {it.text == direction} ?: NONE
fun fromString(direction: String?) =
values().firstOrNull { it.text == direction } ?: NONE
}
}
enum class SourceSensor(val text : String) {
@SerializedName("AndroidAPS-Dexcom") DEXCOM_NATIVE_UNKNOWN("AndroidAPS-Dexcom"),
@SerializedName("AndroidAPS-DexcomG6") DEXCOM_G6_NATIVE("AndroidAPS-DexcomG6"),
@SerializedName("AndroidAPS-DexcomG5") DEXCOM_G5_NATIVE("AndroidAPS-DexcomG5"),
@SerializedName("Bluetooth Wixel") DEXCOM_G4_WIXEL("Bluetooth Wixel"),
@SerializedName("xBridge Wixel") DEXCOM_G4_XBRIDGE("xBridge Wixel"),
@SerializedName("G4 Share Receiver") DEXCOM_G4_NATIVE("G4 Share Receiver"),
@SerializedName("Medtrum A6") MEDTRUM_A6("Medtrum A6"),
@SerializedName("Network G4") DEXCOM_G4_NET("Network G4"),
@SerializedName("Network G4 and xBridge") DEXCOM_G4_NET_XBRIDGE("Network G4 and xBridge"),
@SerializedName("Network G4 and Classic xDrip") DEXCOM_G4_NET_CLASSIC("Network G4 and Classic xDrip"),
@SerializedName("DexcomG5") DEXCOM_G5_XDRIP("DexcomG5"),
@SerializedName("G6 Native") DEXCOM_G6_NATIVE_XDRIP("G6 Native"),
@SerializedName("G5 Native") DEXCOM_G5_NATIVE_XDRIP("G5 Native"),
@SerializedName("G6 Native / G5 Native") DEXCOM_G6_G5_NATIVE_XDRIP("G6 Native / G5 Native"),
@SerializedName("Network libre") LIBRE_1_NET("Network libre"),
@SerializedName("BlueReader") LIBRE_1_BLUE("BlueReader"),
@SerializedName("Transmiter PL") LIBRE_1_PL("Transmiter PL"),
@SerializedName("Blucon") LIBRE_1_BLUCON("Blucon"),
@SerializedName("Tomato") LIBRE_1_TOMATO("Tomato"),
@SerializedName("Rfduino") LIBRE_1_RF("Rfduino"),
@SerializedName("LimiTTer") LIBRE_1_LIMITTER("LimiTTer"),
@SerializedName("Glimp") GLIMP("Glimp"),
@SerializedName("Libre2") LIBRE_2_NATIVE("Libre2"),
@SerializedName("Poctech") POCTECH_NATIVE("Poctech"),
@SerializedName("MM600Series") MM_600_SERIES("MM600Series"),
@SerializedName("Eversense") EVERSENSE("Eversense"),
@SerializedName("Random") RANDOM("Random"),
@SerializedName("Unknown") UNKNOWN("Unknown"),
enum class SourceSensor(val text: String) {
DEXCOM_NATIVE_UNKNOWN("AndroidAPS-Dexcom"),
DEXCOM_G6_NATIVE("AndroidAPS-DexcomG6"),
DEXCOM_G5_NATIVE("AndroidAPS-DexcomG5"),
DEXCOM_G4_WIXEL("Bluetooth Wixel"),
DEXCOM_G4_XBRIDGE("xBridge Wixel"),
DEXCOM_G4_NATIVE("G4 Share Receiver"),
MEDTRUM_A6("Medtrum A6"),
DEXCOM_G4_NET("Network G4"),
DEXCOM_G4_NET_XBRIDGE("Network G4 and xBridge"),
DEXCOM_G4_NET_CLASSIC("Network G4 and Classic xDrip"),
DEXCOM_G5_XDRIP("DexcomG5"),
DEXCOM_G6_NATIVE_XDRIP("G6 Native"),
DEXCOM_G5_NATIVE_XDRIP("G5 Native"),
DEXCOM_G6_G5_NATIVE_XDRIP("G6 Native / G5 Native"),
LIBRE_1_NET("Network libre"),
LIBRE_1_BLUE("BlueReader"),
LIBRE_1_PL("Transmiter PL"),
LIBRE_1_BLUCON("Blucon"),
LIBRE_1_TOMATO("Tomato"),
LIBRE_1_RF("Rfduino"),
LIBRE_1_LIMITTER("LimiTTer"),
GLIMP("Glimp"),
LIBRE_2_NATIVE("Libre2"),
POCTECH_NATIVE("Poctech"),
MM_600_SERIES("MM600Series"),
EVERSENSE("Eversense"),
RANDOM("Random"),
UNKNOWN("Unknown"),
IOB_PREDICTION("IOBPrediction"),
A_COB_PREDICTION("aCOBPrediction"),