avoid duplicate stationary log

This commit is contained in:
Pringgosutono
2025-11-06 10:08:22 +07:00
parent 036b499360
commit 32deb2d3a8

View File

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