Compare commits
5 Commits
5fba83a829
...
dbcbaff3e1
Author | SHA1 | Date | |
---|---|---|---|
|
dbcbaff3e1 | ||
|
0fc2aa5f05 | ||
|
6c5adf546c | ||
|
426ebd189c | ||
|
86d3ebed7e |
106
get_table.php
106
get_table.php
@ -1,45 +1,87 @@
|
|||||||
<?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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
//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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
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 = [];
|
$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 +89,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 +98,38 @@ 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);
|
usort($runners, "cmp");
|
||||||
for ($i=0; $i < count($runners); $i++) {
|
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];
|
$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) {
|
||||||
|
$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>
|
<!DOCTYPE html>
|
||||||
<html lang="no">
|
<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>
|
<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
|
||||||
@ -9,4 +18,16 @@ include("get_table.php")
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</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>
|
</html>
|
||||||
|
@ -1,24 +1,59 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="no">
|
<html lang="no">
|
||||||
<head>
|
<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>
|
<style>
|
||||||
.passed {
|
.passed {
|
||||||
background-color: #8ff0a4;
|
background-color: #8ff0a4;
|
||||||
}
|
}
|
||||||
|
fieldset {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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>
|
<table>
|
||||||
<tbody id="runners">
|
<tbody id="runners">
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
|
<?php
|
||||||
|
$action = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
|
||||||
|
print_r($action)
|
||||||
|
?>
|
||||||
<script>
|
<script>
|
||||||
// Hvilken matpost vi er på:
|
// Hvilken matpost vi er på:
|
||||||
var control = 1;
|
var control = location.search[1];
|
||||||
|
|
||||||
function register_runner(id) {
|
function register_runner(id) {
|
||||||
|
control = document.querySelector('input[name="post"]:checked').value;
|
||||||
let formData = new FormData();
|
let formData = new FormData();
|
||||||
formData.append(name= 'control', value=control);
|
formData.append(name= 'control', value=control);
|
||||||
formData.append(name= 'id', value=id);
|
formData.append(name= 'id', value=id);
|
||||||
@ -55,14 +90,33 @@ function create_row(id, name, passed) {
|
|||||||
|
|
||||||
function create_rows(csv) {
|
function create_rows(csv) {
|
||||||
csv = csv.split('\n')
|
csv = csv.split('\n')
|
||||||
rows = ""
|
rows = "<tr><th>#</th><th>Navn</th><th></th>";
|
||||||
for (i in csv) {
|
for (i in csv) {
|
||||||
data = csv[i].split(",")
|
data = csv[i].split(",")
|
||||||
rows += create_row(data[0], data[1], false)
|
rows += create_row(data[0], data[1], false)
|
||||||
}
|
}
|
||||||
return rows
|
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) {
|
function update_row(id, name, passed) {
|
||||||
row = document.getElementById(id)
|
row = document.getElementById(id)
|
||||||
row.innerHTML = create_row(id, name, passed)
|
row.innerHTML = create_row(id, name, passed)
|
||||||
|
Loading…
Reference in New Issue
Block a user