Fix daily_summary dan hourly_summary aggregation, tambah fallback logic untuk dashboard, update validator untuk camera dan location type

This commit is contained in:
mwpn
2025-12-18 11:13:06 +07:00
parent 9416de7d87
commit d05fa2f4cd
31 changed files with 2041 additions and 45 deletions

86
bin/check_today_data.php Normal file
View File

@@ -0,0 +1,86 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
use App\Config\AppConfig;
use App\Support\Database;
AppConfig::loadEnv(__DIR__ . '/..');
$db = Database::getConnection(
AppConfig::get('DB_HOST'),
AppConfig::get('DB_NAME'),
AppConfig::get('DB_USER'),
AppConfig::get('DB_PASS')
);
// Get today's date
$today = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 day'));
echo "=== Checking Today's Data ===\n";
echo "Today: $today\n";
echo "Yesterday: $yesterday\n\n";
$dates = [$today, $yesterday, '2025-12-17', '2025-12-18'];
foreach ($dates as $date) {
echo "--- Date: $date ---\n";
// Check entry_events
$stmt = $db->prepare('SELECT COUNT(*) as count, MIN(event_time) as first_event, MAX(event_time) as last_event FROM entry_events WHERE DATE(event_time) = ?');
$stmt->execute([$date]);
$entryResult = $stmt->fetch();
$entryCount = $entryResult['count'];
echo " entry_events:\n";
echo " Count: $entryCount events\n";
if ($entryCount > 0) {
echo " First event: " . ($entryResult['first_event'] ?? 'N/A') . "\n";
echo " Last event: " . ($entryResult['last_event'] ?? 'N/A') . "\n";
// Get sample data
$stmt = $db->prepare('SELECT event_time, location_code, gate_code, category FROM entry_events WHERE DATE(event_time) = ? ORDER BY event_time DESC LIMIT 5');
$stmt->execute([$date]);
$samples = $stmt->fetchAll();
echo " Sample events (last 5):\n";
foreach ($samples as $sample) {
echo " - " . $sample['event_time'] . " | " . $sample['location_code'] . " | " . $sample['gate_code'] . " | " . $sample['category'] . "\n";
}
}
// Check daily_summary
$stmt = $db->prepare('SELECT COUNT(*) as count, SUM(total_count) as total_count, SUM(total_amount) as total_amount FROM daily_summary WHERE summary_date = ?');
$stmt->execute([$date]);
$summaryResult = $stmt->fetch();
$summaryCount = $summaryResult['count'];
$summaryTotal = $summaryResult['total_count'] ?? 0;
$summaryAmount = $summaryResult['total_amount'] ?? 0;
echo " daily_summary:\n";
echo " Records: $summaryCount\n";
echo " Total count: $summaryTotal\n";
echo " Total amount: $summaryAmount\n";
if ($entryCount > 0 && $summaryCount == 0) {
echo " ⚠️ WARNING: Data exists in entry_events but NOT aggregated to daily_summary!\n";
echo " Run: php bin/daily_summary.php $date\n";
}
echo "\n";
}
// Check all dates with data
echo "=== All dates with entry_events (last 10) ===\n";
$stmt = $db->query('SELECT DATE(event_time) as date, COUNT(*) as count FROM entry_events GROUP BY DATE(event_time) ORDER BY date DESC LIMIT 10');
$results = $stmt->fetchAll();
foreach ($results as $row) {
echo $row['date'] . ' - ' . $row['count'] . ' events' . "\n";
}
echo "\n=== All dates with daily_summary (last 10) ===\n";
$stmt = $db->query('SELECT summary_date, SUM(total_count) as total FROM daily_summary GROUP BY summary_date ORDER BY summary_date DESC LIMIT 10');
$results = $stmt->fetchAll();
foreach ($results as $row) {
echo $row['summary_date'] . ' - ' . $row['total'] . ' total' . "\n";
}