Lagde en løperklasse

This commit is contained in:
Trygve 2024-02-17 19:23:27 +01:00
parent acd4823dac
commit 5fba83a829

View File

@ -1,32 +1,77 @@
<?php <?php
//TODO: les fra config istedet: date_default_timezone_set('UTC');
$start_time = DateTime::createFromFormat(DateTime::ISO8601, "2024-02-12T15:07:32+01"); $GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-02-12T15:07:32+01");
echo(date_timestamp_get($start_time)); $GLOBALS['number_of_controls'] = 3;
$db = file_get_contents("db.csv"); //declare(strict_types=1);
$db = str_getcsv($db, "\n"); class Runner {
public int $id;
public string $name;
public array $splits;
$timings = file_get_contents("passering.csv"); function __construct($id, $name) {
$timings = str_getcsv($timings, "\n"); echo($id);
echo($name);
//add the time diff to each runner if ($id == null) {$id = 0; $name = "";}
for ($i = 0; $i < count($timings); $i++) { $this->id = $id;
$line = str_getcsv($timings[$i]); $this->name = $name;
$control = $line[0]; for($i = 0; $i<$$GLOBALS['number_of_controls']; $i++) {
$id = $line[1]; array_push($this->splits, 0);
$time = DateTime::createFromFormat(DateTime::ISO8601, $line[2]); }
if (!in_array($id, $db)) {
continue;
//TODO: Burde logge dette ellerno
} }
arra
array_search($id, $db); function set_split($control, $timestamp) {
$this->splits[$control] = $timestamp;
}
}
//find runner by id in list of Runner objects
function get_runner($runnner_list, int $id) {
for ($i = 0; $i < count($runnner_list); $i++) {
if ($runnner_list[$i] == $id) {
return $runnner_list[$i];
}
}
return false;
}
$runners = [];
$csv_runners = file_get_contents("db.csv");
$csv_runners = str_getcsv($csv_runners, "\n");
print_r($csv_runners);
for ($i=0; $i < count($csv_runners); $i++) {
$line = str_getcsv($csv_runners[$i]);
array_push($runners, new Runner($line[0], $line[1]));
} }
for ($i=0; $i < count($db); $i++) { $timings = file_get_contents("passering.csv");
$runner = str_getcsv($db[$i]); $timings = str_getcsv($timings, "\n");
echo("<tr><td>$runner[0]</td><td>$runner[1]</td></tr>"); for ($i=0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]);
$time = DateTime::createFromFormat("Y-m-d\TH:i:sp", $line[2]);
if (!$time) {
//error
continue;
}
$runner = get_runner($runners, (int)$line[1]);
if (!$runner) {
//error
continue;
}
$runner->set_split($line[0], $time);
}
print_r($runners);
for ($i=0; $i < count($runners); $i++) {
$runner = $runners[$i];
$times = "";
//for ($i= 0; $i < count($runner[2]); $i++) {
//echo("". $runner[2][$i][1] ."\n");
//}
echo("<tr><td>$runner->id</td><td>$runner->name</td></tr>");
} }