Some fixes

This commit is contained in:
furo 2021-11-01 22:49:52 +01:00
parent 089e0d6fb7
commit f90312a7c7
5 changed files with 18 additions and 28 deletions

View File

@ -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 })

View File

@ -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,

View File

@ -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

View File

@ -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" (

View File

@ -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
)
}