trafficmonitor init...2

This commit is contained in:
최준흠 2025-11-27 17:52:05 +09:00
parent c4a0c30d8f
commit 271cbdc698

View File

@ -44,7 +44,7 @@ class CollectorModel extends CommonModel
* @param string $endDate '2024-10-30' * @param string $endDate '2024-10-30'
* @return mixed 해당 자리의 수치값 * @return mixed 해당 자리의 수치값
*/ */
public function get95PercentileValue(TrafficEntity $trafficEntity, string $field, string $startDate, string $endDate) public function get95PercentileValue_OLD(TrafficEntity $trafficEntity, string $field, string $startDate, string $endDate)
{ {
// 1) 해당 조건의 전체 개수 구하기 // 1) 해당 조건의 전체 개수 구하기
$total = $total =
@ -70,8 +70,22 @@ class CollectorModel extends CommonModel
// 🔥 실행되기 전에 SQL 확인 // 🔥 실행되기 전에 SQL 확인
$sql = $builder->getCompiledSelect(false); //반드시 false해야 queryu reset 않함 $sql = $builder->getCompiledSelect(false); //반드시 false해야 queryu reset 않함
log_message('debug', '[95PERCENTILE QUERY] ' . $sql); log_message('debug', '[95PERCENTILE QUERY] ' . $sql);
$row = $builder->get()->getFirstRow('array');
$row = $builder->get()->getRowArray();
return $row[$field] ?? null; return $row[$field] ?? null;
} }
public function get95PercentileValue(TrafficEntity $trafficEntity, string $field, string $startDate, string $endDate)
{
$sql = "WITH ranked AS (
SELECT `{$field}`,`created_at`, ROW_NUMBER() OVER (ORDER BY `in` DESC) AS rn,COUNT(*) OVER () AS total
FROM {$this->table}
WHERE trafficinfo_uid = ?
AND created_at BETWEEN ? AND ?
)
SELECT `{$field}`
FROM ranked
WHERE rn = FLOOR(total * 0.05) + 1
LIMIT 1";
return $this->query($sql, [$trafficEntity->getPK(), $startDate, $endDate])->getRowArray()[$field];
}
} }