This commit is contained in:
Pringgosutono
2025-11-04 13:12:42 +07:00
parent 6c1738b488
commit 3dcb228e55
2 changed files with 16 additions and 7 deletions

View File

@ -472,9 +472,16 @@ class ListenController {
let previousCrtD = 0
for (const rec of records) {
// console.log("rec ====> ", rec)
const timestamp_device = rec.gnss.timestamp / 1000 - 25200
// avoid duplicate timestamp
if (previousCrtD == rec.gnss.timestamp) continue
previousCrtD = rec.gnss.timestamp
if (previousCrtD == timestamp_device) continue
previousCrtD = timestamp_device
const isSleepMode = rec.io["Sleep Mode"] == 0 ? false : true
if (isSleepMode) {
// get previous log io
// continue;
}
const now = moment().unix()
const logDevice = {
@ -509,8 +516,8 @@ class ListenController {
crt: now,
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
// minus 7 hours -- ngikutin data gt06 biar sinkron
crt_d: rec.gnss.timestamp / 1000 - 25200,
crt_d_format: moment.unix(rec.gnss.timestamp / 1000 - 25200).format("YYYY-MM-DD HH:mm:ss"),
crt_d: timestamp_device,
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,

View File

@ -179,7 +179,7 @@ async function tripGrouping() {
const q2 = `
insert into trips
(id,name,nopol1,vhc_id,mileage,start,finish,startMileage,finishMileage,startLoc,finishLoc,pool_code,dc_code,row_count)
(id,name,nopol1,vhc_id,mileage,start,finish,startMileage,finishMileage,startLoc,finishLoc,pool_code,dc_code,row_count,fuel_consume)
WITH
gaps AS (
SELECT
@ -232,7 +232,8 @@ async function tripGrouping() {
MAX(a.vhc_milleage) AS finishMileage,
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MIN(a.id) LIMIT 1) AS startLoc,
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MAX(a.id) LIMIT 1) AS finishLoc,
COUNT(*) AS row_count
COUNT(*) AS row_count,
max(fuel_count) - min(fuel_count) AS fuel_consume
FROM t_vehicles v
LEFT JOIN numbered a ON a.vhc_id = v.id
WHERE
@ -255,7 +256,8 @@ async function tripGrouping() {
finishMileage = values(finishMileage),
startLoc = values(startLoc),
finishLoc = values(finishLoc),
row_count = values(row_count)
row_count = values(row_count),
fuel_consume = values(fuel_consume)
`
const d2 = [startOfMonth, endOfMonth]
const r2 = await db.query(q2, d2)