avoid duplicate stationary log
This commit is contained in:
@ -23,6 +23,7 @@ async function commitMessage(now, logDevice) {
|
|||||||
|
|
||||||
const vhc = await VhcModels.getVhcByDeviceId(logDevice.device_id)
|
const vhc = await VhcModels.getVhcByDeviceId(logDevice.device_id)
|
||||||
const lastTrack = await GpsTracksModels.get2LastLocByDeviceId(logDevice.device_id)
|
const lastTrack = await GpsTracksModels.get2LastLocByDeviceId(logDevice.device_id)
|
||||||
|
|
||||||
if (["heartbeat", "alarm"].includes(logDevice.action)) {
|
if (["heartbeat", "alarm"].includes(logDevice.action)) {
|
||||||
if (logDevice.ignition == GpsTracksModels.STTS_IGNITION_HIGH) {
|
if (logDevice.ignition == GpsTracksModels.STTS_IGNITION_HIGH) {
|
||||||
if (logDevice.speed) {
|
if (logDevice.speed) {
|
||||||
@ -477,11 +478,10 @@ class ListenController {
|
|||||||
if (previousCrtD == timestamp_device) continue
|
if (previousCrtD == timestamp_device) continue
|
||||||
previousCrtD = timestamp_device
|
previousCrtD = timestamp_device
|
||||||
|
|
||||||
|
const lastTrack = (await GpsTracksModels.get2LastLocByDeviceId(logDevice.device_id))?.[0]
|
||||||
const isSleepMode = rec.io["Sleep Mode"] == 0 ? false : true
|
const isSleepMode = rec.io["Sleep Mode"] == 0 ? false : true
|
||||||
if (isSleepMode) {
|
const isMoreThan1Min = lastTrack ? (timestamp_device - lastTrack.crt_d >= 60 ? true : false) : true
|
||||||
// get previous log io
|
if (!isMoreThan1Min && lastTrack.speed === 0 && rec.gnss.speed === 0) continue // avoid duplicate stationary log
|
||||||
// continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const now = moment().unix()
|
const now = moment().unix()
|
||||||
const logDevice = {
|
const logDevice = {
|
||||||
@ -520,8 +520,14 @@ class ListenController {
|
|||||||
crt_d_format: moment.unix(timestamp_device).format("YYYY-MM-DD HH:mm:ss"),
|
crt_d_format: moment.unix(timestamp_device).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
crt_s: now,
|
crt_s: now,
|
||||||
crt_s_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
crt_s_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
fuel_curr: rec.io["Fuel Level"] || 0,
|
fuel_curr:
|
||||||
fuel_count: rec.io["Fuel Consumed (counted)"] || 0,
|
rec.io["Fuel Level"] === 0 && isSleepMode
|
||||||
|
? lastTrack?.fuel_curr ?? 0
|
||||||
|
: rec.io["Fuel Level"] ?? 0,
|
||||||
|
fuel_count:
|
||||||
|
rec.io["Fuel Consumed (counted)"] === 0 && isSleepMode
|
||||||
|
? lastTrack?.fuel_count ?? 0
|
||||||
|
: rec.io["Fuel Consumed (counted)"] ?? 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
await commitMessage(now, logDevice)
|
await commitMessage(now, logDevice)
|
||||||
|
|||||||
Reference in New Issue
Block a user