-
Notifications
You must be signed in to change notification settings - Fork 8
fix(dashboard): trend grafigi ay sonunda 7-11 aya dusuyordu #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ersinkoc
wants to merge
3
commits into
CodeByPinar:main
from
ersinkoc:fix/dashboard-trend-month-window
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| <?php | ||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * RiskOps - Ay bazli trend pencereleri regresyon testi | ||
| * Calistirma: php tools/trend_months_test.php | ||
| * | ||
| * Bagimlilik YOK: veritabani ve bootstrap gerekmez, yalnizca | ||
| * includes/functions.php icindeki recent_months() test edilir. | ||
| * | ||
| * Kapsanan tuketiciler: | ||
| * api/dashboard_charts.php (12 aylik trend penceresi) | ||
| * reports/executive_summary.php (6 aylik "Son 6 Ay" penceresi) | ||
| * | ||
| * REGRESYON ARKAPLANI: pencereler bir zamanlar | ||
| * date('Y-m', strtotime("-{$i} month")) | ||
| * ile kuruluyordu. strtotime ay aritmetiginde gun tasmasini kirmaz; | ||
| * ayin 29-31'inde hedef ayda o gun yoksa sonuc bir SONRAKI aya tasiyor, | ||
| * ayni 'Y-m' anahtari iki kez uretiliyor ve pencere kuculuyordu | ||
| * (dashboard 7-11 aya, yonetici ozeti 3-5 aya dusuyordu; kayip | ||
| * aylarin riskleri hic sayilmiyordu). | ||
| */ | ||
|
|
||
| if (PHP_SAPI !== 'cli') { | ||
| http_response_code(403); | ||
| exit('CLI only.'); | ||
| } | ||
|
|
||
| require_once __DIR__ . '/../includes/functions.php'; | ||
|
|
||
| $PASS = 0; | ||
| $FAIL = 0; | ||
|
|
||
| function check(string $label, bool $ok, string $detail = ''): void | ||
| { | ||
| global $PASS, $FAIL; | ||
| if ($ok) { | ||
| $PASS++; | ||
| printf(" [ OK ] %-52s %s\n", $label, $detail); | ||
| } else { | ||
| $FAIL++; | ||
| printf(" [FAIL] %-52s %s\n", $label, $detail); | ||
| } | ||
| } | ||
|
|
||
| function section(string $title): void | ||
| { | ||
| echo "\n" . str_repeat('-', 72) . "\n " . $title . "\n" . str_repeat('-', 72) . "\n"; | ||
| } | ||
|
|
||
| /** | ||
| * ORACLE — beklenen ay listesi mktime() ay normalizasyonuyla hesaplanir | ||
| * (recent_months icindeki kodun bagimsizi). | ||
| */ | ||
| function expected_months(int $baseTs, int $count): array | ||
| { | ||
| [$y, $m] = array_map('intval', explode('-', date('Y-m', $baseTs))); | ||
| $out = []; | ||
| for ($k = $count - 1; $k >= 0; $k--) { | ||
| $out[] = date('Y-m', mktime(1, 1, 1, $m - $k, 1, $y)); | ||
| } | ||
| return $out; | ||
| } | ||
|
|
||
| echo "\n=============== Trend Month Window Regression Test ==============="; | ||
|
|
||
| /* ------------------------------------------------------------------ */ | ||
| section('1. Ay sonu gunlerinde pencere (regresyon)'); | ||
| /* ------------------------------------------------------------------ */ | ||
|
|
||
| // Hatali davranisin kanitlandigi gunler: 29-31 (hedef ay kisa ise tasma). | ||
| $probes = [ | ||
| '2026-05-31', '2026-03-31', '2026-08-31', '2025-12-31', | ||
| '2026-01-31', '2026-01-30', '2024-02-29', '2026-02-28', | ||
| '2026-10-31', '2026-04-30', '2025-11-30', '2026-12-31', | ||
| ]; | ||
|
|
||
| foreach ($probes as $d) { | ||
| $bts = strtotime($d . ' 12:00:00'); | ||
| $got = recent_months(12, $bts); | ||
| check( | ||
| "12 ay: {$d}", | ||
| $got === expected_months($bts, 12) && count(array_unique($got)) === 12, | ||
| count($got) . ' ay' | ||
| ); | ||
| } | ||
|
|
||
| /* ------------------------------------------------------------------ */ | ||
| section('2. Sinir ve ikincil dallar'); | ||
| /* ------------------------------------------------------------------ */ | ||
|
|
||
| $now = time(); | ||
| check('bugun (varsayilan taban): 12 ay', | ||
| recent_months(12) === expected_months($now, 12)); | ||
| check('taban null acik gecilirse ayni sonuc', | ||
| recent_months(12, null) === recent_months(12)); | ||
| check('count=1 yalnizca bulunulan ay', | ||
| recent_months(1, $now) === [date('Y-m', $now)]); | ||
| check('count=0 bos liste', recent_months(0, $now) === []); | ||
| check('count negatif bos liste', recent_months(-3, $now) === []); | ||
| check('count=13 yil sinirini asar', | ||
| recent_months(13, strtotime('2026-01-15 12:00:00')) | ||
| === expected_months(strtotime('2026-01-15 12:00:00'), 13)); | ||
| check('count=6 yonetici ozeti penceresi (2026-05-31 taban)', | ||
| recent_months(6, strtotime('2026-05-31 12:00:00')) | ||
| === expected_months(strtotime('2026-05-31 12:00:00'), 6)); | ||
| check('anahtarlar eskiden yeniye sirali', | ||
| recent_months(12, $now) === array_values(array_sort(recent_months(12, $now)))); | ||
|
|
||
| /* SQL :since degeri: en eski ayin 1'i (api/dashboard_charts.php tuketimi) */ | ||
| $keys = recent_months(12, strtotime('2026-05-31 12:00:00')); | ||
| check('since = en eski ayin 1\'i (2026-05-31 taban)', | ||
| $keys[0] . '-01' === '2025-06-01', $keys[0] . '-01'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This Prompt for AI agents |
||
|
|
||
| /* ------------------------------------------------------------------ */ | ||
| section('3. Uc nokta baglantisi'); | ||
| /* ------------------------------------------------------------------ */ | ||
|
|
||
| $src = (string)file_get_contents(__DIR__ . '/../api/dashboard_charts.php'); | ||
| check('api/dashboard_charts.php recent_months() kullaniyor', | ||
| str_contains($src, 'recent_months(12)')); | ||
| check('dashboard bozuk strtotime("-N month") ifadesi kaldirildi', | ||
| !str_contains($src, 'strtotime("-{')); | ||
|
|
||
| $srcExec = (string)file_get_contents(__DIR__ . '/../reports/executive_summary.php'); | ||
| check('reports/executive_summary.php recent_months() kullaniyor', | ||
| str_contains($srcExec, 'recent_months(6)')); | ||
| check('yonetici ozeti bozuk strtotime ay ifadeleri kaldirildi', | ||
| !str_contains($srcExec, 'strtotime("-{') && !str_contains($srcExec, "strtotime('-5 month')")); | ||
|
|
||
| /* ------------------------------------------------------------------ */ | ||
|
|
||
| echo "\n" . str_repeat('-', 72) . "\n"; | ||
| printf("Sonuc: %d OK, %d FAIL\n", $PASS, $FAIL); | ||
| if ($FAIL > 0) { | ||
| echo "TREND MONTH WINDOW TEST: FAIL\n"; | ||
| exit(1); | ||
| } | ||
| echo "TREND MONTH WINDOW TEST: PASS\n"; | ||
| exit(0); | ||
|
|
||
| /** Kucukten buyuge siralar (strcmp) — 'Y-m' anahtarlari icin yeterli. */ | ||
| function array_sort(array $a): array | ||
| { | ||
| usort($a, static fn(string $x, string $y) => strcmp($x, $y)); | ||
| return $a; | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: At a month rollover,
recent_months(12)can read a later month than$now, making this regression test fail intermittently; the null/default check has the same race. Use one stable base timestamp for the assertions, or explicitly allow the bounded rollover case.Prompt for AI agents