napperley
03/16/2020, 11:59 PMnapperley
03/17/2020, 12:09 AM{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {
"__name__": "cell_voltage",
"battery": "1",
"cell": "1",
"exported_job": "cell_job",
"instance": "xxxx:xxxx",
"job": "push_gateway"
},
"value": [
1584393298.147,
"3366"
]
},
// ...
}
}
Dominaezzz
03/17/2020, 12:22 AMnapperley
03/17/2020, 12:28 AMnapperley
03/17/2020, 12:50 AMnapperley
03/17/2020, 1:39 AM@Serializable
internal data class CellVoltageValue(val timestamp: Double, val value: Int) {
@Serializer(forClass = CellVoltageValue::class)
internal companion object : KSerializer<CellVoltageValue> {
override fun deserialize(decoder: Decoder): CellVoltageValue {
val timestampPos = 0
val valuePos = 1
val input = decoder as? JsonInput ?: throw SerializationException("Expected Json Input")
val array = input.decodeJson() as? JsonArray ?: throw SerializationException("Expected Json Array")
val timestamp = array[timestampPos].primitive.double
val value = array[valuePos].primitive.content.toInt()
return CellVoltageValue(timestamp, value)
}
}
}
napperley
03/17/2020, 1:42 AMnapperley
03/17/2020, 1:45 AM@Serializable
internal data class CellVoltageResultItem(val metric: CellVoltageMetric, val value: CellVoltageValue)
napperley
03/17/2020, 1:47 AM