|
|
|
@ -14,6 +14,8 @@ import com.yinuo.safetywatcher.databinding.ActivityQueryDataBinding
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.base.BaseActivity
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.constant.DEFAULT_QUERY_TIME_INTERVAL
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.constant.TimeStep
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.port.convertData
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.port.getLocalGasUnit
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.ui.adapter.HistoryDataAdapter
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.ui.view.CommonTopBar
|
|
|
|
|
import com.yinuo.safetywatcher.watcher.utils.ChartBridge
|
|
|
|
@ -136,7 +138,10 @@ class QueryDataActivity : BaseActivity() {
|
|
|
|
|
}
|
|
|
|
|
// 全量数据
|
|
|
|
|
val gasDao = DBUtils.gasDao()
|
|
|
|
|
val gasList = gasDao.getAllByTime(startTime, endTime)
|
|
|
|
|
var gasList = gasDao.getAllByTime(startTime, endTime)
|
|
|
|
|
gasList = gasList.map {
|
|
|
|
|
tryConvertData(it)
|
|
|
|
|
}
|
|
|
|
|
// 多气体,分开创建list,存储之后。 再分步
|
|
|
|
|
val gasMap = gasList.groupBy {
|
|
|
|
|
it.gasName
|
|
|
|
@ -151,7 +156,7 @@ class QueryDataActivity : BaseActivity() {
|
|
|
|
|
var count = 0
|
|
|
|
|
list.forEachIndexed { index, gas ->
|
|
|
|
|
if (startGas == null) {
|
|
|
|
|
startGas = gas
|
|
|
|
|
startGas = gas.copy()
|
|
|
|
|
tempTime = gas.time - ((gas.time - startTime) % intervalMs)
|
|
|
|
|
gasValue = 0.0
|
|
|
|
|
count = 0
|
|
|
|
@ -163,7 +168,7 @@ class QueryDataActivity : BaseActivity() {
|
|
|
|
|
newMapList.add(startGas!!)
|
|
|
|
|
|
|
|
|
|
tempTime += intervalMs
|
|
|
|
|
startGas = gas
|
|
|
|
|
startGas = gas.copy()
|
|
|
|
|
gasValue = gas.gasValue
|
|
|
|
|
count = 1
|
|
|
|
|
}
|
|
|
|
@ -206,6 +211,16 @@ class QueryDataActivity : BaseActivity() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun tryConvertData(it: Gas): Gas {
|
|
|
|
|
val localGasUnit = getLocalGasUnit(it.gasName)
|
|
|
|
|
val unit = it.unit
|
|
|
|
|
if (unit != localGasUnit) {
|
|
|
|
|
it.gasValue = convertData(it.gasName, it.gasValue, unit, localGasUnit)
|
|
|
|
|
it.unit = localGasUnit
|
|
|
|
|
}
|
|
|
|
|
return it
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private fun doExportData() {
|
|
|
|
|
val usbPath = StorageUtils.getStoragePath(this@QueryDataActivity)
|
|
|
|
|
if (usbPath.isNullOrEmpty()) {
|
|
|
|
@ -214,7 +229,12 @@ class QueryDataActivity : BaseActivity() {
|
|
|
|
|
}
|
|
|
|
|
showLoadingDialog(R.string.export_data_tip, false)
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
|
TestUtils.testExportExcel(this@QueryDataActivity, usbPath, mAdapter._data, loadingDialog)
|
|
|
|
|
TestUtils.testExportExcel(
|
|
|
|
|
this@QueryDataActivity,
|
|
|
|
|
usbPath,
|
|
|
|
|
mAdapter._data,
|
|
|
|
|
loadingDialog
|
|
|
|
|
)
|
|
|
|
|
launch(Dispatchers.Main) {
|
|
|
|
|
showToast(getString(R.string.export_success))
|
|
|
|
|
}
|
|
|
|
|