Skip to content

Commit

Permalink
Overview: show adjusted target in NSC mode
Browse files Browse the repository at this point in the history
  • Loading branch information
MilosKozak committed Oct 30, 2023
1 parent 238a622 commit aa2ae1b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package app.aaps.core.interfaces.nsclient

import android.text.Spanned
import app.aaps.core.interfaces.aps.APSResult
import dagger.android.HasAndroidInjector
import org.json.JSONObject

interface ProcessedDeviceStatusData {
Expand Down Expand Up @@ -61,7 +60,7 @@ interface ProcessedDeviceStatusData {
val extendedOpenApsStatus: Spanned
val openApsStatus: Spanned
val openApsTimestamp: Long
fun getAPSResult(injector: HasAndroidInjector): APSResult
fun getAPSResult(): APSResult
val uploaderStatus: String
val uploaderStatusSpanned: Spanned
val extendedUploaderStatus: Spanned
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,9 +963,12 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
profileUtil.toTargetRangeString(tempTarget.lowTarget, tempTarget.highTarget, GlucoseUnit.MGDL, units) + " " + dateUtil.untilString(tempTarget.end, rh)
)
} else {
// If the target is not the same as set in the profile then oref has overridden it
profileFunction.getProfile()?.let { profile ->
val targetUsed = loop.lastRun?.constraintsProcessed?.targetBG ?: 0.0
// If the target is not the same as set in the profile then oref has overridden it
val targetUsed =
if (config.APS) loop.lastRun?.constraintsProcessed?.targetBG ?: 0.0
else if (config.NSCLIENT) JsonHelper.safeGetDouble(processedDeviceStatusData.getAPSResult().json, "targetBg")
else 0.0

if (targetUsed != 0.0 && abs(profile.getTargetMgdl() - targetUsed) > 0.01) {
aapsLogger.debug("Adjusted target. Profile: ${profile.getTargetMgdl()} APS: $targetUsed")
Expand Down Expand Up @@ -1111,7 +1114,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
val isfMgdl = profile?.getIsfMgdl()
val variableSens =
if (config.APS && request is VariableSensitivityResult) request.variableSens ?: 0.0
else if (config.NSCLIENT) JsonHelper.safeGetDouble(processedDeviceStatusData.getAPSResult(injector).json, "variable_sens")
else if (config.NSCLIENT) JsonHelper.safeGetDouble(processedDeviceStatusData.getAPSResult().json, "variable_sens")
else 0.0

if (variableSens != isfMgdl && variableSens != 0.0 && isfMgdl != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class ProcessedDeviceStatusDataImpl @Inject constructor(
override val openApsTimestamp: Long
get() = if (openAPSData.clockSuggested != 0L) openAPSData.clockSuggested else -1

override fun getAPSResult(injector: HasAndroidInjector): APSResult =
override fun getAPSResult(): APSResult =
instantiator.provideAPSResultObject().also {
it.json = openAPSData.suggested
it.date = openAPSData.clockSuggested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PreparePredictionsWorker(
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as PreparePredictionsData?
?: return Result.failure(workDataOf("Error" to "missing input data"))

val apsResult = if (config.APS) loop.lastRun?.constraintsProcessed else processedDeviceStatusData.getAPSResult(injector)
val apsResult = if (config.APS) loop.lastRun?.constraintsProcessed else processedDeviceStatusData.getAPSResult()
val predictionsAvailable = if (config.APS) loop.lastRun?.request?.hasPredictions == true else config.NSCLIENT
val menuChartSettings = overviewMenus.setting
// align to hours
Expand Down

0 comments on commit aa2ae1b

Please sign in to comment.