timefix
This commit is contained in:
@ -9,6 +9,7 @@ class Helper
|
||||
const EARTH_RADIUS_M = 6371000;
|
||||
const EARTH_RADIUS_KM = 6371;
|
||||
const EARTH_RADIUS_MILES = 3959; // 3958.756 || 3959 || 3963
|
||||
const TIMEFIX = 25200;
|
||||
|
||||
/**
|
||||
* Calculates the great-circle distance between two points, with
|
||||
|
||||
@ -49,6 +49,8 @@ class ReportsController extends Controller
|
||||
return new Response($apiResp, $apiResp["meta"]["code"]);
|
||||
}
|
||||
|
||||
// $from_date = $req->input('from_date');
|
||||
// $to_date = $req->input('to_date');
|
||||
$from_date = $req->input('from_date');
|
||||
$to_date = $req->input('to_date');
|
||||
$vid = $req->input('vid');
|
||||
@ -62,7 +64,7 @@ class ReportsController extends Controller
|
||||
-- mark the start of a trip when ignition=4 and previous ignition <> 4
|
||||
CASE
|
||||
WHEN ignition = 4
|
||||
AND LAG(ignition, 1, 0) OVER (PARTITION BY vhc_id ORDER BY crt_s) <> 4
|
||||
AND LAG(ignition, 1, 0) OVER (PARTITION BY vhc_id ORDER BY crt_d) <> 4
|
||||
THEN 1 ELSE 0
|
||||
END AS trip_start
|
||||
FROM t_gps_tracks t
|
||||
@ -70,13 +72,13 @@ class ReportsController extends Controller
|
||||
t.latitude IS NOT NULL
|
||||
AND t.longitude IS NOT NULL
|
||||
AND t.action = 'location'
|
||||
AND t.crt_s BETWEEN ? AND ?
|
||||
AND t.crt_d BETWEEN ? AND ?
|
||||
)
|
||||
, numbered AS (
|
||||
SELECT
|
||||
*,
|
||||
-- assign a trip_id by cumulative sum of trip_start
|
||||
SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_s) AS trip_id
|
||||
SUM(trip_start) OVER (PARTITION BY vhc_id ORDER BY crt_d) AS trip_id
|
||||
FROM trips
|
||||
where ignition = 4
|
||||
),
|
||||
@ -88,10 +90,10 @@ class ReportsController extends Controller
|
||||
v.nopol1,
|
||||
vhc_id,
|
||||
-- trip_id,
|
||||
ROW_NUMBER() OVER (PARTITION BY v.id ORDER BY MIN(a.crt_s)) AS trip_id,
|
||||
ROW_NUMBER() OVER (PARTITION BY v.id ORDER BY MIN(a.crt_d)) AS trip_id,
|
||||
SUM(pre_milleage) AS mileage,
|
||||
MIN(a.crt_s) AS start,
|
||||
MAX(a.crt_s) AS finish,
|
||||
MIN(a.crt_d) AS start,
|
||||
MAX(a.crt_d) AS finish,
|
||||
MIN(a.vhc_milleage) AS startMileage,
|
||||
MAX(a.vhc_milleage) AS finishMileage,
|
||||
(SELECT fulladdress FROM t_gps_tracks_address WHERE master_id = MIN(a.id) LIMIT 1) AS startLoc,
|
||||
@ -202,7 +204,7 @@ class ReportsController extends Controller
|
||||
|
||||
$d = [$vid, $tgl0, $tgl1];
|
||||
$list = DB::select("SELECT
|
||||
t.crt_s , t.latitude, t.longitude, t.speed,
|
||||
t.crt_d , t.latitude, t.longitude, t.speed,
|
||||
tgta.fulladdress,
|
||||
t.pre_milleage, t.vhc_milleage
|
||||
FROM
|
||||
@ -213,23 +215,23 @@ class ReportsController extends Controller
|
||||
and t.latitude IS NOT NULL
|
||||
AND t.longitude IS NOT NULL
|
||||
AND t.action = 'location'
|
||||
AND t.crt_s BETWEEN ? AND ?
|
||||
ORDER BY t.crt_s asc
|
||||
AND t.crt_d BETWEEN ? AND ?
|
||||
ORDER BY t.crt_d asc
|
||||
", $d);
|
||||
|
||||
$start = [
|
||||
'time' => $list[0]->crt_s,
|
||||
'time' => $list[0]->crt_d,
|
||||
'fulladdress' => urldecode($list[0]->fulladdress),
|
||||
'mileage' => $list[0]->vhc_milleage,
|
||||
];
|
||||
$finish = [
|
||||
'time' => $list[count($list) - 1]->crt_s,
|
||||
'time' => $list[count($list) - 1]->crt_d,
|
||||
'fulladdress' => urldecode($list[count($list) - 1]->fulladdress),
|
||||
'mileage' => $list[count($list) - 1]->vhc_milleage,
|
||||
];
|
||||
|
||||
$t0 = Carbon::createFromTimestamp($list[0]->crt_s);
|
||||
$t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_s);
|
||||
$t0 = Carbon::createFromTimestamp($list[0]->crt_d);
|
||||
$t1 = Carbon::createFromTimestamp($list[count($list) - 1]->crt_d);
|
||||
$diff = $t1->diff($t0);
|
||||
$hours = $diff->h + ($diff->days * 24); // include days converted to hours
|
||||
$minutes = $diff->i;
|
||||
@ -285,7 +287,7 @@ class ReportsController extends Controller
|
||||
try {
|
||||
$list = DB::select("SELECT
|
||||
tv.name, tv.nopol1,
|
||||
t.crt_s, t.speed, tgta.fulladdress,
|
||||
t.crt_d, t.speed, tgta.fulladdress,
|
||||
tvd.speed_limit, tvd.pool_code, tvd.dc_code
|
||||
from
|
||||
t_gps_tracks t
|
||||
@ -295,11 +297,11 @@ class ReportsController extends Controller
|
||||
WHERE
|
||||
t.action = 'location'
|
||||
and t.speed != 0
|
||||
AND t.crt_s BETWEEN ? AND ?
|
||||
AND t.crt_d BETWEEN ? AND ?
|
||||
and if(? , tv.id = ? , 1=1)
|
||||
-- and t.speed > tvd.speed_limit
|
||||
having t.speed >= tvd.speed_limit
|
||||
ORDER BY t.crt_s
|
||||
ORDER BY t.crt_d
|
||||
", [$from_date, $to_date, $vid, $vid]);
|
||||
|
||||
// // RETURN 1 - LIST
|
||||
|
||||
Reference in New Issue
Block a user