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,11 +16,26 @@ 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())
{
$dogs[] = $row['hund'];
}
if(count($dogs) == 0)
return partial('error.html', ['errorTitle' => 'Error', 'errorMessage' => 'Error: Keine Ergebnisse gefunden. Bitte Nachname und Vorname prüfen.']);
foreach($dogs as $dog)
{
$res = $db->query("SELECT * FROM results WHERE teilnehmer LIKE '$q' AND hund LIKE '$dog'");
while($row = $res->fetchArray()) while($row = $res->fetchArray())
{ {
$row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']); $row['date'] = $db->querySingle("SELECT date FROM events WHERE id = ".$row['event']);
@ -28,15 +43,17 @@ class Smart extends Page {
$row['unixtimestamp'] = strtotime($row['date']); $row['unixtimestamp'] = strtotime($row['date']);
$row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']); $row['run'] = $db->querySingle("SELECT name FROM runs WHERE id = ".$row['run']);
$row['ago'] = printRelativeTime(time(),$row['unixtimestamp']); $row['ago'] = printRelativeTime(time(),$row['unixtimestamp']);
$results[] = $row; $results[$dog][] = $row;
} }
//sort results by date //sort results by date
usort($results, function($a, $b) { usort($results[$dog], function($a, $b) {
return $b['unixtimestamp'] <=> $a['unixtimestamp']; return $a['unixtimestamp'] <=> $b['unixtimestamp'];
}); });
}
$this->set('results', $results); $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,8 +1,21 @@
<pre><?=$query;?></pre> <h2>Hunde:</h2>
<ul>
<?php foreach ($dogs as $dog) : ?>
<li><a href="#<?= $dog ?>"><?= $dog ?></a></li>
<?php endforeach; ?>
</ul>
<table class="table">
<?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> <tr>
<th>event</th> <th>event</th>
<th>Wann wars</th> <th>Wann wars</th>
<th>run</th> <th>run</th>
@ -20,7 +33,21 @@
<th>bew</th> <th>bew</th>
<th>punkte</th> <th>punkte</th>
</tr> </tr>
<?php foreach($results as $res): ?> <?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> <tr>
<td><?= $res['event'] ?></td> <td><?= $res['event'] ?></td>
<td><?= $res['ago'] ?></td> <td><?= $res['ago'] ?></td>
@ -41,4 +68,92 @@
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</table> </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; ?>