desc:气体浓度使用float

main
xiaowusky 2 years ago
parent 7b53e16843
commit a2c4bd6c15

@ -37,10 +37,10 @@ object TestUtils {
// 构造告警数据
val warningDao = DBUtils.warningDao()
val warnings = mutableListOf<Warning>()
warnings.add(Warning("CO", 60.0, "", timeMillis))
warnings.add(Warning("CO", 80.0, "", timeMillis - 30 * 1000))
warnings.add(Warning("CO2", 80.0, "", timeMillis - 30 * 1000))
warnings.add(Warning("O2", 10.0, "", timeMillis - 90 * 1000))
warnings.add(Warning("CO", 60f, "", timeMillis))
warnings.add(Warning("CO", 80f, "", timeMillis - 30 * 1000))
warnings.add(Warning("CO2", 80f, "", timeMillis - 30 * 1000))
warnings.add(Warning("O2", 10f, "", timeMillis - 90 * 1000))
warningDao.insertAll(warnings)
}
}

@ -165,16 +165,16 @@ fun getGasRange(gasType: String, gasUnit: String): String {
return ""
}
fun ppm2mgm3(ppmValue: Double, molecular: Int): Double {
return ppmValue * molecular / 22.4
fun ppm2mgm3(ppmValue: Float, molecular: Int): Float {
return ppmValue * molecular / 22.4f
}
fun mgm3ToPpm(mValue: Double, molecular: Int): Double {
return mValue * 22.4 / molecular
fun mgm3ToPpm(mValue: Float, molecular: Int): Float {
return mValue * 22.4f / molecular
}
fun ch4Lel2ppm(lelValue: Double): Double {
return lelValue * 10000 / 20.0
fun ch4Lel2ppm(lelValue: Float): Float {
return lelValue * 10000 / 20f
}
/**
@ -184,10 +184,10 @@ fun ch4Lel2ppm(lelValue: Double): Double {
*/
fun convertData(
gasType: String,
value: Double,
value: Float,
unit: String,
localGasUnit: String
): Double {
): Float {
var retValue = value
if (CH4 == gasType) {
retValue = convertCH4(unit, value, localGasUnit)
@ -218,9 +218,9 @@ fun convertData(
*/
private fun convertCH4(
unit: String,
value: Double,
value: Float,
localGasUnit: String
): Double {
): Float {
var ret = value
if (UNIT_LEL == unit) {
// to ppm

@ -100,7 +100,7 @@ object ParseHelper {
val valueHexLong: Long = HexUtils.hexToLong(valueHex)
// 浓度
var value =
c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2) / 10.0.pow(
c18.plus(c17).plus(java.lang.Long.toBinaryString(valueHexLong)).toInt(2) / 10f.pow(
pointNum
)
// 量程
@ -147,11 +147,11 @@ object ParseHelper {
/**
* 插入气体数据
*/
private fun insertGasData(gasType: String, value: Double, unit: String) {
private fun insertGasData(gasType: String, value: Float, unit: String) {
GlobalScope.launch {
// 阈值范围
val min = getGasLowThreshold(gasType).toDouble()
val max = getGasHighThreshold(gasType).toDouble()
val min = getGasLowThreshold(gasType)
val max = getGasHighThreshold(gasType)
// 构造气体数据
val timeMillis = System.currentTimeMillis()

@ -151,18 +151,18 @@ class QueryDataActivity : BaseActivity() {
gasMap.forEach { (type, list) ->
val newMapList = mutableListOf<Gas>()
var startGas: Gas? = null
var gasValue = 0.0
var gasValue = 0f
var tempTime = 0L
var count = 0
list.forEachIndexed { index, gas ->
if (startGas == null) {
startGas = gas.copy()
tempTime = gas.time - ((gas.time - startTime) % intervalMs)
gasValue = 0.0
gasValue = 0f
count = 0
}
if (gas.time - tempTime > intervalMs) {
if (gasValue >= 0.0) {
if (gasValue >= 0f) {
startGas!!.gasValue = gasValue / count
startGas!!.time = tempTime
newMapList.add(startGas!!)
@ -177,7 +177,7 @@ class QueryDataActivity : BaseActivity() {
if (num > 0) {
for (i in num downTo 1) {
tempTime += intervalMs
newMapList.add(gas.copy(time = tempTime, gasValue = -1.0))
newMapList.add(gas.copy(time = tempTime, gasValue = -1.0f))
}
}
} else {
@ -187,7 +187,7 @@ class QueryDataActivity : BaseActivity() {
// 最后一个特殊处理
if (list.size - 1 == index) {
if (gasValue >= 0.0) {
if (gasValue >= 0f) {
startGas!!.gasValue = gasValue / count
startGas!!.time = tempTime
newMapList.add(startGas!!)
@ -201,7 +201,7 @@ class QueryDataActivity : BaseActivity() {
gasNewMap.forEach { (t, u) ->
newList.addAll(u)
}
newList = newList.filter { it.gasValue >= 0.0 } as MutableList<Gas>
newList = newList.filter { it.gasValue >= 0f } as MutableList<Gas>
newList.sortWith { o1, o2 ->
(o2.time - o1.time).toInt()
}

@ -8,10 +8,10 @@ import androidx.room.PrimaryKey
data class Gas(
@ColumnInfo(name = "time") var time: Long,
@ColumnInfo(name = "gas_name") var gasName: String,
@ColumnInfo(name = "gas_value") var gasValue: Double = 0.0,
@ColumnInfo(name = "gas_value") var gasValue: Float = 0f,
@ColumnInfo(name = "unit") var unit: String = "",
@ColumnInfo(name = "threshold_low") var thresholdLow: Double = 0.0,
@ColumnInfo(name = "threshold_high") var thresholdHigh: Double = 0.0,
@ColumnInfo(name = "threshold_low") var thresholdLow: Float = 0f,
@ColumnInfo(name = "threshold_high") var thresholdHigh: Float = 0f,
@ColumnInfo(name = "sync_flag") var syncFlag: Boolean = false,
@PrimaryKey(autoGenerate = true) var id: Int = 0
)

@ -7,11 +7,11 @@ import androidx.room.PrimaryKey
@Entity
data class Warning(
@ColumnInfo(name = "gas_name") var gasName: String,
@ColumnInfo(name = "gas_value") var gasValue: Double,
@ColumnInfo(name = "gas_value") var gasValue: Float,
@ColumnInfo(name = "unit") var unit: String,
@ColumnInfo(name = "start_time") var startTime: Long,
@ColumnInfo(name = "threshold_low") var thresholdLow: Double = 0.0,
@ColumnInfo(name = "threshold_high") var thresholdHigh: Double = 0.0,
@ColumnInfo(name = "threshold_low") var thresholdLow: Float = 0f,
@ColumnInfo(name = "threshold_high") var thresholdHigh: Float = 0f,
@ColumnInfo(name = "end_time") var endTime: Long = -1L,
@PrimaryKey(autoGenerate = true) var id: Int = 0
)

Loading…
Cancel
Save