graph it
All checks were successful
Build and push / Pulling repo on server (push) Successful in 5s

This commit is contained in:
Chris 2023-11-26 14:00:23 +01:00
parent 26ec6de1e3
commit a67d1eb05b
5 changed files with 191 additions and 58 deletions

View File

@ -19,7 +19,7 @@ CREATE TABLE IF NOT EXISTS "results" (
"id" INTEGER, "id" INTEGER,
"event" INTEGER, "event" INTEGER,
"run" INTEGER, "run" INTEGER,
"rang" TEXT, "rang" INTEGER,
"stnr" INTEGER, "stnr" INTEGER,
"teilnehmer" TEXT, "teilnehmer" TEXT,
"hund" TEXT, "hund" TEXT,

View File

@ -184,6 +184,7 @@ function analyzeResultCSV($csv,$run,$event)
$stnr = $row['stnr']; $stnr = $row['stnr'];
$teilnehmer = $row['teilnehmer']; $teilnehmer = $row['teilnehmer'];
$hund = $row['hund']; $hund = $row['hund'];
$rang = $row['rang'];
$verein = $row['verein']; $verein = $row['verein'];
$f = $row['f']; $f = $row['f'];
$vw = $row['vw']; $vw = $row['vw'];
@ -198,7 +199,7 @@ function analyzeResultCSV($csv,$run,$event)
{ {
$res = $GLOBALS['db']->query("SELECT * FROM results WHERE stnr = '$stnr' AND run = '$run' AND event = '$event'"); $res = $GLOBALS['db']->query("SELECT * FROM results WHERE stnr = '$stnr' AND run = '$run' AND event = '$event'");
if($res->fetchArray() == false) if($res->fetchArray() == false)
$GLOBALS['db']->exec("INSERT INTO results (stnr, run, event, teilnehmer, hund, verein, f, vw, zf, zeit, gf, msek, bew) VALUES ('$stnr', '$run', '$event', '$teilnehmer', '$hund', '$verein', '$f', '$vw', '$zf', '$zeit', '$gf', '$msek', '$bew')"); $GLOBALS['db']->exec("INSERT INTO results (stnr, rang, run, event, teilnehmer, hund, verein, f, vw, zf, zeit, gf, msek, bew) VALUES ('$stnr', '$rang', '$run', '$event', '$teilnehmer', '$hund', '$verein', '$f', '$vw', '$zf', '$zeit', '$gf', '$msek', '$bew')");
} }
catch(Exception $ex) { catch(Exception $ex) {
//die( $ex->getMessage() ); //die( $ex->getMessage() );

Binary file not shown.

View File

@ -16,27 +16,44 @@ class Smart extends Page {
function search() function search()
{ {
$db = new SQLite3(ROOT.DS.'../crawler/data.db'); $db = new SQLite3(ROOT.DS.'../crawler/data.db', SQLITE3_OPEN_READONLY);
$q = $_REQUEST['q']; $q = $_REQUEST['q'];
$query = "SELECT * FROM results WHERE teilnehmer LIKE '$q'"; if(!$q || strlen($q) < 3 || strpos($q, ' ') === false)
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Error: Bitte Nachname und Vorname eingeben.']);
$query = "SELECT DISTINCT(hund) FROM results WHERE teilnehmer LIKE '$q'";
$res = $db->query($query); $res = $db->query($query);
$results = []; $results = [];
$dogs = [];
while($row = $res->fetchArray()) while($row = $res->fetchArray())
{ {
$row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']); $dogs[] = $row['hund'];
$row['event'] = $db->querySingle("SELECT name FROM events WHERE id = ".$row['event']);
$row['unixtimestamp'] = strtotime($row['date']);
$row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']);
$row['ago'] = printRelativeTime(time(),$row['unixtimestamp']);
$results[] = $row;
} }
//sort results by date if(count($dogs) == 0)
usort($results, function($a, $b) { return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Error: Keine Ergebnisse gefunden. Bitte Nachname und Vorname prüfen.']);
return $b['unixtimestamp'] <=> $a['unixtimestamp'];
});
$this->set('results', $results); foreach($dogs as $dog)
{
$res = $db->query("SELECT * FROM results WHERE teilnehmer LIKE '$q' AND hund LIKE '$dog'");
while($row = $res->fetchArray())
{
$row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']);
$row['event'] = $db->querySingle("SELECT name FROM events WHERE id = ".$row['event']);
$row['unixtimestamp'] = strtotime($row['date']);
$row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']);
$row['ago'] = printRelativeTime(time(),$row['unixtimestamp']);
$results[$dog][] = $row;
}
//sort results by date
usort($results[$dog], function($a, $b) {
return $a['unixtimestamp'] <=> $b['unixtimestamp'];
});
}
$this->set('results_dogs', $results);
$this->set('dogs', $dogs);
$this->set('query', $query); $this->set('query', $query);
$this->set('template', 'search.html.php'); $this->set('template', 'search.html.php');

View File

@ -1,44 +1,159 @@
<pre><?=$query;?></pre> <h2>Hunde:</h2>
<ul>
<table class="table"> <?php foreach ($dogs as $dog) : ?>
<tr> <li><a href="#<?= $dog ?>"><?= $dog ?></a></li>
<th>event</th>
<th>Wann wars</th>
<th>run</th>
<th>rang</th>
<th>stnr</th>
<th>teilnehmer</th>
<th>hund</th>
<th>verein</th>
<th>f</th>
<th>vw</th>
<th>zf</th>
<th>zeit</th>
<th>gf</th>
<th>msek</th>
<th>bew</th>
<th>punkte</th>
</tr>
<?php foreach($results as $res): ?>
<tr>
<td><?= $res['event'] ?></td>
<td><?= $res['ago'] ?></td>
<td><?= $res['run'] ?></td>
<td><?= $res['rang'] ?></td>
<td><?= $res['stnr'] ?></td>
<td><?= $res['teilnehmer'] ?></td>
<td><?= $res['hund'] ?></td>
<td><?= $res['verein'] ?></td>
<td><?= $res['f'] ?></td>
<td><?= $res['vw'] ?></td>
<td><?= $res['zf'] ?></td>
<td><?= $res['zeit'] ?></td>
<td><?= $res['gf'] ?></td>
<td><?= $res['msek'] ?></td>
<td><?= $res['bew'] ?></td>
<td><?= $res['punkte'] ?></td>
</tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </ul>
<?php foreach ($dogs as $dog) :
$results = $results_dogs[$dog];
?>
<h1 id="<?= $dog; ?>"><?= $dog; ?></h1>
<button onClick="getElementById('table_<?= $dog ?>').style.display='table'">Tabelle anzeigen</button>
<table id="table_<?= $dog ?>" class="table" style="display:none">
<tr>
<th>event</th>
<th>Wann wars</th>
<th>run</th>
<th>rang</th>
<th>stnr</th>
<th>teilnehmer</th>
<th>hund</th>
<th>verein</th>
<th>f</th>
<th>vw</th>
<th>zf</th>
<th>zeit</th>
<th>gf</th>
<th>msek</th>
<th>bew</th>
<th>punkte</th>
</tr>
<?php foreach ($results as $res) :
// graph data preparation
//if ($res['bew'] != 'DIS' && $res['punkte'] != 'DIS')
{
$sdata['dates'][] = date("d.m.Y", strtotime($res['date']));
$sdata['speed'][] = $res['msek'] ?: 0;
$sdata['errors'][] = $res['f'] ?: 0;
$sdata['refusals'][] = $res['vw'] ?: 0;
$sdata['time'][] = $res['zeit'] ?: 0;
$sdata['points'][] = $res['punkte'];
$sdata['ranking'][] = $res['rang'];
}
?>
<tr>
<td><?= $res['event'] ?></td>
<td><?= $res['ago'] ?></td>
<td><?= $res['run'] ?></td>
<td><?= $res['rang'] ?></td>
<td><?= $res['stnr'] ?></td>
<td><?= $res['teilnehmer'] ?></td>
<td><?= $res['hund'] ?></td>
<td><?= $res['verein'] ?></td>
<td><?= $res['f'] ?></td>
<td><?= $res['vw'] ?></td>
<td><?= $res['zf'] ?></td>
<td><?= $res['zeit'] ?></td>
<td><?= $res['gf'] ?></td>
<td><?= $res['msek'] ?></td>
<td><?= $res['bew'] ?></td>
<td><?= $res['punkte'] ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php if (count($results) > 0) : ?>
<div class="col">
<div id="graph<?= $dog ?>" data-bs-theme="light" class="card bg-light text-black" style="min-height: 400px;"></div>
<script type="text/javascript">
// Initialize the echarts instance based on the prepared dom
var myChart = echarts.init(document.getElementById('graph<?= $dog ?>'));
// Specify the configuration items and data for the chart
var option = {
title: {
text: 'Stacked Line'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Geschwindigkeit', 'Fehler', 'Verweigerungen', 'Zeit', 'Geschwindigkeit', 'Punkte', 'Platz']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: <?= json_encode($sdata['dates']); ?>
},
yAxis: {
type: 'value'
},
series: [{
name: 'Geschwindigkeit',
type: 'line',
stack: 'Total',
data: <?= json_encode($sdata['speed']); ?>
},
{
name: 'Fehler',
type: 'line',
stack: 'Total',
data: <?= json_encode($sdata['errors']); ?>
},
{
name: 'Verweigerungen',
type: 'line',
stack: 'Total',
data: <?= json_encode($sdata['refusals']); ?>
},
{
name: 'Zeit',
type: 'line',
stack: 'Total',
data: <?= json_encode($sdata['time']); ?>
},
{
name: 'Punkte',
type: 'line',
stack: 'Total',
data: <?= json_encode($sdata['points']); ?>
},
{
name: 'Platz',
type: 'line',
stack: 'Total',
data: <?= json_encode($sdata['ranking']); ?>
}
]
};
// Display the chart using the configuration items and data just specified.
myChart.setOption(option);
</script>
</div>
<?php endif; ?>
<hr>
<?php endforeach; ?>