Flytta import av løpere og strekktider til egen php fil
This commit is contained in:
parent
16b98e0b9f
commit
544517b3d8
126
import_runners.php
Normal file
126
import_runners.php
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
<?php
|
||||||
|
class Runner
|
||||||
|
{
|
||||||
|
public int $id;
|
||||||
|
public string $name;
|
||||||
|
public string $club;
|
||||||
|
public string $course;
|
||||||
|
public string $email;
|
||||||
|
public string $phone;
|
||||||
|
public array $splits;
|
||||||
|
|
||||||
|
function __construct($id, $name, $club, $course, $email, $phone)
|
||||||
|
{
|
||||||
|
if ($id == null) {
|
||||||
|
$id = 0;
|
||||||
|
$name = "";
|
||||||
|
}
|
||||||
|
$this->id = $id;
|
||||||
|
$this->name = $name;
|
||||||
|
$this->club = $club;
|
||||||
|
$this->course = $course;
|
||||||
|
$this->email = $email;
|
||||||
|
$this->phone = $phone;
|
||||||
|
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
|
||||||
|
$this->splits[$i] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_split($control, $timestamp)
|
||||||
|
{
|
||||||
|
$this->splits[$control] = $timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function get_control()
|
||||||
|
{ 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)
|
||||||
|
{
|
||||||
|
for ($i = 0; $i < count($runnner_list); $i++) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
function cmp_course(Runner $a, Runner $b) {
|
||||||
|
return strcmp($a->course, $b->course);
|
||||||
|
}
|
||||||
|
|
||||||
|
function filter_runners(Runner $runner, $id) {
|
||||||
|
if ($runner->id == $id) {
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function time_diff(DateTime $date_1, DateTime $date_2) {
|
||||||
|
return $date_2->getTimestamp() - $date_1->getTimestamp();
|
||||||
|
}
|
||||||
|
|
||||||
|
function read_runners_from_csv(){
|
||||||
|
$runners = [];
|
||||||
|
$csv_runners = file_get_contents("data/db.csv");
|
||||||
|
$csv_runners = str_getcsv($csv_runners, "\n");
|
||||||
|
for ($i = 1; $i < count($csv_runners); $i++) {
|
||||||
|
$line = str_getcsv($csv_runners[$i], ";");
|
||||||
|
array_push($runners, new Runner($line[0], $line[2], $line[5], $line[6], $line[3], $line[4]));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$timings = file_get_contents("data/passering.csv");
|
||||||
|
$timings = str_getcsv($timings, "\n");
|
||||||
|
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]-1, $time);
|
||||||
|
}
|
||||||
|
return $runners;
|
||||||
|
}
|
||||||
124
table.php
124
table.php
@ -18,128 +18,8 @@ if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
class Runner
|
|
||||||
{
|
|
||||||
public int $id;
|
|
||||||
public string $name;
|
|
||||||
public string $club;
|
|
||||||
public string $course;
|
|
||||||
public string $email;
|
|
||||||
public string $phone;
|
|
||||||
public array $splits;
|
|
||||||
|
|
||||||
function __construct($id, $name, $club, $course, $email, $phone)
|
include("import_runners.php");
|
||||||
{
|
|
||||||
if ($id == null) {
|
|
||||||
$id = 0;
|
|
||||||
$name = "";
|
|
||||||
}
|
|
||||||
$this->id = $id;
|
|
||||||
$this->name = $name;
|
|
||||||
$this->club = $club;
|
|
||||||
$this->course = $course;
|
|
||||||
$this->email = $email;
|
|
||||||
$this->phone = $phone;
|
|
||||||
for ($i = 0; $i < $GLOBALS['number_of_controls']; $i++) {
|
|
||||||
$this->splits[$i] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_split($control, $timestamp)
|
|
||||||
{
|
|
||||||
$this->splits[$control] = $timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_control()
|
|
||||||
{ 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)
|
|
||||||
{
|
|
||||||
for ($i = 0; $i < count($runnner_list); $i++) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
function cmp_course(Runner $a, Runner $b) {
|
|
||||||
return strcmp($a->course, $b->course);
|
|
||||||
}
|
|
||||||
|
|
||||||
function filter_runners(Runner $runner, $id) {
|
|
||||||
if ($runner->id == $id) {
|
|
||||||
return True;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return False;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function time_diff(DateTime $date_1, DateTime $date_2) {
|
|
||||||
return $date_2->getTimestamp() - $date_1->getTimestamp();
|
|
||||||
}
|
|
||||||
|
|
||||||
$runners = [];
|
|
||||||
$csv_runners = file_get_contents("data/db.csv");
|
|
||||||
$csv_runners = str_getcsv($csv_runners, "\n");
|
|
||||||
for ($i = 1; $i < count($csv_runners); $i++) {
|
|
||||||
$line = str_getcsv($csv_runners[$i], ";");
|
|
||||||
array_push($runners, new Runner($line[0], $line[2], $line[5], $line[6], $line[3], $line[4]));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$timings = file_get_contents("data/passering.csv");
|
|
||||||
$timings = str_getcsv($timings, "\n");
|
|
||||||
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]-1, $time);
|
|
||||||
}
|
|
||||||
|
|
||||||
function registration_table($runners) {
|
function registration_table($runners) {
|
||||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||||
@ -301,6 +181,8 @@ function liveresult_table($runners) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$runners = read_runners_from_csv();
|
||||||
|
|
||||||
if (!isset($query)){
|
if (!isset($query)){
|
||||||
parse_str($_SERVER['QUERY_STRING'], $query);
|
parse_str($_SERVER['QUERY_STRING'], $query);
|
||||||
if ($query["type"] == "registrering"){
|
if ($query["type"] == "registrering"){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user