Added ranking, calc

This commit is contained in:
Timon Ostertun
2020-09-26 18:08:34 +02:00
parent 9d1ba271f3
commit 9e30ed5e9c
11 changed files with 897 additions and 4 deletions

View File

@@ -256,6 +256,147 @@ function dbGetResultCalculated(regatta) {
}); });
} }
function dbGetRanking(minDate, maxDate, jugend, jugstrict) {
return new Promise(async function(resolve) {
var rankNoResults = [];
var sailors = await dbGetData('sailors');
var regattas = await dbGetRegattasRange(minDate, maxDate);
var sailorIds = {};
for (s in sailors) {
sailorIds[sailors[s].id] = s;
}
for (var i in sailors) {
sailors[i].regattas = {};
sailors[i].tmp_rlp = [];
}
for (var i in regattas) {
var regatta = regattas[i];
// regatta has to be min. 2 days to be ranking regatta
if (regatta.length < 2) continue;
var results = await dbGetDataIndex('results', 'regatta', regatta.id);
if (results.length <= 0) {
if (regatta.dateTo <= getToday()) {
if (regatta.canceled == '0') {
rankNoResults.push(regatta);
}
}
continue;
}
// in one race there must be at least 10 boats started
var ok = false;
for (var j = 1; j <= regatta.races; j ++) {
var temp = 0;
for (var r in results) {
if ((results[r]['race' + j] != 'DNC') && (results[r]['race' + j] != 'DNS')) {
temp ++;
}
}
if (temp >= 10) {
ok = true;
break;
}
}
if (!ok) continue;
var fb = regatta.finishedBoats;
// calc m
var m;
if (regatta.m > 0) {
m = regatta.m;
} else if (regatta.races <= 4) {
m = regatta.races;
} else {
if ((regatta.length > 2) && (regatta.races >= 6)) {
m = 5;
} else {
m = 4;
}
}
// add regatta to each sailor
for (var r in results) {
var result = results[r];
if (result.rlp == 0) continue;
// check if crew is youth
// TODO: not used
sailors[sailorIds[result.steuermann]].regattas[regatta.id] = {
regatta: regatta.id,
boat: result.boat,
crew: result.crew,
place: result.place,
fb: fb,
rlp: result.rlp,
used: 0,
m: m
};
for (var j = 0; j < m; j ++) {
sailors[sailorIds[result.steuermann]].tmp_rlp.push([regatta.id, result.rlp]);
}
}
}
// remove not german or not youth sailors
for (var i = sailors.length - 1; i >= 0; i --) {
if (sailors[i].german == '0') {
sailors.splice(i, 1);
} else if (jugend) {
if (((sailors[i].year != null) && (sailors[i].year < (formatDate('Y', maxDate) - YOUTH_AGE))) ||
((sailors[i].year == null) && (jugstrict))) {
sailors.splice(i, 1);
}
}
}
for (var i = sailors.length - 1; i >= 0; i --) {
// sort rlps desc
sailors[i].tmp_rlp.sort(function (a,b) {
return b[1] - a[1];
});
// calc mean rlp
var sum = 0;
var cnt = 0;
for (var t in sailors[i].tmp_rlp) {
var r = sailors[i].tmp_rlp[t];
sum += parseFloat(r[1]);
sailors[i].regattas[r[0]].used ++;
cnt ++;
if (cnt >= 9) break;
}
delete sailors[i].tmp_rlp;
if (cnt > 0) {
var rlp = sum / cnt;
sailors[i].rlp = rlp;
sailors[i].m = cnt;
} else {
sailors.splice(i, 1);
}
}
sailors.sort(function (a,b) {
if (a.m != b.m) return b.m - a.m;
return b.rlp - a.rlp;
});
for (var i = 0; i < sailors.length; i ++) {
sailors[i].rank = (i + 1);
}
resolve([sailors, rankNoResults]);
});
}
async function updateSyncStatus() { // TODO async function updateSyncStatus() { // TODO
// var syncStatus = document.getElementById('syncstatus'); // var syncStatus = document.getElementById('syncstatus');
// var lastSync = await dbGetData('update_times', 'last_sync'); // var lastSync = await dbGetData('update_times', 'last_sync');

View File

@@ -9,6 +9,8 @@
const QUERY_URL = '<?php echo SERVER_ADDR; ?>/api/'; const QUERY_URL = '<?php echo SERVER_ADDR; ?>/api/';
const BOATCLASS = '<?php echo BOATCLASS; ?>'; const BOATCLASS = '<?php echo BOATCLASS; ?>';
const LINK_PRE = '<?php echo SERVER_ADDR; ?>/'; const LINK_PRE = '<?php echo SERVER_ADDR; ?>/';
const YOUTH_AGE = '<?php echo $_CLASS['youth-age']; ?>';
const YOUTH_GERMAN_NAME = '<?php echo $_CLASS['youth-german-name']; ?>';
var randomId = function() { return '_' + Math.random().toString(36).substr(2, 9); } var randomId = function() { return '_' + Math.random().toString(36).substr(2, 9); }

View File

@@ -43,6 +43,107 @@
text-align: right; text-align: right;
} }
/*** RANKING LIST ***/
.ranking-list > div {
padding-top: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid #dee2e6;
cursor: pointer;
}
.ranking-list > div:last-child {
border: 0;
padding-bottom: 0;
}
.ranking-list div {
white-space: nowrap;
}
.ranking-list > div > div > div {
display: inline-block;
}
.ranking-list > div > div:nth-child(1) > div:nth-child(1) {
width: 25%;
}
.ranking-list > div > div:nth-child(1) > div:nth-child(2) {
width: 50%;
text-align: right;
}
.ranking-list > div > div:nth-child(1) > div:nth-child(3) {
width: 25%;
text-align: right;
}
.ranking-list > div > div:nth-child(2) > div:nth-child(1) {
width: 75%;
}
.ranking-list > div > div:nth-child(2) > div:nth-child(2) {
width: 25%;
text-align: right;
}
/*** RANKING DETAIL LIST ***/
.ranking-detail-list > div {
padding-top: 1rem;
padding-bottom: 1rem;
border-bottom: 1px solid #dee2e6;
cursor: pointer;
}
.ranking-detail-list > div:last-child {
border: 0;
padding-bottom: 0;
}
.ranking-detail-list div {
white-space: nowrap;
}
.ranking-detail-list > div > div > div {
display: inline-block;
}
.ranking-detail-list > div > div:nth-child(2) > div:nth-child(1) {
width: 50%;
}
.ranking-detail-list > div > div:nth-child(2) > div:nth-child(2) {
width: 25%;
text-align: right;
}
.ranking-detail-list > div > div:nth-child(2) > div:nth-child(3) {
width: 25%;
text-align: right;
}
.ranking-detail-list > div > div:nth-child(3) {
border-bottom: 1px dashed #dee2e6;
}
.ranking-detail-list > div > div:nth-child(3) > div:nth-child(1) {
width: 50%;
}
.ranking-detail-list > div > div:nth-child(3) > div:nth-child(2) {
width: 50%;
text-align: right;
}
.ranking-detail-list > div > div:nth-child(4) > div:nth-child(1) {
width: 50%;
}
.ranking-detail-list > div > div:nth-child(4) > div:nth-child(2) {
width: 50%;
text-align: right;
}
.ranking-detail-list > div > div:nth-child(n+5) > div:nth-child(1) {
width: 75%;
}
.ranking-detail-list > div > div:nth-child(n+5) > div:nth-child(2) {
width: 25%;
text-align: right;
}
/*** NORMAL LIST ***/ /*** NORMAL LIST ***/
.normal-list > div { .normal-list > div {
padding-top: 1rem; padding-top: 1rem;

65
server/content/calc.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
$sp['title'] = 'RLP Rechner - Regatten.net ' . $_CLASS['name'];
$sp['backbutton'] = 'index';
$sp['activenav'] = 5;
// Title
$content = "<h1>RLP Rechner</h1>";
$content .= '<p>Einfach Ranglistenpunkte berechnen</p>';
$sp['output'] .= $tpl->load('card', [$content]);
// Inputs
$content = $tpl->load('input', ['html-id' => 'input-rlf', 'placeholder' => 'Ranglistenfaktor (rlf)', 'type' => 'number']);
$content .= $tpl->load('input', ['html-id' => 'input-m', 'placeholder' => 'Multiplikator (m)', 'type' => 'number']);
$content .= $tpl->load('input', ['html-id' => 'input-fb', 'placeholder' => 'Gezeitete Boote (fb)', 'type' => 'number']);
$content .= $tpl->load('input', ['html-id' => 'input-pl', 'placeholder' => 'Platzierung (pl)', 'type' => 'number']);
$content .= $tpl->load('button', ['Hinzuf&uuml;gen', '#', 'html-id' => 'button-add']);
$sp['output'] .= $tpl->load('card', [$content]);
// Table
$thead = '<tr><th>RLF</th><th>m</th><th>fb</th><th>pl</th><th>RLP</th><th></th></tr>';
$content = $tpl->load('table', [$thead, 'html-id' => 'table-races']);
$content .= '<p id="p-result"></p>';
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-races']);
// Infos
$content = '<h2>Hinweise zum Ausf&uuml;llen</h2>';
$content .= '<p><b>Ranglistenfaktor (RLF)</b><br>';
$content .= 'Der Ranglistenfaktor ist ein von der KV vorgegebener Faktor zwischen 1,0 und 1,6 zur Gewichtung der Regatten.<br>';
$content .= 'Du findest ihn in der <a href="' . LINK_PRE . 'regattas">Regatten-Liste</a>.';
$content .= '</p>';
$content .= '<p><b>Multiplikator (m)</b><br>';
$content .= 'Der Multiplikator gibt an, wie oft eine Regatta in die Wertung eingeht.<br>';
$content .= 'Er ist abh&auml;ngig von den tats&auml;chlich gesegelten Wettfahrten. Dabei gilt:<br>';
$content .= '<b>1</b> Wettfahrt => <b>m = 1</b><br>';
$content .= '<b>2</b> Wettfahrten => <b>m = 2</b><br>';
$content .= '<b>3</b> Wettfahrten => <b>m = 3</b><br>';
$content .= '<b>4 oder mehr</b> Wettfahrten => <b>m = 4</b><br>';
$content .= 'Ist die Regatta f&uuml;r mehr als 2 Tage ausgeschrieben, gilt au&szlig;erdem:<br>';
$content .= '<b>6 oder mehr</b> Wettfahrten => <b>m = 5</b>';
$content .= '</p>';
$content .= '<p><b>Gezeitete Boote (fb)</b><br>';
$content .= 'Die Anzahl der Boote, die in mindestens einer Wettfahrt ins Ziel gefahren sind.';
$content .= '</p>';
$content .= '<p><b>Platzierung (pl)</b><br>';
$content .= 'Deine Platzierung in den Endergebnissen';
$content .= '</p>';
$sp['output'] .= $tpl->load('card', [$content]);
$content = '<h2>Berechnung</h2>';
$content .= '<p>Die Ranglistenpunkte (RLP) f&uuml;r eine Regatta berechnen sich nach folgender Formel:<br>';
$content .= '<i>RLP = RLF * 100 * ((fb + 1 - pl) / fb)</i><br>';
$content .= 'Diese Ranglistenpunkte k&ouml;nnen je nach Multiplikator bis zu 5 mal in die Wertung eingehen.<br>';
$content .= 'Der Mittelwert der 9 besten Wertungen ergibt die Ranglistenpunkte.';
$content .= '</p>';
$sp['output'] .= $tpl->load('card', [$content]);
$sp['scripts'] .= $scripts->load('calc');
?>

46
server/content/rank.php Normal file
View File

@@ -0,0 +1,46 @@
<?php
$sp['title'] = 'Ranglisten - Regatten.net ' . $_CLASS['name'];
$sp['backbutton'] = 'index';
$sp['activenav'] = 3;
// Title, Inputs
$content = "<h1>Ranglisten</h1>";
$options = '<option value="year">Jahres-Rangliste</option>';
$options .= '<option value="youth">Jugend-Rangliste</option>';
$options .= '<option value="idjm">' . $_CLASS['youth-german-name'] . '-Rangliste</option>';
$options .= '<option value="user">Benutzerdefiniert</option>';
$content .= $tpl->load('select', ['html-id' => 'select-type', 'placeholder' => 'Rangliste', 'options' => $options, 'css-class' => 'mt-3 mb-0']);
$content .= $tpl->load('select', ['html-id' => 'select-year', 'placeholder' => 'Jahr', 'css-class' => 'mt-3 mb-0']);
$content .= $tpl->load('input', ['html-id' => 'input-from', 'placeholder' => 'Von', 'type' => 'date', 'css-class' => 'mt-3']);
$content .= $tpl->load('input', ['html-id' => 'input-to', 'placeholder' => 'Bis', 'type' => 'date']);
$chbox = $tpl->load('checkbox', ['html-id' => 'input-jugend', 'placeholder' => 'Jugend']);
$content .= '<div class="mb-3" style="display:inline-block; width:50%;">' . $chbox . '</div>';
$chbox = $tpl->load('checkbox', ['html-id' => 'input-jugstrict', 'placeholder' => 'Streng']);
$content .= '<div class="mb-3" style="display:inline-block; width:50%;">' . $chbox . '</div>';
$content .= $tpl->load('button', ['Anzeigen', '#', 'html-id' => 'button-show']);
$sp['output'] .= $tpl->load('card', [$content]);
// No Results
$content = '<h2 class="color-white">ACHTUNG</h2>';
$content .= '<p class="color-white">Zu folgenden Regatten wurden noch keine Ergebnisse hinterlegt:</p>';
$content .= '<ul id="ul-noresults"></ul>';
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-noresults', 'css-class' => 'bg-red2-dark']);
// Ranking
$content = $tpl->load('input', ['html-id' => 'input-search', 'placeholder' => 'Suche', 'type' => 'text']);
$content .= '<div id="div-rank" class="ranking-list mb-0"></div>';
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-rank']);
// Menu
$items = '<p id="menu-item-text" class="mb-2 mt-1" style="line-height: 1.5em;"></p>';
$items .= '<div id="div-details" class="ranking-detail-list mb-3" style="line-height: 2em;"></div>';
$sp['menus'] .= $tpl->load('menu/bottom', [$items, 'html-id' => 'menu-rank', 'title' => 'Ranglisten-Details', 'height' => 500]);
$sp['scripts'] .= $scripts->load('rank');
?>

20
server/content/result.php Normal file
View File

@@ -0,0 +1,20 @@
<?php
$sp['title'] = 'Ergebnisse - Regatten.net ' . $_CLASS['name'];
$sp['backbutton'] = true;
// Title, Inputs
$content = '<h1 id="h1-title"></h1>';
$content .= '<p id="p-title"></p>';
$sp['output'] .= $tpl->load('card', [$content]);
// Results
$content = '<p id="p-info" class="mb-0"></p>';
$content .= $tpl->load('table', ['html-id' => 'table-results', 'css-class' => 'mb-0 text-nowrap']);
$sp['output'] .= $tpl->load('card', [$content, 'html-id' => 'card-results']);
$sp['scripts'] .= $scripts->load('result');
?>

92
server/scripts/calc.js Normal file
View File

@@ -0,0 +1,92 @@
var races = [];
var firstCall = true;
function reCalc() {
setTimeout(function(){
if (races.length > 0) {
$('#card-races').show();
$('#p-result').text('Berechne...');
var rlps = [];
var tbody = '';
for (var i = 0; i < races.length; i ++) {
tbody += '<tr>';
tbody += '<td>' + races[i].rlf + '</td>';
tbody += '<td>' + races[i].m + '</td>';
tbody += '<td>' + races[i].fb + '</td>';
tbody += '<td>' + races[i].pl + '</td>';
tbody += '<td>' + races[i].rlp.toFixed(3) + '</td>';
tbody += '<td><a href="#" onclick="removeRace(' + i + ')" class="btn rounded-s text-uppercase font-900 shadow-m bg-highlight"><i class="fas fa-times"></i></a></td>';
tbody += '</tr>';
for (var j = 0; j < races[i].m; j ++) {
rlps.push(races[i].rlp);
}
}
$('#table-races').find('tbody').html(tbody);
rlps.sort(function (a,b) {
return b-a;
});
var sum = 0;
var cnt = Math.min(rlps.length, 9);
for (var i = 0; i < cnt; i ++) {
sum += rlps[i];
}
$('#p-result').html('<b>' + (sum / cnt).toFixed(3) + '</b> Punkte aus <b>' + cnt + '</b> Wertungen.');
} else {
$('#card-races').hide();
}
}, 0);
}
function addRace() {
var rlf = parseFloat($('#input-rlf').val().replace(',', '.'));
var m = parseFloat($('#input-m').val());
var fb = parseFloat($('#input-fb').val());
var pl = parseFloat($('#input-pl').val().replace(',', '.'));
if (isNaN(rlf) || (rlf < 1) || (rlf > 1.6)) {
toastError('RLF ungültig');
return;
}
if (isNaN(m) || (m < 1) || (m > 5)) {
toastError('m ungültig');
return;
}
if (isNaN(fb) || (fb < 1)) {
toastError('fb ungültig');
return;
}
if (isNaN(pl) || (pl < 1) || (pl > (fb + 1))) {
toastError('pl ungültig');
return;
}
var race = {
rlf: rlf,
m: m,
fb: fb,
pl: pl,
rlp: (100 * rlf * ((fb + 1 - pl) / fb))
};
$('#input-rlf').val('');
$('#input-m').val('');
$('#input-fb').val('');
$('#input-pl').val('');
races.push(race);
reCalc();
}
function removeRace(id) {
if ((id >= 0) && (id < races.length)) races.splice(id, 1);
reCalc();
}
var siteScript = async function () {
if (firstCall) {
firstCall = false;
$('#button-add').click(addRace);
}
reCalc();
hideLoader();
}

View File

@@ -19,14 +19,23 @@ var siteScript = async function() {
if (watched.length > 0) { if (watched.length > 0) {
var year = (new Date()).getFullYear(); var year = (new Date()).getFullYear();
$('#th-ranking').html('Rangliste ' + year); $('#th-ranking').html('Rangliste ' + year);
// TODO: get ranking var ranking = (await dbGetRanking(parseDate('01.12.' + (year - 1)), parseDate('30.11.' + year), false, false))[0];
tbody = ''; tbody = '';
for (i in watched) { for (i in watched) {
sailor = watched[i]; sailor = watched[i];
tbody += '<tr><td>' + sailor.name + '</td><td>'; tbody += '<tr><td>' + sailor.name + '</td><td>';
// TODO: check if ranking and output var rank = null;
//tbody += '<i>nicht in der Rangliste</i>'; for (r in ranking) {
tbody += '<i>Ranglisten werden aktuell noch nicht unterst&uuml;tzt</i>'; if (ranking[r].id == sailor.id) {
rank = ranking[r].rank;
break;
}
}
if (rank == null) {
tbody += '<i>nicht in der Rangliste</i>';
} else {
tbody += '<b>' + rank + '.</b> Platz';
}
tbody += '</td></tr>'; tbody += '</td></tr>';
} }
$('#table-favorites').find('tbody').html(tbody); $('#table-favorites').find('tbody').html(tbody);

335
server/scripts/rank.js Normal file
View File

@@ -0,0 +1,335 @@
function onDetailClicked(regatta) {
location.href = LINK_PRE + 'result?regatta=' + regatta;
}
async function onRankingClicked(id) {
var sailor = null;
for (var i in ranking) {
if (ranking[i].id == id) {
sailor = ranking[i];
break;
}
}
if (sailor == null) return;
$('#menu-rank').find('.menu-title').find('p').text(sailor.name);
if (lastRanking != null) {
var lastRank;
if (sailor.id in lastRanking) {
lastRank = lastRanking[sailor.id] + '.';
} else {
lastRank = 'nicht in der Rangliste';
}
$('#menu-item-text').text('Vorheriges Jahr: ' + lastRank);
$('#menu-item-text').show();
} else {
$('#menu-item-text').hide();
}
list = '';
for (var i in sailor.regattas) {
var entry = sailor.regattas[i];
var regatta = entry.regatta;
var boat = await dbGetData('boats', entry.boat);
var dateFrom = parseDate(regatta.date);
var dateTo = parseDate(regatta.date);
dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta.length) - 1, 0));
list += '<div onclick="onDetailClicked(' + regatta.id + ')">';
// ZEILE 1
list += '<div><b>' + regatta.name + '</b></div>';
// ZEILE 2
list += '<div>';
// DATE
list += '<div>' + formatDate('d.m.Y', dateFrom) + ' - ' + formatDate('d.m.Y', dateTo) + '</div>';
// m
list += '<div>m: ' + entry.m + '</div>';
// rlf
list += '<div>RLF: ' + parseFloat(regatta.rlf).toFixed(2) + '</div>';
list += '</div>';
// ZEILE 3
list += '<div>';
// Place
list += '<div>Platz ' + entry.place + ' / ' + entry.fb + '</div>';
// rlp
var color;
if (entry.used == 0) { color = 'color-red2-dark'; }
else if (entry.used == entry.m) { color = 'color-green2-dark'; }
else { color = 'color-yellow2-dark'; }
list += '<div>Punkte: ' + entry.used + ' x <b class="' + color + '">' + parseFloat(entry.rlp).toFixed(2) + '</b></div>';
list += '</div>';
// ZEILE 4
list += '<div>';
// Sailnumber
list += '<div>' + boat.sailnumber + '</div>';
// Boatname
list += '<div>' + boat.name + '</div>';
list += '</div>';
// ZEILE 5...
var crew = entry.crew.split(',');
for (var c in crew) {
var cr = await dbGetData('sailors', crew[c]);
if (cr != null) {
list += '<div>';
// Name
list += '<div>' + cr.name + '</div>';
// Year
list += '<div>' + ((cr.year != null) ? ('(' + cr.year + ')') : '') + '</div>';
list += '</div>';
}
}
list += '</div>';
}
$('#div-details').html(list);
$('#menu-rank').showMenu();
$('#menu-rank').scrollTop(0);
}
function selectChange(callSiteScript = true) {
var type = $('#select-type').val();
var year = parseInt($('#select-year').val());
if (type == "user") {
$('#select-year').parent().hide();
$('#input-from').parent().show();
$('#input-to').parent().show();
$('#input-jugend').parent().parent().show();
$('#input-jugstrict').parent().parent().show();
$('#button-show').show();
} else {
$('#select-year').parent().show();
$('#input-from').parent().hide();
$('#input-to').parent().hide();
$('#input-jugend').parent().parent().hide();
$('#input-jugstrict').parent().parent().hide();
$('#button-show').hide();
var from, to, jugend, jugstrict;
switch (type) {
case 'year':
from = (year - 1) + '-12-01';
to = year + '-11-30';
jugend = jugstrict = false;
break;
case 'youth':
from = (year - 1) + '-12-01';
to = year + '-11-30';
jugend = jugstrict = true;
break;
case 'idjm':
// TODO
from = (year - 1) + '-12-01';
to = year + '-11-30';
jugend = true;
jugstrict = false;
break;
}
$('#input-from').val(from);
$('#input-to').val(to);
$('#input-jugend').prop('checked', jugend);
$('#input-jugstrict').prop('checked', jugstrict);
if (callSiteScript && (typeof siteScript === 'function'))
siteScript();
}
}
function initSelects() {
var type = findGetParameter('type');
var year = findGetParameter('year');
if (type === null) type = 'year';
if (year === null) year = new Date().getFullYear();
$('#select-type').val(type);
$('#select-year').html('<option value="' + year + '">' + year + '</option>');
$('#select-year').val(year);
selectChange(false);
}
var firstCall = true;
var rows = [];
var ranking;
var lastRanking;
async function drawList () {
window.setTimeout(function () {
var list = '';
rows.forEach(function (entry) {
if (entry == null) {
list += '<div><div align="center" class="color-highlight" style="white-space:normal;"><b>Ende der Rangliste gem&auml;&szlig; DSV-Ranglistenverordnung (min. m = 9 Wertungen)</b></div></div>';
} else if (search($('#input-search').val(), entry.keywords)) {
list += entry.content;
}
});
$('#div-rank').html(list);
}, 0);
}
var siteScript = async function() {
if (firstCall) {
firstCall = false;
initSelects();
$('#select-type').change(selectChange);
$('#select-year').change(selectChange);
$('#button-show').click(siteScript);
$('#input-search').on('input', drawList);
}
var minDate = parseDate($('#input-from').val());
var maxDate = parseDate($('#input-to').val());
var jugend = $('#input-jugend').prop('checked');
var jugstrict = $('#input-jugstrict').prop('checked');
var dbRanking = await dbGetRanking(minDate, maxDate, jugend, jugstrict);
ranking = dbRanking[0];
lastRanking = null;
if (($('#select-type').val() == 'year') || ($('#select-type').val() == 'youth')) {
lastRanking = {};
var lYear = parseInt($('#select-year').val()) - 1;
var lMinDate = parseDate((lYear - 1) + '-12-01');
var lMaxDate = parseDate(lYear + '-11-30');
var lDbRanking = (await dbGetRanking(lMinDate, lMaxDate, jugend, jugstrict))[0];
for (var i in lDbRanking) {
lastRanking[lDbRanking[i].id] = lDbRanking[i].rank;
}
}
var selectedYear = $('#select-year').val();
var years = await dbGetData('years');
years.sort(function (a, b) {
if (a['year'] > b['year']) return -1;
if (a['year'] < b['year']) return 1;
return 0;
});
var options = '';
for (id in years) {
var year = years[id]['year'];
options += '<option value="' + year + '">' + year + '</option>';
}
$('#select-year').html(options);
$('#select-year').val(selectedYear);
if (dbRanking[1].length > 0) {
$('#card-noresults').show();
list = '';
for (id in dbRanking[1]) {
list += '<li>';
list += dbRanking[1][id].name;
list += '</li>';
}
$('#ul-noresults').html(list);
} else {
$('#card-noresults').hide();
}
var count = ranking.length;
if (count > 0) {
$('#input-search').parent().show();
var dsvEnd = false;
rows = [];
for (id in ranking) {
var entry = ranking[id];
for (var i in entry.regattas) {
entry.regattas[i].regatta = await dbGetData('regattas', entry.regattas[i].regatta);
}
entry.regattas = Object.values(entry.regattas);
entry.regattas.sort(function (a,b) {
return a.regatta.date.localeCompare(b.regatta.date);
});
var club = null;
if (entry['club'] != null)
club = await dbGetData('clubs', entry['club']);
var row = { keywords: [], content: '' };
row.keywords.push(entry['name']);
if (entry['year'] != null) row.keywords.push(entry['year']);
if (club != null) row.keywords.push(club['kurz'], club['name']);
if (!dsvEnd && (entry.m < 9)) {
rows.push(null);
dsvEnd = true;
}
row.content += '<div onclick="onRankingClicked(' + entry['id'] + ');">';
// ZEILE 1
row.content += '<div>';
// Rank
var icon = '';
if (lastRanking != null) {
if (entry.id in lastRanking) {
if (entry.rank < lastRanking[entry.id]) { icon = 'color-green2-dark fa-caret-up'; }
else if (entry.rank > lastRanking[entry.id]) { icon = 'color-red2-dark fa-caret-down'; }
else { icon = 'color-yellow2-dark fa-minus'; }
} else {
icon = 'color-green2-dark fa-caret-up';
}
icon = '<i class="font-16 fas ' + icon + '" style="width: 1.1em; text-align: center;"></i> ';
}
row.content += '<div>' + icon + '<b>' + entry.rank + '.</b></div>';
// m
row.content += '<div>m = ' + entry.m + '</div>';
// rlp
row.content += '<div>' + entry.rlp.toFixed(3) + '</div>';
row.content += '</div>';
// ZEILE 2
row.content += '<div>';
// Name
row.content += '<div><b>' + entry.name + '</b></div>';
// Year
row.content += '<div>' + ((entry.year != null) ? ('(' + entry.year + ')') : '') + '</div>';
row.content += '</div></div>';
rows.push(row);
}
if (!dsvEnd) {
rows.push(null);
}
drawList();
} else {
$('#div-rank').html('Keine Ergebnisse gefunden!');
$('#input-search').parent().hide();
}
hideLoader();
}

77
server/scripts/result.js Normal file
View File

@@ -0,0 +1,77 @@
var siteScript = async function() {
var regattaId = findGetParameter('regatta');
if (regattaId == null) {
$('#h1-title').text('Regatta nicht gefunden');
hideLoader();
return;
}
var regatta = await dbGetData('regattas', regattaId);
if (regatta == null) {
$('#h1-title').text('Regatta nicht gefunden');
hideLoader();
return;
}
var dateFrom = parseDate(regatta['date']);
var dateTo = parseDate(regatta['date']);
dateTo.setDate(dateTo.getDate() + Math.max(parseInt(regatta['length']) - 1, 0));
$('#h1-title').text(regatta.name);
$('#p-title').text(formatDate('d.m.Y', dateFrom) + ' - ' + formatDate('d.m.Y', dateTo));
var results = await dbGetResultCalculated(regatta);
if (results.length > 0) {
var m;
if (regatta.m > 0) {
m = regatta.m;
} else if (regatta.races <= 4) {
m = regatta.races;
} else {
if ((regatta.length > 2) && (regatta.races >= 6)) {
m = 5;
} else {
m = 4;
}
}
$('#p-info').text(regatta.races + ' Wettfahrten, ' + regatta.streicher + ' Streicher, m = ' + m);
$('#table-results').show();
var thead = '<tr><th>#</th><th>Boot</th><th>Crew</th><th></th>';
for (var i = 1; i <= regatta.races; i ++) thead += '<th>WF ' + i + '</th>';
thead += '<th></th><th>Summe</th><th>Netto</th><th>#</th><th>RLP</th></tr>';
$('#table-results').find('thead').html(thead);
var tbody = '';
for (var r in results) {
var result = results[r];
var boat = await dbGetData('boats', result.boat);
var steuermann = (await dbGetData('sailors', result.steuermann)).name;
var cr = result.crew.split(',');
var crew = [];
for (c in cr) {
var s = await dbGetData('sailors', cr[c]);
if (s != null) crew.push(s.name);
}
tbody += '<tr>';
tbody += '<td>' + result.place + '.</td>';
tbody += '<td>' + boat.sailnumber + '<br>' + boat.name + '</td>';
tbody += '<td>' + steuermann + '<br>' + crew.join('<br>') + '</td>';
tbody += '<td></td>';
for (var i = 0; i < regatta.races; i ++) {
tbody += '<td>' + result.texts[i] + '</td>';
}
tbody += '<td></td>';
tbody += '<td>' + result.brutto + '</td>';
tbody += '<td>' + result.netto + '</td>';
tbody += '<td>' + result.place + '.</td>';
tbody += '<td>' + parseFloat(result.rlp).toFixed(2) + '</td>';
tbody += '</tr>';
}
$('#table-results').find('tbody').html(tbody);
} else {
$('#p-info').text('Keine Ergebnisse gefunden.');
$('#table-results').hide();
}
hideLoader();
}

View File

@@ -0,0 +1,5 @@
<div class="fac fac-checkbox fac-blue $$css-class;">
<span></span>
<input id="$$html-id;" type="checkbox" $$checked; />
<label for="$$html-id;">$$placeholder;</label>
</div>