45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php
|
|
|
|
include "include.php";
|
|
|
|
try {
|
|
// === LOAD SCORE FILE ===
|
|
$teamQuestionDates = loadScoreFile();
|
|
|
|
// === GENERATE GRAPH DATA ===
|
|
$period = new DatePeriod(new DateTime("2022-11-01"),
|
|
new DateInterval("P1D"),
|
|
new DateTime());
|
|
|
|
$labels = [];
|
|
foreach ($period as $date) {
|
|
$labels[] = $date->format("m-d");
|
|
}
|
|
|
|
$datasets = [];
|
|
foreach (TEAMS as $team) {
|
|
$dataset = ['label' => $team, 'data' => [], 'borderColor' => TEAM_COLORS[$team]];
|
|
|
|
$questionDates = $teamQuestionDates[$team];
|
|
$questions = array_keys($questionDates);
|
|
|
|
$score = 0;
|
|
$i = 0;
|
|
|
|
foreach ($period as $date) {
|
|
while ($i < count($questionDates) && $questionDates[$questions[$i]] <= $date->format("Y-m-d")) {
|
|
$score += QUESTION_POINTS[$questions[$i]];
|
|
$i++;
|
|
}
|
|
$dataset['data'][] = $score;
|
|
}
|
|
|
|
$datasets[] = $dataset;
|
|
}
|
|
|
|
echo json_encode(['labels' => $labels, 'datasets' => $datasets]);
|
|
} catch (Exception $e) {
|
|
echo json_encode(['error' => $e->getMessage()]);
|
|
}
|
|
|
|
?>
|