Skip to content

Commit

Permalink
fix: Rework calculation of 60-140 and 100-200
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Nov 4, 2024
1 parent 4b199dd commit 00614d4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult
}

override fun onRunning(vehicleCapabilities: VehicleCapabilities?) {
reset()
reset0()
}

override fun postValue(obdMetric: ObdMetric) {
Expand All @@ -80,7 +80,7 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult
} else if (obdMetric.isVehicleSpeed()) {

if (obdMetric.value.toInt() == SPEED_0_KM_H) {
reset()
reset0()

if (Log.isLoggable(LOG_KEY, Log.VERBOSE)) {
Log.v(LOG_KEY, "Ready to measure, current speed: ${obdMetric.value}")
Expand All @@ -93,9 +93,20 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult
registry.readyToRace(false)
}


if (isGivenSpeedReached(obdMetric, SPEED_60_KM_H - 5) && obdMetric.value.toInt() < SPEED_60_KM_H) {
Log.i(LOG_KEY, "Reset 60-140 measurement at speed: ${obdMetric.value.toInt()}")
result60_140 = null
_60ts = null
}

if (isGivenSpeedReached(obdMetric, SPEED_60_KM_H)) {
if (result0_60 == null) {
if (_60ts == null) {
_60ts = obdMetric.timestamp
Log.i(LOG_KEY, "Setting 60km/h ts: ${obdMetric.timestamp}")
}

if (result0_60 == null) {

_0ts?.let { _0_ts ->
result0_60 = obdMetric.timestamp - _0_ts
Expand All @@ -107,9 +118,21 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult
}



if (isGivenSpeedReached(obdMetric, SPEED_100_KM_H - 5) && obdMetric.value.toInt() < SPEED_100_KM_H) {
Log.i(LOG_KEY, "Reset 100-200 measurement at speed: ${obdMetric.value.toInt()}")
result100_200 = null
_100ts = null
}

if (isGivenSpeedReached(obdMetric, SPEED_100_KM_H)) {
if (result0_100 == null) {
if (_100ts == null) {
_100ts = obdMetric.timestamp
Log.i(LOG_KEY, "Setting 100km/h ts: ${obdMetric.timestamp}")
}

if (result0_100 == null) {

_0ts?.let { _0_ts ->
result0_100 = obdMetric.timestamp - _0_ts
registry.update0100(DragRacingMetric(time = result0_100!!,speed = obdMetric.value.toInt(),
Expand Down Expand Up @@ -145,15 +168,15 @@ internal class DragRacingMetricsProcessor(private val registry: DragRacingResult
result60_140 = obdMetric.timestamp - _60_ts
registry.update60140(DragRacingMetric(time = result60_140!!,speed = obdMetric.value.toInt(),
ambientTemp = ambientTemp, atmPressure = atmPressure))
Log.i(LOG_KEY, "Current speed: ${obdMetric.value}. Result: 60-140 ${result60_140}ms")
Log.i(LOG_KEY, "Current speed: ${obdMetric.value}, _60ts=${_60ts}, _140ts=${obdMetric.timestamp}, Result: 60-140 ${result60_140}ms")
}
}
}
}

private fun isGivenSpeedReached(obdMetric: ObdMetric, givenSpeed: Int): Boolean = min(obdMetric.value.toInt(), givenSpeed) == givenSpeed

private fun reset() {
private fun reset0() {
_0ts = null
_100ts = null
_60ts = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ internal class InMemoryDragRacingRegistry : DragRacingResultRegistry {
Prefs.getString(id.last, null)?.let {
entry.last = it.toLong()
}
Log.e("EEEEEEE","Read entry ${entry}")
}

private fun updateEntry(entry: DragRacingEntry, id: PreferencesIds, metric: DragRacingMetric) {
Expand Down

0 comments on commit 00614d4

Please sign in to comment.