286 lines
6.0 KiB
Markdown
286 lines
6.0 KiB
Markdown
|
|
# Test Manual Cron - Hourly Summary
|
|||
|
|
|
|||
|
|
## Cara Test Manual Execute Cron
|
|||
|
|
|
|||
|
|
### 1. Test Update Hari Ini (Semua Jam)
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd /www/wwwroot/api.btekno.cloud/api
|
|||
|
|
php bin/hourly_summary.php today
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Yang terjadi:**
|
|||
|
|
- ✅ Query semua event hari ini dari `entry_events`
|
|||
|
|
- ✅ Group by jam (0-23), location, gate, category
|
|||
|
|
- ✅ Upsert ke `hourly_summary` (INSERT jika baru, UPDATE jika sudah ada)
|
|||
|
|
- ✅ Data lama **DIGANTI** dengan hasil rekap ulang
|
|||
|
|
|
|||
|
|
### 2. Test Update Jam Tertentu Hari Ini
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Update jam 14 (2 siang) hari ini
|
|||
|
|
php bin/hourly_summary.php today 14
|
|||
|
|
|
|||
|
|
# Update jam 1 pagi hari ini
|
|||
|
|
php bin/hourly_summary.php today 1
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Yang terjadi:**
|
|||
|
|
- ✅ Query hanya event jam tertentu hari ini
|
|||
|
|
- ✅ Lebih cepat karena hanya proses 1 jam
|
|||
|
|
- ✅ Upsert ke `hourly_summary` untuk jam tersebut
|
|||
|
|
|
|||
|
|
### 3. Test Rekap Kemarin
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
php bin/hourly_summary.php yesterday
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Yang terjadi:**
|
|||
|
|
- ✅ Query semua event kemarin dari `entry_events`
|
|||
|
|
- ✅ Rekap semua jam kemarin (0-23)
|
|||
|
|
- ✅ Upsert ke `hourly_summary` untuk kemarin
|
|||
|
|
|
|||
|
|
## Verifikasi Data Ter-Update
|
|||
|
|
|
|||
|
|
### Sebelum Execute Cron
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- Cek data jam tertentu hari ini
|
|||
|
|
SELECT
|
|||
|
|
summary_date,
|
|||
|
|
summary_hour,
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
total_count,
|
|||
|
|
total_amount,
|
|||
|
|
updated_at
|
|||
|
|
FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = HOUR(NOW())
|
|||
|
|
ORDER BY summary_hour DESC, location_code, gate_code, category;
|
|||
|
|
|
|||
|
|
-- Atau cek jam tertentu (misalnya jam 14)
|
|||
|
|
SELECT * FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = 14;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Execute Cron Manual
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Contoh: update jam 14 hari ini
|
|||
|
|
php bin/hourly_summary.php today 14
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Output yang diharapkan:**
|
|||
|
|
```
|
|||
|
|
Processing hourly summary for date: 2025-12-17, hour: 14
|
|||
|
|
Success!
|
|||
|
|
Date: 2025-12-17
|
|||
|
|
Hour: 14
|
|||
|
|
Rows processed: 12
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Setelah Execute Cron
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- Cek lagi data yang sama
|
|||
|
|
SELECT
|
|||
|
|
summary_date,
|
|||
|
|
summary_hour,
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
total_count,
|
|||
|
|
total_amount,
|
|||
|
|
updated_at
|
|||
|
|
FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = 14;
|
|||
|
|
|
|||
|
|
-- Bandingkan:
|
|||
|
|
-- 1. total_count dan total_amount harus sesuai dengan entry_events
|
|||
|
|
-- 2. updated_at harus ter-update (jika kolom ada)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Verifikasi dengan Entry Events
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- Hitung manual dari entry_events untuk jam tertentu
|
|||
|
|
SELECT
|
|||
|
|
DATE(event_time) as date,
|
|||
|
|
HOUR(event_time) as hour,
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
COUNT(*) as count_from_events
|
|||
|
|
FROM entry_events
|
|||
|
|
WHERE DATE(event_time) = CURDATE()
|
|||
|
|
AND HOUR(event_time) = 14
|
|||
|
|
GROUP BY DATE(event_time), HOUR(event_time), location_code, gate_code, category;
|
|||
|
|
|
|||
|
|
-- Bandingkan dengan hourly_summary:
|
|||
|
|
SELECT
|
|||
|
|
summary_date,
|
|||
|
|
summary_hour,
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
total_count as count_from_summary
|
|||
|
|
FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = 14;
|
|||
|
|
|
|||
|
|
-- Harusnya count_from_events = count_from_summary
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## Contoh Test Lengkap
|
|||
|
|
|
|||
|
|
### Step 1: Cek Data Sebelumnya
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Masuk ke MySQL
|
|||
|
|
mysql -u sql_retribusi -p sql_retribusi
|
|||
|
|
|
|||
|
|
# Query data jam 14 hari ini
|
|||
|
|
SELECT * FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = 14
|
|||
|
|
LIMIT 5;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Catat nilai:**
|
|||
|
|
- total_count: ?
|
|||
|
|
- total_amount: ?
|
|||
|
|
|
|||
|
|
### Step 2: Execute Cron Manual
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Keluar dari MySQL (exit)
|
|||
|
|
# Execute cron manual
|
|||
|
|
cd /www/wwwroot/api.btekno.cloud/api
|
|||
|
|
php bin/hourly_summary.php today 14
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Output:**
|
|||
|
|
```
|
|||
|
|
Processing hourly summary for date: 2025-12-17, hour: 14
|
|||
|
|
Success!
|
|||
|
|
Date: 2025-12-17
|
|||
|
|
Hour: 14
|
|||
|
|
Rows processed: 12
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Step 3: Cek Data Setelah Update
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
# Masuk ke MySQL lagi
|
|||
|
|
mysql -u sql_retribusi -p sql_retribusi
|
|||
|
|
|
|||
|
|
# Query data yang sama
|
|||
|
|
SELECT * FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = 14
|
|||
|
|
LIMIT 5;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**Bandingkan:**
|
|||
|
|
- ✅ total_count harus sesuai dengan COUNT dari entry_events
|
|||
|
|
- ✅ total_amount harus sesuai dengan total_count × tariff.price
|
|||
|
|
- ✅ Data **DIGANTI** dengan nilai baru (bukan ditambah)
|
|||
|
|
|
|||
|
|
### Step 4: Verifikasi dengan Entry Events
|
|||
|
|
|
|||
|
|
```sql
|
|||
|
|
-- Hitung dari source data
|
|||
|
|
SELECT
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
COUNT(*) as event_count
|
|||
|
|
FROM entry_events
|
|||
|
|
WHERE DATE(event_time) = CURDATE()
|
|||
|
|
AND HOUR(event_time) = 14
|
|||
|
|
GROUP BY location_code, gate_code, category;
|
|||
|
|
|
|||
|
|
-- Bandingkan dengan summary
|
|||
|
|
SELECT
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
total_count
|
|||
|
|
FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
AND summary_hour = 14;
|
|||
|
|
|
|||
|
|
-- Harusnya event_count = total_count untuk setiap kombinasi
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## Troubleshooting
|
|||
|
|
|
|||
|
|
### Problem: Data Tidak Ter-Update
|
|||
|
|
|
|||
|
|
**Cek:**
|
|||
|
|
1. Apakah ada error saat execute?
|
|||
|
|
```bash
|
|||
|
|
php bin/hourly_summary.php today 14 2>&1
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
2. Apakah ada data di entry_events untuk jam tersebut?
|
|||
|
|
```sql
|
|||
|
|
SELECT COUNT(*) FROM entry_events
|
|||
|
|
WHERE DATE(event_time) = CURDATE()
|
|||
|
|
AND HOUR(event_time) = 14;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
3. Apakah location/gate aktif?
|
|||
|
|
```sql
|
|||
|
|
SELECT * FROM locations WHERE code = 'kerkof_01' AND is_active = 1;
|
|||
|
|
SELECT * FROM gates WHERE location_code = 'kerkof_01' AND is_active = 1;
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### Problem: Data Double/Triple Count
|
|||
|
|
|
|||
|
|
**Ini TIDAK mungkin terjadi** karena menggunakan `ON DUPLICATE KEY UPDATE`:
|
|||
|
|
- Data selalu diganti, bukan ditambah
|
|||
|
|
- Jika terlihat double, kemungkinan ada masalah di query aggregation
|
|||
|
|
|
|||
|
|
**Cek:**
|
|||
|
|
```sql
|
|||
|
|
-- Cek apakah ada duplikasi di hourly_summary
|
|||
|
|
SELECT
|
|||
|
|
summary_date,
|
|||
|
|
summary_hour,
|
|||
|
|
location_code,
|
|||
|
|
gate_code,
|
|||
|
|
category,
|
|||
|
|
COUNT(*) as duplicate_count
|
|||
|
|
FROM hourly_summary
|
|||
|
|
WHERE summary_date = CURDATE()
|
|||
|
|
GROUP BY summary_date, summary_hour, location_code, gate_code, category
|
|||
|
|
HAVING duplicate_count > 1;
|
|||
|
|
|
|||
|
|
-- Harusnya tidak ada hasil (karena ada PRIMARY KEY)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## Kesimpulan
|
|||
|
|
|
|||
|
|
✅ **Manual execute cron AKAN mengupdate data**
|
|||
|
|
- Data lama diganti dengan hasil rekap ulang
|
|||
|
|
- Bukan ditambah, tapi diganti
|
|||
|
|
- Memastikan data summary selalu sesuai dengan entry_events
|
|||
|
|
|
|||
|
|
✅ **Cara test:**
|
|||
|
|
1. Cek data sebelum execute
|
|||
|
|
2. Execute cron manual
|
|||
|
|
3. Cek data setelah execute
|
|||
|
|
4. Verifikasi dengan entry_events
|
|||
|
|
|
|||
|
|
✅ **Expected behavior:**
|
|||
|
|
- Data ter-update sesuai dengan entry_events
|
|||
|
|
- Nilai lama diganti dengan nilai baru
|
|||
|
|
- Konsisten dan akurat
|
|||
|
|
|