Add log() overloads to UserEntryLogger that accept a timestamp

That way, if the user is already passing the timestamp as part of the
log() call's payload (in listValues), mismatches can be avoided by passing
the same timestamp as the timestamp arguments in the new overloads.
This commit is contained in:
Carlos Rafael Giani 2023-02-25 17:07:43 +01:00
parent 9145f3a96a
commit a6aa05b110
3 changed files with 18 additions and 6 deletions

View file

@ -9,6 +9,8 @@ import info.nightscout.interfaces.userEntry.ValueWithUnitMapper
interface UserEntryLogger { interface UserEntryLogger {
fun log(action: Action, source: Sources, note: String?, timestamp: Long, vararg listValues: ValueWithUnit?)
fun log(action: Action, source: Sources, note: String?, timestamp: Long, listValues: List<ValueWithUnit?>)
fun log(action: Action, source: Sources, note: String? = "", vararg listValues: ValueWithUnit?) fun log(action: Action, source: Sources, note: String? = "", vararg listValues: ValueWithUnit?)
fun log(action: Action, source: Sources, vararg listValues: ValueWithUnit?) fun log(action: Action, source: Sources, vararg listValues: ValueWithUnit?)
fun log(action: Action, source: Sources, note: String? = "", listValues: List<ValueWithUnit?> = listOf()) fun log(action: Action, source: Sources, note: String? = "", listValues: List<ValueWithUnit?> = listOf())

View file

@ -29,16 +29,14 @@ class UserEntryLoggerImpl @Inject constructor(
private val compositeDisposable = CompositeDisposable() private val compositeDisposable = CompositeDisposable()
override fun log(action: Action, source: Sources, note: String?, vararg listValues: ValueWithUnit?) = log(action, source, note, listValues.toList()) override fun log(action: Action, source: Sources, note: String?, timestamp: Long, vararg listValues: ValueWithUnit?) = log(action, source, note, timestamp, listValues.toList())
override fun log(action: Action, source: Sources, vararg listValues: ValueWithUnit?) = log(action, source, "", listValues.toList()) override fun log(action: Action, source: Sources, note: String?, timestamp: Long, listValues: List<ValueWithUnit?>) {
override fun log(action: Action, source: Sources, note: String?, listValues: List<ValueWithUnit?>) {
val filteredValues = listValues.toList().filterNotNull() val filteredValues = listValues.toList().filterNotNull()
log( log(
listOf( listOf(
UserEntry( UserEntry(
timestamp = dateUtil.now(), timestamp = timestamp,
action = action, action = action,
source = source, source = source,
note = note ?: "", note = note ?: "",
@ -48,6 +46,12 @@ class UserEntryLoggerImpl @Inject constructor(
) )
} }
override fun log(action: Action, source: Sources, note: String?, vararg listValues: ValueWithUnit?) = log(action, source, note, listValues.toList())
override fun log(action: Action, source: Sources, vararg listValues: ValueWithUnit?) = log(action, source, "", listValues.toList())
override fun log(action: Action, source: Sources, note: String?, listValues: List<ValueWithUnit?>) = log(action, source, note, dateUtil.now(), listValues)
override fun log(entries: List<UserEntry>) { override fun log(entries: List<UserEntry>) {
compositeDisposable += repository.runTransactionForResult(UserEntryTransaction(entries)) compositeDisposable += repository.runTransactionForResult(UserEntryTransaction(entries))
.subscribeOn(aapsSchedulers.io) .subscribeOn(aapsSchedulers.io)

View file

@ -273,7 +273,13 @@ class PumpSyncImplementation @Inject constructor(
pumpSerial = pumpSerial pumpSerial = pumpSerial
) )
) )
uel.log(UserEntry.Action.CAREPORTAL, pumpType.source.toDbSource(), note, ValueWithUnit.Timestamp(timestamp), ValueWithUnit.TherapyEventType(type.toDBbEventType())) uel.log(
action = UserEntry.Action.CAREPORTAL,
source = pumpType.source.toDbSource(),
note = note,
timestamp = timestamp,
ValueWithUnit.Timestamp(timestamp), ValueWithUnit.TherapyEventType(type.toDBbEventType())
)
repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(therapyEvent)) repository.runTransactionForResult(InsertIfNewByTimestampTherapyEventTransaction(therapyEvent))
.doOnError { .doOnError {
aapsLogger.error(LTag.DATABASE, "Error while saving TherapyEvent", it) aapsLogger.error(LTag.DATABASE, "Error while saving TherapyEvent", it)