Compare commits
5 Commits
5fba83a829
...
dbcbaff3e1
Author | SHA1 | Date | |
---|---|---|---|
|
dbcbaff3e1 | ||
|
0fc2aa5f05 | ||
|
6c5adf546c | ||
|
426ebd189c | ||
|
86d3ebed7e |
100
get_table.php
100
get_table.php
@ -1,45 +1,87 @@
|
||||
<?php
|
||||
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;
|
||||
|
||||
//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++) {
|
||||
array_push($this->splits, 0);
|
||||
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
|
||||
$this->splits[$i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
if ($runnner_list[$i]->id == $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=0; $i < count($csv_runners); $i++) {
|
||||
//print_r($csv_runners);
|
||||
for ($i = 1; $i < count($csv_runners); $i++) {
|
||||
$line = str_getcsv($csv_runners[$i]);
|
||||
array_push($runners, new Runner($line[0], $line[1]));
|
||||
}
|
||||
@ -62,16 +104,32 @@ for ($i=0; $i < count($timings); $i++) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$runner->set_split($line[0], $time);
|
||||
$runner->set_split($line[0]-1, $time);
|
||||
}
|
||||
|
||||
print_r($runners);
|
||||
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++) {
|
||||
$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>");
|
||||
$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");
|
||||
}
|
21
index.php
21
index.php
@ -1,6 +1,15 @@
|
||||
<!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
|
||||
@ -9,4 +18,16 @@ 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>
|
||||
|
@ -1,24 +1,59 @@
|
||||
<!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 = 1;
|
||||
var control = location.search[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);
|
||||
@ -55,14 +90,33 @@ function create_row(id, name, passed) {
|
||||
|
||||
function create_rows(csv) {
|
||||
csv = csv.split('\n')
|
||||
rows = ""
|
||||
rows = "<tr><th>#</th><th>Navn</th><th></th>";
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user