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 .= " ,tr.id as master_id,tr.latitude,tr.longitude,tr.speed,tr.orientation";
$query .= "
,(tr.crt + ( 9 * 3600 )) AS lst_loc_crt
,(tr.crt_d + ( 9 * 3600 )) AS lst_loc_crt_d
,(tr.crt + ( 7 * 3600 )) AS lst_loc_crt
,(tr.crt_d + ( 7 * 3600 )) AS lst_loc_crt_d
,tr.crt_s AS lst_loc_crt_s";
$query .= " ,tr.ignition,tr.stts_engine";
$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"])) {
$query .= " LIMIT ?";
$params[] = $filter["limit"] ?? 500;
$params[] = $filter["limit"] ?? 1000;
}
$query .= " ;";
// return DB::select($query, $params);
$rawTracks = DB::select($query, $params);
// $cleanTracks = self::filterJumps($rawTracks);
$cleanTracks = $rawTracks;
//dd($cleanTracks);
$rawTracks = collect($rawTracks);
// if (isset($filter["limit"])) {
// return array_slice($cleanTracks, 0, $filter["limit"]);
// }
return $cleanTracks;
$filtered = collect();
$zeroBlock = collect();
$tempBlock = collect();
$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 = [])