This commit is contained in:
meusinfirmary
2025-06-20 14:59:38 +08:00
parent c4c1bb90fe
commit f41a39417f

View File

@ -355,71 +355,13 @@ class Tracks extends Model
usort($rawTracks, fn($a, $b) => $a->lst_loc_crt <=> $b->lst_loc_crt); usort($rawTracks, fn($a, $b) => $a->lst_loc_crt <=> $b->lst_loc_crt);
// Filter loncatan // Filter loncatan
$filtered = self::filterJumps($rawTracks, 1000, 5, 300); $filtered = self::filterJumps($rawTracks, 3000, 5, 300);
return $filtered; return $filtered;
// return array_reverse($filtered); // return array_reverse($filtered);
} }
// public static function filterJumps($points, $maxDistance = 1000, $maxTimeGap = 5, $maxSpeed = 300) public static function filterJumps($points, $maxDistance = 3000, $maxTimeGap = 5, $maxSpeed = 150)
// {
// $filtered = [];
// $last = null;
// foreach ($points as $p) {
// // 🛡️ 1. Validasi data koordinat
// if (!is_numeric($p->latitude) || !is_numeric($p->longitude)) {
// continue;
// }
// if (strlen((string) abs($p->latitude)) < 8 || strlen((string) abs($p->longitude)) < 8) {
// // Buang lat/lon kurang dari 8 digit desimal (umumnya noise)
// continue;
// }
// if (!$last) {
// $filtered[] = $p;
// $last = $p;
// continue;
// }
// // 2. Hitung jarak dan waktu
// $distance = self::haversineDistance(
// $last->latitude,
// $last->longitude,
// $p->latitude,
// $p->longitude
// );
// $timeGap = $p->lst_loc_crt - $last->lst_loc_crt;
// if ($timeGap <= 0) {
// continue;
// }
// $speed = ($distance / $timeGap) * 3.6; // m/s to km/h
// // 🧠 3. Validasi kombinasi logis
// if ($speed <= $maxSpeed && ($distance <= $maxDistance || $timeGap >= $maxTimeGap)) {
// $filtered[] = $p;
// $last = $p;
// } else {
// // Optional debug:
// // Log::info("LONCAT: speed={$speed}, dist={$distance}, timeGap={$timeGap}, pointID={$p->master_id}");
// }
// }
// // ⏳ Tambahkan titik terakhir jika tidak masuk
// if (!empty($points)) {
// $lastPoint = end($points);
// if (empty($filtered) || end($filtered)->lst_loc_crt !== $lastPoint->lst_loc_crt) {
// $filtered[] = $lastPoint;
// }
// }
// return $filtered;
// }
public static function filterJumps($points, $maxDistance = 2000, $maxTimeGap = 5, $maxSpeed = 150)
{ {
$filtered = []; $filtered = [];
$last = null; $last = null;