La til strekktider i tabellen

This commit is contained in:
Trygve 2024-10-08 12:55:19 +02:00
parent 5fba83a829
commit 86d3ebed7e
2 changed files with 46 additions and 24 deletions

View File

@ -1,34 +1,41 @@
<?php <?php
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-02-12T15:07:32+01"); $GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-10-08T08:07:32+01");
$GLOBALS['number_of_controls'] = 3; $GLOBALS['number_of_controls'] = 3;
//declare(strict_types=1); //declare(strict_types=1);
class Runner { class Runner
{
public int $id; public int $id;
public string $name; public string $name;
public array $splits; public array $splits;
function __construct($id, $name) { function __construct($id, $name)
echo($id); {
echo($name); //echo($id);
if ($id == null) {$id = 0; $name = "";} //echo($name);
if ($id == null) {
$id = 0;
$name = "";
}
$this->id = $id; $this->id = $id;
$this->name = $name; $this->name = $name;
for($i = 0; $i<$$GLOBALS['number_of_controls']; $i++) { for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
array_push($this->splits, 0); $this->splits[$i] = false;
} }
} }
function set_split($control, $timestamp) { function set_split($control, $timestamp)
{
$this->splits[$control] = $timestamp; $this->splits[$control] = $timestamp;
} }
} }
//find runner by id in list of Runner objects //find runner by id in list of Runner objects
function get_runner($runnner_list, int $id) { function get_runner($runnner_list, int $id)
{
for ($i = 0; $i < count($runnner_list); $i++) { for ($i = 0; $i < count($runnner_list); $i++) {
if ($runnner_list[$i] == $id) { if ($runnner_list[$i]->id == $id) {
return $runnner_list[$i]; return $runnner_list[$i];
} }
} }
@ -38,8 +45,8 @@ function get_runner($runnner_list, int $id) {
$runners = []; $runners = [];
$csv_runners = file_get_contents("db.csv"); $csv_runners = file_get_contents("db.csv");
$csv_runners = str_getcsv($csv_runners, "\n"); $csv_runners = str_getcsv($csv_runners, "\n");
print_r($csv_runners); //print_r($csv_runners);
for ($i=0; $i < count($csv_runners); $i++) { for ($i = 1; $i < count($csv_runners); $i++) {
$line = str_getcsv($csv_runners[$i]); $line = str_getcsv($csv_runners[$i]);
array_push($runners, new Runner($line[0], $line[1])); array_push($runners, new Runner($line[0], $line[1]));
} }
@ -47,7 +54,7 @@ for ($i=0; $i < count($csv_runners); $i++) {
$timings = file_get_contents("passering.csv"); $timings = file_get_contents("passering.csv");
$timings = str_getcsv($timings, "\n"); $timings = str_getcsv($timings, "\n");
for ($i=0; $i < count($timings); $i++) { for ($i = 0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]); $line = str_getcsv($timings[$i]);
$time = DateTime::createFromFormat("Y-m-d\TH:i:sp", $line[2]); $time = DateTime::createFromFormat("Y-m-d\TH:i:sp", $line[2]);
@ -56,22 +63,32 @@ for ($i=0; $i < count($timings); $i++) {
continue; continue;
} }
$runner = get_runner($runners, (int)$line[1]); $runner = get_runner($runners, (int) $line[1]);
if (!$runner) { if (!$runner) {
//error //error
continue; continue;
} }
$runner->set_split($line[0], $time); $runner->set_split($line[0]-1, $time);
} }
print_r($runners); //print_r($runners);
for ($i=0; $i < count($runners); $i++) { for ($i = 0; $i < count($runners); $i++) {
$runner = $runners[$i]; $runner = $runners[$i];
$times = ""; $tid_1_mat = "";
//for ($i= 0; $i < count($runner[2]); $i++) { if ($runner->splits[0] != false) {
//echo("". $runner[2][$i][1] ."\n"); // https://www.php.net/manual/en/class.dateinterval.php
//} $tid_1_mat = $GLOBALS['start_time']->diff($runner->splits[0])->format('%H:%I:%S');
}
echo("<tr><td>$runner->id</td><td>$runner->name</td></tr>"); $tid_2_mat = "";
if ($runner->splits[1] != false) {
// https://www.php.net/manual/en/class.dateinterval.php
$tid_2_mat = $GLOBALS['start_time']->diff($runner->splits[1])->format('%H:%I:%S');
}
$tid_maal = "";
if ($runner->splits[2] != false) {
// https://www.php.net/manual/en/class.dateinterval.php
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
}
echo ("<tr><td>$runner->id</td><td>$runner->name</td><td>$tid_1_mat</td><td>$tid_2_mat</td><td>$tid_maal</td></tr>");
} }

View File

@ -1,6 +1,11 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="no"> <html lang="no">
<head>
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
</head>
<body> <body>
<h1>Løpende resultater kadaverløpet 2024</h1>
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
<table> <table>
<tbody> <tbody>
<?php <?php