Initial commit

This commit is contained in:
Zdeněk Burda
2026-01-09 21:26:40 +01:00
parent e83aec6dca
commit 41e3ce6f25
404 changed files with 61250 additions and 28 deletions

View File

@@ -0,0 +1,160 @@
<?php
namespace Tests\Feature\Evaluation;
use App\Jobs\AggregateLogResultsJob;
use App\Models\LogResult;
use App\Models\QsoResult;
use App\Models\WorkingQso;
use Carbon\Carbon;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AggregateLogResultsJobTest extends TestCase
{
use RefreshDatabase;
private function createQso(int $runId, int $logId, int $bandId, Carbon $ts, int $points): int
{
$logQso = $this->createLogQso(['log_id' => $logId]);
$this->createQsoResult([
'evaluation_run_id' => $runId,
'log_qso_id' => $logQso->id,
'is_valid' => true,
'points' => $points,
]);
WorkingQso::create([
'evaluation_run_id' => $runId,
'log_qso_id' => $logQso->id,
'log_id' => $logId,
'ts_utc' => $ts,
'band_id' => $bandId,
'call_norm' => 'OK1AAA',
'rcall_norm' => 'OK1BBB',
'loc_norm' => 'JN00AA',
'rloc_norm' => 'JN00AA',
]);
return $logQso->id;
}
public function test_aggregate_applies_operating_window_for_6h(): void
{
$ruleSet = $this->createRuleSet([
'use_multipliers' => false,
'multiplier_type' => 'NONE',
'multiplier_scope' => 'OVERALL',
'multiplier_source' => 'VALID_ONLY',
'operating_window_mode' => 'BEST_CONTIGUOUS',
'operating_window_hours' => 6,
]);
$round = $this->createRound();
$log = $this->createLog(['round_id' => $round->id]);
$run = $this->createEvaluationRun([
'round_id' => $round->id,
'rule_set_id' => $ruleSet->id,
]);
$band = $this->createBand();
$t0 = Carbon::create(2025, 1, 1, 0, 0, 0, 'UTC');
$t1 = Carbon::create(2025, 1, 1, 1, 0, 0, 'UTC');
$t2 = Carbon::create(2025, 1, 1, 7, 0, 0, 'UTC');
$t3 = Carbon::create(2025, 1, 1, 8, 0, 0, 'UTC');
$firstA = $this->createQso($run->id, $log->id, $band->id, $t0, 10);
$firstB = $this->createQso($run->id, $log->id, $band->id, $t1, 10);
$secondA = $this->createQso($run->id, $log->id, $band->id, $t2, 10);
$secondB = $this->createQso($run->id, $log->id, $band->id, $t3, 10);
$this->createLogResult([
'evaluation_run_id' => $run->id,
'log_id' => $log->id,
'sixhr_category' => true,
'status' => 'OK',
]);
(new AggregateLogResultsJob($run->id, $log->id))->handle();
$result = LogResult::where('evaluation_run_id', $run->id)
->where('log_id', $log->id)
->first();
$this->assertNotNull($result);
$this->assertSame(40, $result->official_score);
$this->assertSame($t0->toDateTimeString(), $result->operating_window_start_utc?->toDateTimeString());
$this->assertSame($t1->toDateTimeString(), $result->operating_window_end_utc?->toDateTimeString());
$this->assertSame($t2->toDateTimeString(), $result->operating_window_2_start_utc?->toDateTimeString());
$this->assertSame($t3->toDateTimeString(), $result->operating_window_2_end_utc?->toDateTimeString());
$this->assertSame(6, $result->operating_window_hours);
$this->assertSame(4, $result->operating_window_qso_count);
$included = QsoResult::where('evaluation_run_id', $run->id)
->whereIn('log_qso_id', [$firstA, $firstB, $secondA, $secondB])
->pluck('is_operating_window_excluded')
->all();
$this->assertSame([false, false, false, false], $included);
$excludedCount = QsoResult::where('evaluation_run_id', $run->id)
->where('is_operating_window_excluded', true)
->count();
$this->assertSame(0, $excludedCount);
}
public function test_aggregate_keeps_all_qso_for_non_6h(): void
{
$ruleSet = $this->createRuleSet([
'use_multipliers' => false,
'multiplier_type' => 'NONE',
'multiplier_scope' => 'OVERALL',
'multiplier_source' => 'VALID_ONLY',
'operating_window_mode' => 'BEST_CONTIGUOUS',
'operating_window_hours' => 6,
]);
$round = $this->createRound();
$log = $this->createLog(['round_id' => $round->id]);
$run = $this->createEvaluationRun([
'round_id' => $round->id,
'rule_set_id' => $ruleSet->id,
]);
$band = $this->createBand();
$t0 = Carbon::create(2025, 1, 1, 0, 0, 0, 'UTC');
$t1 = Carbon::create(2025, 1, 1, 1, 0, 0, 'UTC');
$t2 = Carbon::create(2025, 1, 1, 7, 0, 0, 'UTC');
$t3 = Carbon::create(2025, 1, 1, 8, 0, 0, 'UTC');
$this->createQso($run->id, $log->id, $band->id, $t0, 10);
$this->createQso($run->id, $log->id, $band->id, $t1, 10);
$this->createQso($run->id, $log->id, $band->id, $t2, 10);
$this->createQso($run->id, $log->id, $band->id, $t3, 10);
$this->createLogResult([
'evaluation_run_id' => $run->id,
'log_id' => $log->id,
'sixhr_category' => false,
'status' => 'OK',
]);
(new AggregateLogResultsJob($run->id, $log->id))->handle();
$result = LogResult::where('evaluation_run_id', $run->id)
->where('log_id', $log->id)
->first();
$this->assertNotNull($result);
$this->assertSame(40, $result->official_score);
$this->assertNull($result->operating_window_start_utc);
$this->assertNull($result->operating_window_end_utc);
$this->assertNull($result->operating_window_2_start_utc);
$this->assertNull($result->operating_window_2_end_utc);
$this->assertNull($result->operating_window_hours);
$this->assertNull($result->operating_window_qso_count);
$excludedCount = QsoResult::where('evaluation_run_id', $run->id)
->where('is_operating_window_excluded', true)
->count();
$this->assertSame(0, $excludedCount);
}
}