Skip to content

Commit

Permalink
clean data
Browse files Browse the repository at this point in the history
  • Loading branch information
paproc committed Dec 22, 2024
1 parent e2bd84a commit 7cc0e22
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 82 deletions.
59 changes: 0 additions & 59 deletions app/Components/ResultsVyfuk/results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ function CategoryResults({ submits, tasks, isAllCategories = false }: { submits:
}
};

// bool if s4-6 should be shown
const showS4To6 = Object.values(tasks).some((tasksInSeries, index) => index >= 3 && tasksInSeries.length > 0);

// calculate the sumOneToThree and sumFourToSix for each contestant
for (const contestant of submits) {
let sumOneToThree = 0;
Expand Down Expand Up @@ -269,42 +266,6 @@ function CategoryResults({ submits, tasks, isAllCategories = false }: { submits:
</React.Fragment>
);
})}
<th
className={`centered-cell clickable-header ${hoveredColumn === 's1-3' ? 'hovered' : ''}`}
onClick={() => toggleSort('s1-3')}
onMouseEnter={() => handleMouseEnter('s1-3')}
onMouseLeave={handleMouseLeave}
>
s&#8288;1&#8288;-&#8288;3<br />
{sortColumn === 's1-3' ? (
<span style={{ color: 'black' }}>
{sortDirection === 'asc' ? '↓' : '↑'}
</span>
) : (
<span className="inactive-arrow">
</span>
)}
</th>
{showS4To6 && (
<th
className={`centered-cell clickable-header ${hoveredColumn === 's4-6' ? 'hovered' : ''}`}
onClick={() => toggleSort('s4-6')}
onMouseEnter={() => handleMouseEnter('s4-6')}
onMouseLeave={handleMouseLeave}
>
s&#8288;4&#8288;-&#8288;6<br />
{sortColumn === 's4-6' ? (
<span style={{ color: 'black' }}>
{sortDirection === 'asc' ? '↓' : '↑'}
</span>
) : (
<span className="inactive-arrow">
</span>
)}
</th>
)}
<th
className={`centered-cell clickable-header ${hoveredColumn === 'Category Rank' || hoveredColumn === 'Total Points' ? 'hovered' : ''}`}
onClick={() => toggleSort('Category Rank')}
Expand Down Expand Up @@ -345,18 +306,6 @@ function CategoryResults({ submits, tasks, isAllCategories = false }: { submits:
</React.Fragment>
);
})}
<th className="centered-cell">
{Object.values(tasks).filter((tasksInSeries, index) => index < 3).reduce((totalSum, tasksInSeries) =>
totalSum + tasksInSeries.reduce((seriesSum, task) => seriesSum + (typeof task.points === 'number' ? task.points : 0), 0), 0
)}
</th>
{showS4To6 && (
<th className="centered-cell">
{Object.values(tasks).filter((tasksInSeries, index) => index >= 3).reduce((totalSum, tasksInSeries) =>
totalSum + tasksInSeries.reduce((seriesSum, task) => seriesSum + (typeof task.points === 'number' ? task.points : 0), 0), 0
)}
</th>
)}
<th className="centered-cell">
{Object.values(tasks).reduce((totalSum, tasksInSeries) =>
totalSum + tasksInSeries.reduce((seriesSum, task) => seriesSum + (typeof task.points === 'number' ? task.points : 0), 0), 0
Expand Down Expand Up @@ -386,14 +335,6 @@ function CategoryResults({ submits, tasks, isAllCategories = false }: { submits:
<td>{contestant.contestant.name}</td>
<td>{contestant.contestant.school}</td>
{seriesContainers}
<td className="centered-cell">
<strong>{contestant.sunOneToThree}</strong>
</td>
{showS4To6 && (
<td className="centered-cell">
<strong>{contestant.sumFourToSix}</strong>
</td>
)}
<td className="centered-cell">
<strong>{contestant.sum}</strong>
</td>
Expand Down
33 changes: 22 additions & 11 deletions app/Modules/Core/ContestPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
use App\Models\Downloader\DummyService;
use App\Models\Downloader\FKSDBDownloader;
use Fykosak\FKSDBDownloaderCore\Requests\SeriesResultsRequest;
use Nette\Caching\Cache;
use Nette\Caching\Storage;
use Nette\Utils\DateTime;

abstract class ContestPresenter extends BasePresenter
{
private readonly DummyService $dummyService;
protected readonly FKSDBDownloader $downloader;
protected readonly Cache $cache;

final public function inject(FKSDBDownloader $downloader): void
{
Expand All @@ -27,6 +30,10 @@ public function injectDummyService(DummyService $dummyService): void
{
$this->dummyService = $dummyService;
}
public function injectCache(Storage $storage): void
{
$this->cache = new Cache($storage);
}

protected function beforeRender(): void
{
Expand All @@ -52,22 +59,26 @@ public function getCurrentYear(): ?ContestYearModel

public function getBodyYear(): ?ContestYearModel
{
foreach (array_reverse($this->getContest()->years) as $year) {
try {
$results = $this->downloader->download(new SeriesResultsRequest($this->getContestId(), $year->year));
foreach ($results["submits"] as $y) {
foreach ($y as $c) {
foreach ($c["submits"] as $s) {
if ($s !== null) {
return $year;
return $this->cache->load("bodyYear", function () {
foreach (array_reverse($this->getContest()->years) as $year) {
try {
$results = $this->downloader->download(new SeriesResultsRequest($this->getContestId(), $year->year));
foreach ($results["submits"] as $y) {
foreach ($y as $c) {
foreach ($c["submits"] as $s) {
if ($s !== null) {
return $year;
}
}
}
}
} finally {
}
} finally {
}
}
return null;
return null;
}, [
Cache::Expire => '1 day',
]);
}

abstract public function getContestId(): int;
Expand Down
5 changes: 1 addition & 4 deletions app/Modules/Vyfuk/DefaultModule/EventsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@
use Nette\Application\BadRequestException;
use Nette\Application\Responses\CallbackResponse;
use Nette\Caching\Cache;
use Nette\Caching\Storage;

class EventsPresenter extends BasePresenter
{
protected Cache $cache;
protected EventService $eventService;

public function injectEventServicesAndCache(Storage $storage, EventService $eventService): void
public function injectEventServicesAndCache(EventService $eventService): void
{
$this->cache = new Cache($storage);
$this->eventService = $eventService;
}

Expand Down
45 changes: 43 additions & 2 deletions app/Modules/Vyfuk/DefaultModule/ResultsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,50 @@ class ResultsPresenter extends BasePresenter
public function renderDefault(): void
{
$year = $this->getBodyYear();
$year = $this->year ?? $year ? $year->year : 1;
$year = $this->year ?? ($year ? $year->year : 1);
$this->template->year = $year;
$this->template->contest = $this->getContest();
$this->template->results = $this->downloader->download(new SeriesResultsRequest($this->getContestId(), $year));
$results = $this->downloader->download(new SeriesResultsRequest($this->getContestId(), $year));
/* TODO dříve (v xml) byly i pro starší ročníky kategorie, nutno opravit v DB */
if (count($results["submits"]) == 1 && array_keys($results["submits"])[0] == "") {
$results["submits"] = ["VYFUK_9" => $results["submits"][""]];
}
$tasksHasResult = [];
foreach ($results['submits'] as $category => $contestants) {
foreach ($contestants as $key => $contestant) {
foreach ($contestant['submits'] as $taskId => $points) {
if ($points === null) {
unset($results['submits'][$category][$key]['submits'][$taskId]);
} else {
$tasksHasResult[$taskId] = true;
}
}
if (count($results['submits'][$category][$key]['submits']) == 0) {
unset($results['submits'][$category][$key]);
}
}
$results['submits'][$category] = array_values($results['submits'][$category]);
}
foreach ($results["tasks"] as $category => $series) {
foreach ($series as $serieNumber => $tasks) {
foreach ($tasks as $taskOrder => $task) {
if (!isset($tasksHasResult[$task['taskId']])) {
unset($results['tasks'][$category][$serieNumber][$taskOrder]);
}
}
if (count($results['tasks'][$category][$serieNumber]) == 0) {
unset($results['tasks'][$category][$serieNumber]);
} else {
$results['tasks'][$category][$serieNumber] = array_values($results['tasks'][$category][$serieNumber]);
}
}
}
$series = [];
foreach ($results["tasks"] as $s) {
$series=array_merge($series, array_keys($s));
}
$series = array_unique($series);
$this->template->results = $results;
$this->template->series = $series;
}
}
34 changes: 28 additions & 6 deletions app/Modules/Vyfuk/DefaultModule/templates/Results/default.latte
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
{varType int $year}
{varType App\Models\Downloader\ContestModel $contest}
{varType array $results}
{block title}Výsledky{/block}
{block main}
<div class="panel color-auto">
<h1 class="inner-container" style="color:red">TODO výsledky Výfuku</h1>
{block title}Výsledky {$year}. ročníku{/block}
{block content}
<div class="dropdown year-and-series-select">
<button class="btn btn-primary dropdown-toggle year-select-button" type="button" id="dropdownMenuButton"
data-bs-toggle="dropdown" aria-expanded="false">Vybrat ročník</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<div class="scrollable-menu">
<div class="series-container">
{foreach array_reverse($contest->years) as $contestYear}
{varType App\Models\Downloader\ContestYearModel $contestYear}
{if $contestYear->year > 0} {* Hide years for which data is not available *}
<a class="series-box full-width btn" href="{plink 'this' 'year'=>$contestYear->year}">
{switch $language->value}
{case 'cs'}{$contestYear->year}. ročník
({$contestYear->begin->format('Y')}/{$contestYear->end->format('y')})
{default}Year {$contestYear->year}
{/switch}
</a>
{/if}
{/foreach}
</div>
</div>
</div>
</div>
{do print_r($results)}
{/block}
{if $year < 7}
<p>Rozdělení do kategorií není dostupné pro starší ročníky.</p> {* TODO dříve (v xml) bylo, nutno opravit v DB *}
{/if}
<div id="contest-results" data-data="{json_encode($results)}"></div>
{/block}

0 comments on commit 7cc0e22

Please sign in to comment.