Compare commits

..

No commits in common. "dbcbaff3e159b80743d73408a28742e8c6621b0d" and "5fba83a8299e95453ac5fc985085406da25cca41" have entirely different histories.

3 changed files with 26 additions and 159 deletions

View File

@ -1,87 +1,45 @@
<?php
date_default_timezone_set('UTC');
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-10-08T08:07:32+01");
$GLOBALS['start_time'] = DateTime::createFromFormat(DateTime::ISO8601, "2024-02-12T15:07:32+01");
$GLOBALS['number_of_controls'] = 3;
//declare(strict_types=1);
class Runner
{
class Runner {
public int $id;
public string $name;
public array $splits;
function __construct($id, $name)
{
//echo($id);
//echo($name);
if ($id == null) {
$id = 0;
$name = "";
}
function __construct($id, $name) {
echo($id);
echo($name);
if ($id == null) {$id = 0; $name = "";}
$this->id = $id;
$this->name = $name;
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
$this->splits[$i] = false;
for($i = 0; $i<$$GLOBALS['number_of_controls']; $i++) {
array_push($this->splits, 0);
}
}
function set_split($control, $timestamp)
{
function set_split($control, $timestamp) {
$this->splits[$control] = $timestamp;
}
function get_control()
{
// Returns wich control the runner last passed
for ($i = 0; $i < count($this->splits); $i++) {
if (!is_object($this->splits[$i])) {
return $i-1;
}
}
return count($this->splits)-1;
}
}
//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++) {
if ($runnner_list[$i]->id == $id) {
if ($runnner_list[$i] == $id) {
return $runnner_list[$i];
}
}
return false;
}
function cmp(Runner $a, Runner $b) {
$a_control = $a->get_control();
$b_control = $b->get_control();
if ($a_control > $b_control){
return -1;
}
if ($a_control < $b_control){
return 1;
}
if ($a_control == -1) {
return 1;
}
if ($b_control == -1) {
return -1;
}
if ($a->splits[$a_control]->getTimestamp() < $b->splits[$b_control]->getTimestamp()){
return -1;
}
if ($a->splits[$a_control]->getTimestamp() > $b->splits[$b_control]->getTimestamp()){
return 1;
}
return 0;
}
$runners = [];
$csv_runners = file_get_contents("db.csv");
$csv_runners = str_getcsv($csv_runners, "\n");
//print_r($csv_runners);
for ($i = 1; $i < count($csv_runners); $i++) {
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]));
}
@ -89,7 +47,7 @@ for ($i = 1; $i < count($csv_runners); $i++) {
$timings = file_get_contents("passering.csv");
$timings = str_getcsv($timings, "\n");
for ($i = 0; $i < count($timings); $i++) {
for ($i=0; $i < count($timings); $i++) {
$line = str_getcsv($timings[$i]);
$time = DateTime::createFromFormat("Y-m-d\TH:i:sp", $line[2]);
@ -98,38 +56,22 @@ for ($i = 0; $i < count($timings); $i++) {
continue;
}
$runner = get_runner($runners, (int) $line[1]);
$runner = get_runner($runners, (int)$line[1]);
if (!$runner) {
//error
continue;
}
$runner->set_split($line[0]-1, $time);
$runner->set_split($line[0], $time);
}
usort($runners, "cmp");
echo(" <tr>
<th>#</th>
<th>Startnummer</th>
<th>Navn</th>
<th>1. matpost</th>
<th>2. matpost</th>
<th>Mål</th>
</tr>");
for ($i = 0; $i < count($runners); $i++) {
print_r($runners);
for ($i=0; $i < count($runners); $i++) {
$runner = $runners[$i];
$tid_1_mat = "";
if ($runner->splits[0] != false) {
// https://www.php.net/manual/en/class.dateinterval.php
$tid_1_mat = $GLOBALS['start_time']->diff($runner->splits[0])->format('%H:%I:%S');
}
$tid_2_mat = "";
if ($runner->splits[1] != false) {
$tid_2_mat = $GLOBALS['start_time']->diff($runner->splits[1])->format('%H:%I:%S');
}
$tid_maal = "";
if ($runner->splits[2] != false) {
$tid_maal = $GLOBALS['start_time']->diff($runner->splits[2])->format('%H:%I:%S');
}
echo ("<tr><td>". $i+1 .".</td><td>$runner->id</td><td>$runner->name</td><td>$tid_1_mat</td><td>$tid_2_mat</td><td>$tid_maal</td></tr>\n");
$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>");
}

View File

@ -1,15 +1,6 @@
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="UTF-8" />
<title>EKT</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
</head>
<body>
<h1>Løpende resultater kadaverløpet 2024</h1>
<h2>Vi tar forbehold om feil. Dette er ikke offisielle resultater</h2>
<table>
<tbody>
<?php
@ -18,16 +9,4 @@ include("get_table.php")
</tbody>
</table>
</body>
<script>
function update() {
const table = document.querySelector("table");
const myRequest = new Request(`get_table.php`);
fetch(myRequest)
.then((response) => response.text())
.then((text) => {
table.innerHTML = text;
});
}
setInterval(update, 5*1000)
</script>
</html>

View File

@ -1,59 +1,24 @@
<!DOCTYPE html>
<html lang="no">
<head>
<meta charset="UTF-8" />
<title>EKT</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="Elektronisk Kadaver Tidtakningssystem" />
<link rel="stylesheet" href="https://matcha.mizu.sh/matcha.css">
<style>
.passed {
background-color: #8ff0a4;
}
fieldset {
display: flex;
flex-wrap: wrap;
justify-content: space-evenly;
}
</style>
</head>
<body>
<fieldset>
<legend>Velg post</legend>
<label>
<input type="radio" name="post" value="1">
1. Matpost
</label>
<label>
<input type="radio" name="post" value="2">
2. Matpost
</label>
<label>
<input type="radio" name="post" value="3">
Mål
</label>
</fieldset>
<input id="search" type="number" class="form-control" onkeyup="filterTable()" placeholder="Søk">
<br>
<table>
<tbody id="runners">
</tbody>
</table>
</body>
<?php
$action = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
print_r($action)
?>
<script>
// Hvilken matpost vi er på:
var control = location.search[1];
var control = 1;
function register_runner(id) {
control = document.querySelector('input[name="post"]:checked').value;
let formData = new FormData();
formData.append(name= 'control', value=control);
formData.append(name= 'id', value=id);
@ -90,33 +55,14 @@ function create_row(id, name, passed) {
function create_rows(csv) {
csv = csv.split('\n')
rows = "<tr><th>#</th><th>Navn</th><th></th>";
rows = ""
for (i in csv) {
data = csv[i].split(",")
rows += create_row(data[0], data[1], false)
}
return rows
}
function filterTable() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("search");
filter = input.value.toUpperCase();
table = document.getElementById("runners");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td");
for (var j = 0; j < td.length; j++) {
txtValue = td[j].textContent || td[j].innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
break;
} else {
tr[i].style.display = "none";
}
}
}
}
function update_row(id, name, passed) {
row = document.getElementById(id)
row.innerHTML = create_row(id, name, passed)