mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
fix(detekt): reduce cyclomatic complexity in saveEnvironmentMetricsCSV
Replace hardcoded one-wire temperature indices (0-7) with a loop over ONE_WIRE_SENSOR_COUNT constant to fix CyclomaticComplexMethod and MagicNumber detekt violations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
e3a78f1afe
commit
0a37635a40
1 changed files with 9 additions and 7 deletions
|
|
@ -383,27 +383,25 @@ open class MetricsViewModel(
|
|||
}
|
||||
|
||||
fun saveEnvironmentMetricsCSV(uri: MeshtasticUri, data: List<Telemetry>) {
|
||||
val oneWireHeaders = (1..ONE_WIRE_SENSOR_COUNT).joinToString(",") { "\"oneWireTemp$it\"" }
|
||||
exportCsv(
|
||||
uri = uri,
|
||||
header =
|
||||
"\"date\",\"time\",\"temperature\",\"relativeHumidity\",\"barometricPressure\"," +
|
||||
"\"gasResistance\",\"iaq\",\"windSpeed\",\"windDirection\",\"soilTemperature\"," +
|
||||
"\"soilMoisture\",\"oneWireTemp1\",\"oneWireTemp2\",\"oneWireTemp3\",\"oneWireTemp4\"," +
|
||||
"\"oneWireTemp5\",\"oneWireTemp6\",\"oneWireTemp7\",\"oneWireTemp8\"\n",
|
||||
"\"soilMoisture\",$oneWireHeaders\n",
|
||||
rows = data,
|
||||
epochSeconds = { it.time.toLong() },
|
||||
) { t ->
|
||||
val em = t.environment_metrics
|
||||
val owt = em?.one_wire_temperature ?: emptyList()
|
||||
val oneWireValues =
|
||||
(0 until ONE_WIRE_SENSOR_COUNT).joinToString(",") { i -> "\"${owt.getOrNull(i) ?: ""}\"" }
|
||||
"\"${em?.temperature ?: ""}\",\"${em?.relative_humidity ?: ""}\"," +
|
||||
"\"${em?.barometric_pressure ?: ""}\",\"${em?.gas_resistance ?: ""}\"," +
|
||||
"\"${em?.iaq ?: ""}\",\"${em?.wind_speed ?: ""}\"," +
|
||||
"\"${em?.wind_direction ?: ""}\",\"${em?.soil_temperature ?: ""}\"," +
|
||||
"\"${em?.soil_moisture ?: ""}\"," +
|
||||
"\"${owt.getOrNull(0) ?: ""}\",\"${owt.getOrNull(1) ?: ""}\"," +
|
||||
"\"${owt.getOrNull(2) ?: ""}\",\"${owt.getOrNull(3) ?: ""}\"," +
|
||||
"\"${owt.getOrNull(4) ?: ""}\",\"${owt.getOrNull(5) ?: ""}\"," +
|
||||
"\"${owt.getOrNull(6) ?: ""}\",\"${owt.getOrNull(7) ?: ""}\""
|
||||
"\"${em?.soil_moisture ?: ""}\",$oneWireValues"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -465,4 +463,8 @@ open class MetricsViewModel(
|
|||
}
|
||||
|
||||
protected fun decodeBase64(base64: String): ByteArray = base64.decodeBase64()?.toByteArray() ?: ByteArray(0)
|
||||
|
||||
companion object {
|
||||
private const val ONE_WIRE_SENSOR_COUNT = 8
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue