This commit is contained in:
meusinfirmary
2025-07-16 18:04:04 +07:00
parent 847757ce0d
commit c97dd332f0
2 changed files with 57 additions and 27 deletions

View File

@ -313,8 +313,8 @@ class Tracks extends Model
$query .= " v.id as vid,v.device_id,v.nopol1,v.nopol2,v.nopol3"; $query .= " v.id as vid,v.device_id,v.nopol1,v.nopol2,v.nopol3";
$query .= " ,tr.id as master_id,tr.latitude,tr.longitude,tr.speed,tr.orientation"; $query .= " ,tr.id as master_id,tr.latitude,tr.longitude,tr.speed,tr.orientation";
$query .= " $query .= "
,(tr.crt + ( 9 * 3600 )) AS lst_loc_crt ,(tr.crt + ( 7 * 3600 )) AS lst_loc_crt
,(tr.crt_d + ( 9 * 3600 )) AS lst_loc_crt_d ,(tr.crt_d + ( 7 * 3600 )) AS lst_loc_crt_d
,tr.crt_s AS lst_loc_crt_s"; ,tr.crt_s AS lst_loc_crt_s";
$query .= " ,tr.ignition,tr.stts_engine"; $query .= " ,tr.ignition,tr.stts_engine";
$query .= " ,tr.pre_milleage,tr.sum_milleage,tr.vhc_milleage,v.sum_milleage AS vhc_sum_milleage_1"; $query .= " ,tr.pre_milleage,tr.sum_milleage,tr.vhc_milleage,v.sum_milleage AS vhc_sum_milleage_1";
@ -356,21 +356,66 @@ class Tracks extends Model
if (isset($filter["limit"])) { if (isset($filter["limit"])) {
$query .= " LIMIT ?"; $query .= " LIMIT ?";
$params[] = $filter["limit"] ?? 500; $params[] = $filter["limit"] ?? 1000;
} }
$query .= " ;"; $query .= " ;";
// return DB::select($query, $params);
$rawTracks = DB::select($query, $params); $rawTracks = DB::select($query, $params);
// $cleanTracks = self::filterJumps($rawTracks); $rawTracks = collect($rawTracks);
$cleanTracks = $rawTracks;
//dd($cleanTracks);
// if (isset($filter["limit"])) { $filtered = collect();
// return array_slice($cleanTracks, 0, $filter["limit"]); $zeroBlock = collect();
// } $tempBlock = collect();
return $cleanTracks;
$lastIndex = $rawTracks->count() - 1;
foreach ($rawTracks as $i => $track) {
$isZero = $track->speed == 0;
if ($i === $lastIndex) {
if ($isZero) {
$zeroBlock->push($track);
} else {
if ($zeroBlock->isNotEmpty()) {
$tempBlock = $zeroBlock;
$tempBlock->push($track);
$zerosOnly = $tempBlock->filter(fn($t) => $t->speed == 0);
if ($zerosOnly->count() === 1) {
$filtered->push($zerosOnly->first());
} elseif ($zerosOnly->count() > 1) {
$filtered->push($zerosOnly->first());
$filtered->push($zerosOnly->last());
}
} else {
$filtered->push($track);
}
}
continue;
}
if ($isZero) {
$zeroBlock->push($track);
} else {
if ($zeroBlock->isNotEmpty()) {
$filtered->push($zeroBlock->first());
$zeroBlock = collect();
}
$filtered->push($track);
}
}
if ($zeroBlock->isNotEmpty() && $rawTracks->last()->speed == 0) {
if ($zeroBlock->count() === 1) {
$filtered->push($zeroBlock->first());
} else {
$filtered->push($zeroBlock->first());
$filtered->push($zeroBlock->last());
}
}
return $filtered->take(500);
} }
public static function nearestInCircle($lat, $lng, $rad, $filter = []) public static function nearestInCircle($lat, $lng, $rad, $filter = [])

View File

@ -9,21 +9,6 @@
@endsection @endsection
@section('customcss') @section('customcss')
<style>
/* .select2-container {
z-index: 99999;
} */
/* .landscape-photo {
max-height: max(21vh, 210px);
} */
/* .thumb-img-table {
width: max(4vw, 75px);
height: max(4vh, 55px);
object-fit: cover;
} */
</style>
@endsection @endsection
@section('content') @section('content')