From 9e42f91848ba985bf67d084c854ae19245a89332 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Sep 2021 15:16:19 +0200 Subject: [PATCH 1/3] finish removing Objective8 --- .../objectives/ObjectivesPlugin.kt | 33 +++++++------------ .../interfaces/ConstraintsCheckerTest.kt | 10 ------ .../objectives/ObjectivesPluginTest.kt | 8 ----- .../general/automation/AutomationEvent.kt | 1 - .../automation/triggers/TriggerConnector.kt | 2 +- .../androidaps/interfaces/Constraints.kt | 1 - .../configBuilder/ConstraintChecker.kt | 13 -------- 7 files changed, 13 insertions(+), 55 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt index 74fa37901d..224a89a888 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPlugin.kt @@ -54,9 +54,8 @@ class ObjectivesPlugin @Inject constructor( const val MAXIOB_ZERO_CL_OBJECTIVE = 5 @Suppress("unused") const val MAXIOB_OBJECTIVE = 6 const val AUTOSENS_OBJECTIVE = 7 - const val AMA_OBJECTIVE = 8 - const val SMB_OBJECTIVE = 9 - const val AUTO_OBJECTIVE = 10 + const val SMB_OBJECTIVE = 8 + const val AUTO_OBJECTIVE = 9 } public override fun onStart() { @@ -64,9 +63,8 @@ class ObjectivesPlugin @Inject constructor( setupObjectives() } - override fun specialEnableCondition(): Boolean { - return activePlugin.activePump.pumpDescription.isTempBasalCapable - } + override fun specialEnableCondition(): Boolean = + activePlugin.activePump.pumpDescription.isTempBasalCapable private fun setupObjectives() { objectives.clear() @@ -80,6 +78,7 @@ class ObjectivesPlugin @Inject constructor( objectives.add(Objective7(injector)) objectives.add(Objective9(injector)) objectives.add(Objective10(injector)) + // edit companion object if you remove/add Objective } fun reset() { @@ -115,8 +114,6 @@ class ObjectivesPlugin @Inject constructor( sp.putLong("Objectives_" + "maxiob" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "autosens" + "_started", dateUtil.now()) sp.putLong("Objectives_" + "autosens" + "_accomplished", dateUtil.now()) - sp.putLong("Objectives_" + "ama" + "_started", dateUtil.now()) - sp.putLong("Objectives_" + "ama" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "smb" + "_started", dateUtil.now()) sp.putLong("Objectives_" + "smb" + "_accomplished", dateUtil.now()) sp.putLong("Objectives_" + "auto" + "_started", dateUtil.now()) @@ -142,49 +139,43 @@ class ObjectivesPlugin @Inject constructor( */ override fun isLoopInvocationAllowed(value: Constraint): Constraint { if (!objectives[FIRST_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), FIRST_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, FIRST_OBJECTIVE + 1), this) return value } override fun isLgsAllowed(value: Constraint): Constraint { if (!objectives[MAXBASAL_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXBASAL_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXBASAL_OBJECTIVE + 1), this) return value } override fun isClosedLoopAllowed(value: Constraint): Constraint { if (!objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), MAXIOB_ZERO_CL_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, MAXIOB_ZERO_CL_OBJECTIVE + 1), this) return value } override fun isAutosensModeEnabled(value: Constraint): Constraint { if (!objectives[AUTOSENS_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTOSENS_OBJECTIVE + 1), this) - return value - } - - override fun isAMAModeEnabled(value: Constraint): Constraint { - if (!objectives[AMA_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AMA_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTOSENS_OBJECTIVE + 1), this) return value } override fun isSMBModeEnabled(value: Constraint): Constraint { if (!objectives[SMB_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), SMB_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, SMB_OBJECTIVE + 1), this) return value } override fun applyMaxIOBConstraints(maxIob: Constraint): Constraint { if (objectives[MAXIOB_ZERO_CL_OBJECTIVE].isStarted && !objectives[MAXIOB_ZERO_CL_OBJECTIVE].isAccomplished) - maxIob.set(aapsLogger, 0.0, String.format(resourceHelper.gs(R.string.objectivenotfinished), MAXIOB_ZERO_CL_OBJECTIVE + 1), this) + maxIob.set(aapsLogger, 0.0, resourceHelper.gs(R.string.objectivenotfinished, MAXIOB_ZERO_CL_OBJECTIVE + 1), this) return maxIob } override fun isAutomationEnabled(value: Constraint): Constraint { if (!objectives[AUTO_OBJECTIVE].isStarted) - value.set(aapsLogger, false, String.format(resourceHelper.gs(R.string.objectivenotstarted), AUTO_OBJECTIVE + 1), this) + value.set(aapsLogger, false, resourceHelper.gs(R.string.objectivenotstarted, AUTO_OBJECTIVE + 1), this) return value } } diff --git a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt index 3235a110c0..874175a2be 100644 --- a/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/interfaces/ConstraintsCheckerTest.kt @@ -198,16 +198,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() { Assert.assertEquals(java.lang.Boolean.FALSE, c.value()) } - // Objectives - @Test - fun isAMAModeEnabledTest() { - objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0 - val c = constraintChecker.isAMAModeEnabled() - Assert.assertEquals(true, c.reasonList.size == 1) // Objectives - Assert.assertEquals(true, c.mostLimitedReasonList.size == 1) // Objectives - Assert.assertEquals(java.lang.Boolean.FALSE, c.value()) - } - // Safety @Test fun isAdvancedFilteringEnabledTest() { diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt index 270753e9a4..c08f4c9033 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt +++ b/app/src/test/java/info/nightscout/androidaps/plugins/constraints/objectives/ObjectivesPluginTest.kt @@ -74,14 +74,6 @@ class ObjectivesPluginTest : TestBase() { Assert.assertEquals(false, c.value()) } - @Test fun notStartedObjective9ShouldLimitAMAMode() { - objectivesPlugin.objectives[ObjectivesPlugin.AMA_OBJECTIVE].startedOn = 0 - var c = Constraint(true) - c = objectivesPlugin.isAMAModeEnabled(c) - Assert.assertEquals(true, c.getReasons(aapsLogger).contains("Objective 9 not started")) - Assert.assertEquals(false, c.value()) - } - @Test fun notStartedObjective10ShouldLimitSMBMode() { objectivesPlugin.objectives[ObjectivesPlugin.SMB_OBJECTIVE].startedOn = 0 var c = Constraint(true) diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt index f0e8bffd89..b02dfb0dd3 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/AutomationEvent.kt @@ -72,7 +72,6 @@ class AutomationEvent(private val injector: HasAndroidInjector) { readOnly = d.optBoolean("readOnly", false) autoRemove = d.optBoolean("autoRemove", false) trigger = TriggerDummy(injector).instantiate(JSONObject(d.getString("trigger"))) - ?: TriggerConnector(injector) val array = d.getJSONArray("actions") actions.clear() for (i in 0 until array.length()) { diff --git a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt index 105f91fe3b..91311a84da 100644 --- a/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt +++ b/automation/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerConnector.kt @@ -95,7 +95,7 @@ class TriggerConnector(injector: HasAndroidInjector) : Trigger(injector) { val array = d.getJSONArray("triggerList") list.clear() for (i in 0 until array.length()) { - instantiate(JSONObject(array.getString(i)))?.let { + instantiate(JSONObject(array.getString(i))).let { list.add(it) } } diff --git a/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt b/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt index 95a901f626..709b4c037b 100644 --- a/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt +++ b/core/src/main/java/info/nightscout/androidaps/interfaces/Constraints.kt @@ -17,7 +17,6 @@ interface Constraints { fun isClosedLoopAllowed(value: Constraint): Constraint = value fun isLgsAllowed(value: Constraint): Constraint = value fun isAutosensModeEnabled(value: Constraint): Constraint = value - fun isAMAModeEnabled(value: Constraint): Constraint = value fun isSMBModeEnabled(value: Constraint): Constraint = value fun isUAMEnabled(value: Constraint): Constraint = value fun isAdvancedFilteringEnabled(value: Constraint): Constraint = value diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt index 99476dff8f..718956c90b 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/configBuilder/ConstraintChecker.kt @@ -24,9 +24,6 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug fun isAutosensModeEnabled(): Constraint = isAutosensModeEnabled(Constraint(true)) - fun isAMAModeEnabled(): Constraint = - isAMAModeEnabled(Constraint(true)) - fun isSMBModeEnabled(): Constraint = isSMBModeEnabled(Constraint(true)) @@ -100,16 +97,6 @@ class ConstraintChecker @Inject constructor(private val activePlugin: ActivePlug return value } - override fun isAMAModeEnabled(value: Constraint): Constraint { - val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java) - for (p in constraintsPlugins) { - val constrain = p as Constraints - if (!p.isEnabled(PluginType.CONSTRAINTS)) continue - constrain.isAMAModeEnabled(value) - } - return value - } - override fun isSMBModeEnabled(value: Constraint): Constraint { val constraintsPlugins = activePlugin.getSpecificPluginsListByInterface(Constraints::class.java) for (p in constraintsPlugins) { From ce59c3afd4c9eb2bc2db97e9fa98f03e1b1a2b94 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Sep 2021 15:35:59 +0200 Subject: [PATCH 2/3] lints --- .../androidaps/plugins/general/actions/ActionsFragment.kt | 2 +- .../androidaps/plugins/general/overview/OverviewFragment.kt | 2 +- .../androidaps/plugins/profile/local/LocalProfileFragment.kt | 4 ++-- .../info/nightscout/androidaps/setupwizard/SWDefinition.kt | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt index ada8f9eab0..3688f1a55f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/actions/ActionsFragment.kt @@ -156,7 +156,7 @@ class ActionsFragment : DaggerFragment() { pbLevelLabel = view.findViewById(R.id.pb_level_label) profileSwitch?.setOnClickListener { - ProfileSwitchDialog().show(childFragmentManager, "Actions") + ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog") } tempTarget?.setOnClickListener { TempTargetDialog().show(childFragmentManager, "Actions") diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 981881ffa3..9da0246b70 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -377,7 +377,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } R.id.temp_target -> v.performClick() - R.id.active_profile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "Overview") }) } + R.id.active_profile -> activity?.let { activity -> protectionCheck.queryProtection(activity, ProtectionCheck.Protection.BOLUS, UIRunnable { ProfileSwitchDialog().show(childFragmentManager, "ProfileSwitchDialog") }) } } return false diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt index d166348713..989ef9dbdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/profile/local/LocalProfileFragment.kt @@ -212,7 +212,7 @@ class LocalProfileFragment : DaggerFragment() { binding.profileswitch.setOnClickListener { ProfileSwitchDialog() .also { it.arguments = Bundle().also { bundle -> bundle.putInt("profileIndex", localProfilePlugin.currentProfileIndex) } } - .show(childFragmentManager, "NewNSTreatmentDialog") + .show(childFragmentManager, "ProfileSwitchDialog") } binding.reset.setOnClickListener { @@ -259,7 +259,7 @@ class LocalProfileFragment : DaggerFragment() { updateGUI() } - fun updateGUI() { + private fun updateGUI() { if (_binding == null) return val isValid = localProfilePlugin.isValidEditState() val isEdited = localProfilePlugin.isEdited diff --git a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt index 8d640afc75..8b526b97bd 100644 --- a/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt +++ b/app/src/main/java/info/nightscout/androidaps/setupwizard/SWDefinition.kt @@ -267,7 +267,7 @@ class SWDefinition @Inject constructor( .label(R.string.profileswitch_ismissing)) .add(SWButton(injector) .text(R.string.doprofileswitch) - .action { ProfileSwitchDialog().show(activity.supportFragmentManager, "SetupWizard") }) + .action { ProfileSwitchDialog().show(activity.supportFragmentManager, "ProfileSwitchDialog") }) .validator { profileFunction.getProfile() != null } .visibility { profileFunction.getProfile() == null } private val screenPump = SWScreen(injector, R.string.configbuilder_pump) From d43393e2af7f6133b267e04967e8fc2b70149d16 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 21 Sep 2021 16:46:12 +0200 Subject: [PATCH 3/3] unify trend arrow AAPS <-> watch --- .../wearintegration/WatchUpdaterService.java | 42 ++------ .../database/entities/GlucoseValue.kt | 102 ++++++++++-------- 2 files changed, 64 insertions(+), 80 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java index d18d9e96bb..1e5c4364e6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/WatchUpdaterService.java @@ -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 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)); } } diff --git a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt index d7140a7900..d101681a7b 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/entities/GlucoseValue.kt @@ -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"),