Skip to content
Permalink
Browse files

Represent active rankings by the rows in table 'rankings'

A ranking is defined if it has a name.  Remove the 'ranking1', 'ranking2',
'ranking3', and 'ranking4' features.
  • Loading branch information...
Andreas Gruenbacher
Andreas Gruenbacher committed Jan 2, 2019
1 parent de623ae commit 553957831de7ebec387531531ed96c1f6122ee16
@@ -317,6 +317,30 @@ async function update_database(connection) {
CHANGE class ranking_class INT
`);
}

let ranking_features;
(await connection.queryAsync(`
SELECT COUNT(*) AS count
FROM event_features
WHERE feature LIKE 'ranking%'
`)).forEach((row) => {
ranking_features = row.count;
});

if (ranking_features) {
console.log('Converting rankings');
await connection.queryAsync(`
DELETE rankings
FROM rankings
LEFT JOIN event_features ON rankings.id = event_features.id AND ranking = MID(feature, 8)
WHERE event_features.id IS NULL
`);

await connection.queryAsync(`
DELETE FROM event_features
WHERE feature LIKE 'ranking%'
`);
}
}

pool.getConnectionAsync()
@@ -4200,7 +4224,7 @@ async function admin_export_csv(connection, id) {

let rankings = [];
for (let n = 1; n <= 4; n++) {
if (event.features['ranking' + n])
if (event.rankings[n - 1])
rankings.push(n);
}

@@ -4250,7 +4274,8 @@ async function admin_export_csv(connection, id) {
}

fields = fields.reduce(function(fields, field) {
if (event.features[field.name])
if (field.name.match(/^ranking\d+$/) ||
event.features[field.name])
fields.push(field.name);
return fields;
}, []);
@@ -428,7 +428,7 @@ function compute_event(cache, id, event) {
score are stored in rider.rankings[ranking - 1] as:
{rank: rank, score: score}. */
for (let ranking = 1; ranking <= 4; ranking++) {
if (!event.features['ranking' + ranking])
if (!event.rankings[ranking - 1])
continue;

for (let ranking_class in riders_per_class) {
@@ -46,14 +46,14 @@ async function compute_serie(connection, serie_id) {
(await connection.queryAsync(`
SELECT ranking, ranking_class, COUNT(*) AS events
FROM (
SELECT DISTINCT ranking_class, MID(feature, 8) + 0 AS ranking, id
SELECT DISTINCT ranking_class, ranking, id
FROM series_events
JOIN events USING (id)
JOIN event_features USING (id)
JOIN rankings USING (id)
JOIN classes USING (id)
JOIN series_classes USING (serie, ranking_class)
WHERE serie = ? AND enabled AND feature LIKE 'ranking%' AND
(ranking <> 'ranking1' OR NOT COALESCE(no_ranking1, 0))
JOIN series_classes USING (serie, ranking, ranking_class)
WHERE serie = ? AND enabled AND
(ranking <> 1 OR NOT COALESCE(no_ranking1, 0))
) AS _
GROUP BY ranking, ranking_class
`, [serie_id])).forEach((row) => {
@@ -107,8 +107,14 @@
SELECT feature
FROM event_features
WHERE id = ?
UNION
SELECT CONCAT('ranking', ranking) AS feature
FROM rankings
WHERE id = ?
});
$sth->execute($letzte_id);
$sth->execute($letzte_id, $letzte_id);
while (my @row = $sth->fetchrow_array) {
$features->{$features_map->{$row[0]}} = 1
if exists $features_map->{$row[0]};
@@ -85,8 +85,14 @@
SELECT feature
FROM event_features
WHERE id = ?
UNION
SELECT CONCAT('ranking', ranking) AS feature
FROM rankings
WHERE id = ?
});
$sth->execute($id);
$sth->execute($id, $id);
while (my @row = $sth->fetchrow_array) {
$features->{$features_map->{$row[0]}} = 1
if exists $features_map->{$row[0]};
@@ -78,7 +78,7 @@ var eventScoresController = [
$scope.rankings = (function() {
var rankings = [];
angular.forEach(event.rankings, function(ranking, index) {
if (features['ranking' + (index + 1)])
if (event.rankings[index])
rankings.push({ ranking: index + 1, name: ranking.name });
});
return rankings;
@@ -576,7 +576,7 @@ var eventScoresController = [

var search = $location.search();
var defaults = {
ranking: features.ranking1 ? 1 : null,
ranking: event.rankings[0] ? 1 : null,
field: fields,
'page-size': 'A4',
'font-size': 8,
@@ -384,7 +384,7 @@ var eventListController = [
heading: name,
expr: "rankings[" + (ranking - 1) + "] ? 'Ja' : ''",
style: { 'text-align': 'center' },
when: function() { return features['ranking' + ranking]; }
when: function() { return event.rankings[ranking - 1]; }
};
});
angular.forEach(defined_fields, function(field) {
@@ -95,7 +95,7 @@ <h1><a href="" ng-click="settings($event)">{{event.title}}</a></h1>
</select>
</td>
</tr>
<tr ng-repeat="ranking in [1,2,3,4]" ng-if="features['ranking' + ranking] && ((show.riders && event.rankings[ranking - 1].riders) || (show.groups && event.rankings[ranking - 1].groups))">
<tr ng-repeat="ranking in [1,2,3,4]" ng-if="event.rankings[ranking - 1] && ((show.riders && event.rankings[ranking - 1].riders) || (show.groups && event.rankings[ranking - 1].groups))">
<th>{{ranking_name(ranking)}}</th>
<td>
<select ng-model="show['ranking' + ranking]" yes-no-null>
@@ -28,7 +28,7 @@ var ridersController = [
var features = event.features;
features.rankings = [];
for (var n = 1; n <= event.rankings.length; n++) {
if ('ranking' + n in features)
if (event.rankings[n - 1])
features.rankings.push(n);
}
if (groups) {
@@ -310,7 +310,7 @@ var ridersController = [
Gruppenwertungen, und für Gruppen die Fahrerwertungen. */
if (rider.start) {
angular.forEach(rider.rankings, function(ranking, index) {
if (ranking && !features['ranking' + (index + 1)])
if (ranking && !event.rankings[index])
rider.rankings[index] = false;
});
}
@@ -365,7 +365,7 @@ var ridersController = [
'group': groups,
'class': null,
'number': null,
'rankings': features.ranking1 ? [ event.ranking1_enabled ] : [],
'rankings': event.rankings[0] ? [ event.ranking1_enabled ] : [],
'insurance': event.insurance,
'verified': true,
'future_starts': {}
@@ -243,6 +243,17 @@ var settingsController = [
event.features = $scope.features;
collapse_scores(event.scores);

function trim_array(array) {
while (array.length && array[array.length - 1] == null)
array.pop()
}

event.rankings.forEach(function(ranking, index) {
if (ranking.name === null || ranking.name === '')
delete event.rankings[index];
});
trim_array(event.rankings);

var future_events = event.future_events;
var future_event = future_events[future_events.length - 1];
if (future_event &&
@@ -247,8 +247,6 @@ <h1>{{event.title}} – Einstellungen</h1>
<label for="feature_last_name">Nachname</label><br>
<input type="checkbox" ng-model="features.first_name" id="feature_first_name" disabled="disabled">
<label for="feature_first_name">Vorname</label><br>
<input type="checkbox" ng-model="features.ranking1" id="feature_ranking1">
<label for="feature_ranking1">Wertung 1</label><br>
<input type="checkbox" ng-model="features.registered" id="feature_registered">
<label for="feature_registered">Nennungseingang</label><br>
<input type="checkbox" ng-model="features.start" id="feature_start" disabled="disabled">
@@ -300,12 +298,6 @@ <h1>{{event.title}} – Einstellungen</h1>
<label for="feature_start_time">Startzeit</label><br>
<input type="checkbox" ng-model="features.finish_time" id="feature_finish_time">
<label for="feature_finish_time">Zielzeit</label><br>
<input type="checkbox" ng-model="features.ranking2" id="feature_ranking2">
<label for="feature_ranking2">Wertung 2</label><br>
<input type="checkbox" ng-model="features.ranking3" id="feature_ranking3">
<label for="feature_ranking3">Wertung 3</label><br>
<input type="checkbox" ng-model="features.ranking4" id="feature_ranking4">
<label for="feature_ranking4">Wertung 4</label><br>
<input type="checkbox" ng-model="features.entry_fee" id="feature_entry_fee">
<label for="feature_entry_fee">Nenngeld</label><br>
<input type="checkbox" ng-model="features.insurance" id="feature_insurance">

0 comments on commit 5539578

Please sign in to comment.
You can’t perform that action at this time.