From f90312a7c705e42a174c6e30b80c8f1a8dec3f7b Mon Sep 17 00:00:00 2001 From: furo Date: Mon, 1 Nov 2021 22:49:52 +0100 Subject: [PATCH] Some fixes --- api/graph.js | 3 ++- api/maps.js | 2 +- api/players.js | 2 +- libs/database/generate.js | 11 ++--------- libs/database/tasks.js | 28 ++++++++++++---------------- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/api/graph.js b/api/graph.js index 2b27ddf..8e72a39 100644 --- a/api/graph.js +++ b/api/graph.js @@ -25,8 +25,9 @@ graphApi.get( GROUP BY a.map ORDER BY a.date; `) - + let currentPoints = 0 let array = [] + for (const finish of finishes.iterate(player)) { currentPoints += finish.points array.push({ t: new Date(finish.date), y: currentPoints }) diff --git a/api/maps.js b/api/maps.js index b3582f9..851ff06 100644 --- a/api/maps.js +++ b/api/maps.js @@ -71,7 +71,7 @@ mapApi.get( let category = req.params.category /* Check if category exists */ - const check = sqlite.prepare(`SELECT category FROM maps WHERE server = ? LIMIT 1`).get(category) + const check = sqlite.prepare(`SELECT category FROM maps WHERE category = ? LIMIT 1`).get(category) if (!check) { return res.json({ success: false, diff --git a/api/players.js b/api/players.js index cc9b511..94634a7 100644 --- a/api/players.js +++ b/api/players.js @@ -14,7 +14,7 @@ playerApi.get( /* Points */ let points = {} - const pointsData = sqlite.prepare(`SELECT type, rank, points FROM points WHERE name = ?`) + const pointsData = sqlite.prepare(`SELECT type, rank, points FROM points WHERE player = ?`) for (const pointsType of pointsData.iterate(player)) { points[pointsType.type] = pointsType diff --git a/libs/database/generate.js b/libs/database/generate.js index e3214a3..4cb71fb 100644 --- a/libs/database/generate.js +++ b/libs/database/generate.js @@ -18,7 +18,7 @@ export function generateDB() { return log("Database already generated!") /* Check if columns are already renamed */ - const renamed = sqlite.prepare(`SELECT COUNT(*) AS CNTREC FROM pragma_table_info('race') WHERE name='date'`).get() + const renamed = sqlite.prepare(`SELECT COUNT(*) AS a FROM pragma_table_info('race') WHERE name='date'`).get() if(!renamed.a === 0) { log("Renaming columns...") @@ -77,7 +77,7 @@ export function generateDB() { execMany([ `CREATE INDEX IF NOT EXISTS "idx_rankings_map" ON "rankings" ("map")`, `CREATE INDEX IF NOT EXISTS "idx_rankings_rank" ON "rankings" ("rank")`, - `CREATE INDEX IF NOT EXISTS "idx_rankings_player" ON "rankings" ("Name")` + `CREATE INDEX IF NOT EXISTS "idx_rankings_player" ON "rankings" ("player")` ]) log("Generating teamrace index...") @@ -109,13 +109,6 @@ export function generateDB() { `CREATE INDEX IF NOT EXISTS "idx_teamrankings_player" ON "teamrankings" ("player")` ]) - sqlite.exec(` - CREATE TABLE IF NOT EXISTS "points" ( - "rank" INTEGER NOT NULL, - "player" varchar(16) NOT NULL, - "points" INTEGER NOT NULL); - `) - log("Generating graphRecordCache...") sqlite.exec(` CREATE TABLE IF NOT EXISTS "graphRecordCache" ( diff --git a/libs/database/tasks.js b/libs/database/tasks.js index 47ac4fe..eaf4e0b 100644 --- a/libs/database/tasks.js +++ b/libs/database/tasks.js @@ -6,7 +6,7 @@ import { sqlite } from './init.js' /** * This module parses the msgpack provided by DDNet... - * @module db/decodeMsgpack + * @module libs/database/decodeMsgpack */ export function decodeMsgpack() { const data = fs.readFileSync('players.msgpack') @@ -24,10 +24,10 @@ export function decodeMsgpack() { /** * This generates rankings for each map... - * @module db/processRankings + * @module libs/database/processRankings */ export function processRankings() { - const maps = sqlite.prepare(`SELECT map FROM maps`); + const maps = sqlite.prepare(`SELECT map FROM maps`) for (const map of maps.iterate()) sqlite @@ -49,15 +49,15 @@ export function processRankings() { GROUP BY player window w AS (ORDER BY time) ) AS a ORDER BY rank `) - .run(map.Map) + .run(map.map) } /** * This generates teamrankings for each map... - * @module db/processTeamRankings + * @module libs/database/processTeamRankings */ export function processTeamRankings() { - const maps = sqlite.prepare(`SELECT map FROM maps`); + const maps = sqlite.prepare(`SELECT map FROM maps`) for (const map of maps.iterate()) sqlite @@ -91,18 +91,14 @@ export function processTeamRankings() { * @module libs/database/processTimeGraph */ export function processTimeGraph() { - - let currentFinish - let currentBest = 0; - - const maps = sqlite.prepare(`SELECT map FROM maps`); + const maps = sqlite.prepare(`SELECT map FROM maps`) const finishes = sqlite.prepare(`SELECT * FROM race WHERE map = ? ORDER BY date`) for (const map of maps.iterate()) { let currentFinish - let currentBest = 0; + let currentBest = 0 for (const record of finishes.iterate(map.map)) { - currentFinish = record.Time + currentFinish = record.time if (currentFinish <= currentBest || currentBest == 0) { currentBest = currentFinish @@ -112,10 +108,10 @@ export function processTimeGraph() { map, player, time, date, server ) VALUES (?, ?, ?, ?, ?) `).run( - map.Map, - record.name, + map.map, + record.player, record.time, - record.timestamp, + record.date, record.server ) }