Skip to content

Commit

Permalink
feat: Fix issue with not updating screens
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Jul 18, 2024
1 parent 7d4baf1 commit 754c21f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private const val LOG_KEY = "InMemoryCollector"
internal class InMemoryCarMetricsCollector : MetricsCollector {

private var metrics: SortedMap<Long, Metric> = TreeMap()
private val metricBuilder = MetricsBuilder()

override fun getMetrics(enabled: Boolean): List<Metric> = metrics.values.filter { it.enabled == enabled }

Expand All @@ -42,7 +43,7 @@ internal class InMemoryCarMetricsCollector : MetricsCollector {
if (Log.isLoggable(LOG_KEY, Log.DEBUG)) {
Log.d(LOG_KEY, "Rebuilding metrics configuration for: $enabled != ${metrics.keys}")
}
MetricsBuilder().buildFor(enabled).forEach {
metricBuilder.buildFor(enabled).forEach {
val key = it.source.command.pid.id

if (metrics.keys.indexOf(key) ==-1) {
Expand All @@ -69,6 +70,10 @@ internal class InMemoryCarMetricsCollector : MetricsCollector {
override fun append(input: ObdMetric?) {

input?.let { metric ->
if (!metrics.containsKey(metric.command.pid.id)) {
metrics[metric.command.pid.id] = metricBuilder.buildFor(metric)
}

metrics[metric.command.pid.id]?.let {
it.source = metric

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ import org.obd.metrics.command.obd.ObdCommand
import org.obd.metrics.pid.PidDefinitionRegistry

class MetricsBuilder {

fun buildFor(obdMetric: ObdMetric): Metric {
val histogramSupplier = dataLogger.getDiagnostics().histogram()
val histogram = histogramSupplier.findBy(obdMetric.command.pid)
return Metric
.newInstance(
min = histogram?.min ?: 0.0,
max = histogram?.max ?: 0.0,
mean = histogram?.mean ?: 0.0,
value = histogram?.latestValue ?: 0,
source = obdMetric
)
}

fun buildFor(ids: Set<Long>) = buildFor(ids, emptyMap())

fun buildFor(ids: Set<Long>, sortOrder: Map<Long, Int>?): MutableList<Metric> {
Expand All @@ -46,6 +60,7 @@ class MetricsBuilder {
return metrics
}


private fun buildMetrics(ids: Set<Long>): MutableList<Metric> {
val pidRegistry: PidDefinitionRegistry = dataLogger.getPidDefinitionRegistry()
val histogramSupplier = dataLogger.getDiagnostics().histogram()
Expand All @@ -55,13 +70,14 @@ class MetricsBuilder {
val histogram = histogramSupplier.findBy(pid)
Metric
.newInstance(
min = histogram?.min?:0.0,
max = histogram?.max?:0.0,
mean = histogram?.mean?:0.0,
value = histogram?.latestValue?:0,
source=ObdMetric.builder()
.command(ObdCommand(pid))
.value(histogram?.latestValue).build())
min = histogram?.min ?: 0.0,
max = histogram?.max ?: 0.0,
mean = histogram?.mean ?: 0.0,
value = histogram?.latestValue ?: 0,
source = ObdMetric.builder()
.command(ObdCommand(pid))
.value(histogram?.latestValue).build()
)
}
}.toMutableList()
}
Expand Down

0 comments on commit 754c21f

Please sign in to comment.