new ranking calculation (via ranking DB table)

This commit is contained in:
ostertun
2022-04-27 13:13:41 +02:00
parent 6c547d43c5
commit 7b6ad832a9
3 changed files with 173 additions and 93 deletions

View File

@@ -1,4 +1,4 @@
const DB_VERSION = 7;
const DB_VERSION = 8;
const USER_ID = localStorage.getItem('auth_user');
const USER_NAME = localStorage.getItem('auth_username');
@@ -262,6 +262,9 @@ function dbGetRanking(minDate, maxDate, maxAge, ageStrict, altM = 9, ageCrew = f
return new Promise(async function(resolve) {
var rankNoResults = [];
// TODO: remove / Abwärtskompatibilität
//if (maxAge === true) maxAge = await dbGetClassProp('youth-age');
var sailors = await dbGetData('sailors');
var regattas = await dbGetRegattasRange(minDate, maxDate);
@@ -570,7 +573,7 @@ function sync() {
localTimes[entry['table']] = entry['time'];
});
syncInProgress = 12;
syncInProgress = 13;
var syncOkay = true;
log("[db] Sync Start");
$('#i-sync').addClass('fa-spin');
@@ -618,6 +621,33 @@ function sync() {
}
});
// RANKINGS
getJSON(QUERY_URL + 'get_rankings', function (code, data) {
if (code == 200) {
var os = db.transaction('rankings', 'readwrite').objectStore('rankings');
data.data.forEach(function (entry) {
os.put(entry);
});
os.openCursor().onsuccess = function (event) {
var cursor = event.target.result;
if (cursor) {
if (!data.keys.includes(parseInt(cursor.key))) {
os.delete(cursor.key);
}
cursor.continue();
} else {
syncInProgress --;
log('[db] rankings synced, remaining:', syncInProgress);
}
};
} else {
log("[db] rankings: Something went wrong (HTTP " + code + ")");
syncOkay = false;
syncInProgress --;
log('[db] rankings failed, remaining:', syncInProgress);
}
});
// CLUBS
if (localTimes['clubs'] < serverTimes['clubs']) {
getJSON(QUERY_URL + 'get_clubs?changed-after=' + localTimes['clubs'], function (code, data) {
@@ -1155,6 +1185,11 @@ function initDatabase() {
var osClass = db.createObjectStore('class', { keyPath: 'key' });
}
if ((oldVersion < 8) && (newVersion >= 8)) {
log('[db] to version 8');
var osRankings = db.createObjectStore('rankings', { keyPath: 'id' });
}
// Force resync after db update
if (oldVersion >= 1) {
var osUpdateTimes = upgradeTransaction.objectStore('update_times');