update
This commit is contained in:
@ -472,9 +472,16 @@ class ListenController {
|
|||||||
let previousCrtD = 0
|
let previousCrtD = 0
|
||||||
for (const rec of records) {
|
for (const rec of records) {
|
||||||
// console.log("rec ====> ", rec)
|
// console.log("rec ====> ", rec)
|
||||||
|
const timestamp_device = rec.gnss.timestamp / 1000 - 25200
|
||||||
// avoid duplicate timestamp
|
// avoid duplicate timestamp
|
||||||
if (previousCrtD == rec.gnss.timestamp) continue
|
if (previousCrtD == timestamp_device) continue
|
||||||
previousCrtD = rec.gnss.timestamp
|
previousCrtD = timestamp_device
|
||||||
|
|
||||||
|
const isSleepMode = rec.io["Sleep Mode"] == 0 ? false : true
|
||||||
|
if (isSleepMode) {
|
||||||
|
// get previous log io
|
||||||
|
// continue;
|
||||||
|
}
|
||||||
|
|
||||||
const now = moment().unix()
|
const now = moment().unix()
|
||||||
const logDevice = {
|
const logDevice = {
|
||||||
@ -509,8 +516,8 @@ class ListenController {
|
|||||||
crt: now,
|
crt: now,
|
||||||
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
crt_format: moment.unix(now).format("YYYY-MM-DD HH:mm:ss"),
|
||||||
// minus 7 hours -- ngikutin data gt06 biar sinkron
|
// minus 7 hours -- ngikutin data gt06 biar sinkron
|
||||||
crt_d: rec.gnss.timestamp / 1000 - 25200,
|
crt_d: timestamp_device,
|
||||||
crt_d_format: moment.unix(rec.gnss.timestamp / 1000 - 25200).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: rec.io["Fuel Level"] || 0,
|
||||||
|
|||||||
@ -179,7 +179,7 @@ async function tripGrouping() {
|
|||||||
|
|
||||||
const q2 = `
|
const q2 = `
|
||||||
insert into trips
|
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
|
WITH
|
||||||
gaps AS (
|
gaps AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -232,7 +232,8 @@ async function tripGrouping() {
|
|||||||
MAX(a.vhc_milleage) AS finishMileage,
|
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 = MIN(a.id) LIMIT 1) AS startLoc,
|
||||||
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MAX(a.id) LIMIT 1) AS finishLoc,
|
(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
|
FROM t_vehicles v
|
||||||
LEFT JOIN numbered a ON a.vhc_id = v.id
|
LEFT JOIN numbered a ON a.vhc_id = v.id
|
||||||
WHERE
|
WHERE
|
||||||
@ -255,7 +256,8 @@ async function tripGrouping() {
|
|||||||
finishMileage = values(finishMileage),
|
finishMileage = values(finishMileage),
|
||||||
startLoc = values(startLoc),
|
startLoc = values(startLoc),
|
||||||
finishLoc = values(finishLoc),
|
finishLoc = values(finishLoc),
|
||||||
row_count = values(row_count)
|
row_count = values(row_count),
|
||||||
|
fuel_consume = values(fuel_consume)
|
||||||
`
|
`
|
||||||
const d2 = [startOfMonth, endOfMonth]
|
const d2 = [startOfMonth, endOfMonth]
|
||||||
const r2 = await db.query(q2, d2)
|
const r2 = await db.query(q2, d2)
|
||||||
|
|||||||
Reference in New Issue
Block a user