move loadbgdata
This commit is contained in:
parent
a1c073a74c
commit
12514c1130
|
@ -5,13 +5,16 @@ import androidx.work.Worker
|
|||
import androidx.work.WorkerParameters
|
||||
import androidx.work.workDataOf
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.core.aps.loadBgData
|
||||
import info.nightscout.core.utils.receivers.DataWorkerStorage
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.interfaces.aps.AutosensDataStore
|
||||
import info.nightscout.interfaces.iob.IobCobCalculator
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.EventBucketedDataCreated
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.shared.utils.T
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoadBgDataWorker(
|
||||
|
@ -34,6 +37,22 @@ class LoadBgDataWorker(
|
|||
val end: Long
|
||||
)
|
||||
|
||||
|
||||
private fun AutosensDataStore.loadBgData(to: Long, repository: AppRepository, aapsLogger: AAPSLogger, dateUtil: DateUtil, rxBus: RxBus) {
|
||||
synchronized(dataLock) {
|
||||
val start = to - T.hours((24 + 10 /* max dia */).toLong()).msecs()
|
||||
// there can be some readings with time in close future (caused by wrong time setting on sensor)
|
||||
// so add 2 minutes
|
||||
bgReadings = repository
|
||||
.compatGetBgReadingsDataFromTime(start, to + T.mins(2).msecs(), false)
|
||||
.blockingGet()
|
||||
.filter { it.value >= 39 }
|
||||
aapsLogger.debug(LTag.AUTOSENS) { "BG data loaded. Size: ${bgReadings.size} Start date: ${dateUtil.dateAndTimeString(start)} End date: ${dateUtil.dateAndTimeString(to)}" }
|
||||
createBucketedData(aapsLogger, dateUtil)
|
||||
rxBus.send(EventBucketedDataCreated())
|
||||
}
|
||||
}
|
||||
|
||||
override fun doWork(): Result {
|
||||
|
||||
val data = dataWorkerStorage.pickupObject(inputData.getLong(DataWorkerStorage.STORE_KEY, -1)) as LoadBgData?
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package info.nightscout.core.aps
|
||||
|
||||
import info.nightscout.database.impl.AppRepository
|
||||
import info.nightscout.interfaces.aps.AutosensDataStore
|
||||
import info.nightscout.rx.bus.RxBus
|
||||
import info.nightscout.rx.events.EventBucketedDataCreated
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.shared.utils.DateUtil
|
||||
import info.nightscout.shared.utils.T
|
||||
|
||||
fun AutosensDataStore.loadBgData(to: Long, repository: AppRepository, aapsLogger: AAPSLogger, dateUtil: DateUtil, rxBus: RxBus) {
|
||||
synchronized(dataLock) {
|
||||
val start = to - T.hours((24 + 10 /* max dia */).toLong()).msecs()
|
||||
// there can be some readings with time in close future (caused by wrong time setting on sensor)
|
||||
// so add 2 minutes
|
||||
bgReadings = repository
|
||||
.compatGetBgReadingsDataFromTime(start, to + T.mins(2).msecs(), false)
|
||||
.blockingGet()
|
||||
.filter { it.value >= 39 }
|
||||
aapsLogger.debug(LTag.AUTOSENS) { "BG data loaded. Size: ${bgReadings.size} Start date: ${dateUtil.dateAndTimeString(start)} End date: ${dateUtil.dateAndTimeString(to)}" }
|
||||
createBucketedData(aapsLogger, dateUtil)
|
||||
rxBus.send(EventBucketedDataCreated())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue