Some fixes
This commit is contained in:
parent
089e0d6fb7
commit
f90312a7c7
|
@ -25,8 +25,9 @@ graphApi.get(
|
||||||
GROUP BY a.map
|
GROUP BY a.map
|
||||||
ORDER BY a.date;
|
ORDER BY a.date;
|
||||||
`)
|
`)
|
||||||
|
let currentPoints = 0
|
||||||
let array = []
|
let array = []
|
||||||
|
|
||||||
for (const finish of finishes.iterate(player)) {
|
for (const finish of finishes.iterate(player)) {
|
||||||
currentPoints += finish.points
|
currentPoints += finish.points
|
||||||
array.push({ t: new Date(finish.date), y: currentPoints })
|
array.push({ t: new Date(finish.date), y: currentPoints })
|
||||||
|
|
|
@ -71,7 +71,7 @@ mapApi.get(
|
||||||
let category = req.params.category
|
let category = req.params.category
|
||||||
|
|
||||||
/* Check if category exists */
|
/* 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) {
|
if (!check) {
|
||||||
return res.json({
|
return res.json({
|
||||||
success: false,
|
success: false,
|
||||||
|
|
|
@ -14,7 +14,7 @@ playerApi.get(
|
||||||
|
|
||||||
/* Points */
|
/* Points */
|
||||||
let 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)) {
|
for (const pointsType of pointsData.iterate(player)) {
|
||||||
points[pointsType.type] = pointsType
|
points[pointsType.type] = pointsType
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function generateDB() {
|
||||||
return log("Database already generated!")
|
return log("Database already generated!")
|
||||||
|
|
||||||
/* Check if columns are already renamed */
|
/* 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) {
|
if(!renamed.a === 0) {
|
||||||
log("Renaming columns...")
|
log("Renaming columns...")
|
||||||
|
@ -77,7 +77,7 @@ export function generateDB() {
|
||||||
execMany([
|
execMany([
|
||||||
`CREATE INDEX IF NOT EXISTS "idx_rankings_map" ON "rankings" ("map")`,
|
`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_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...")
|
log("Generating teamrace index...")
|
||||||
|
@ -109,13 +109,6 @@ export function generateDB() {
|
||||||
`CREATE INDEX IF NOT EXISTS "idx_teamrankings_player" ON "teamrankings" ("player")`
|
`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...")
|
log("Generating graphRecordCache...")
|
||||||
sqlite.exec(`
|
sqlite.exec(`
|
||||||
CREATE TABLE IF NOT EXISTS "graphRecordCache" (
|
CREATE TABLE IF NOT EXISTS "graphRecordCache" (
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { sqlite } from './init.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This module parses the msgpack provided by DDNet...
|
* This module parses the msgpack provided by DDNet...
|
||||||
* @module db/decodeMsgpack
|
* @module libs/database/decodeMsgpack
|
||||||
*/
|
*/
|
||||||
export function decodeMsgpack() {
|
export function decodeMsgpack() {
|
||||||
const data = fs.readFileSync('players.msgpack')
|
const data = fs.readFileSync('players.msgpack')
|
||||||
|
@ -24,10 +24,10 @@ export function decodeMsgpack() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This generates rankings for each map...
|
* This generates rankings for each map...
|
||||||
* @module db/processRankings
|
* @module libs/database/processRankings
|
||||||
*/
|
*/
|
||||||
export function 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())
|
for (const map of maps.iterate())
|
||||||
sqlite
|
sqlite
|
||||||
|
@ -49,15 +49,15 @@ export function processRankings() {
|
||||||
GROUP BY player window w AS (ORDER BY time) ) AS a
|
GROUP BY player window w AS (ORDER BY time) ) AS a
|
||||||
ORDER BY rank
|
ORDER BY rank
|
||||||
`)
|
`)
|
||||||
.run(map.Map)
|
.run(map.map)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This generates teamrankings for each map...
|
* This generates teamrankings for each map...
|
||||||
* @module db/processTeamRankings
|
* @module libs/database/processTeamRankings
|
||||||
*/
|
*/
|
||||||
export function 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())
|
for (const map of maps.iterate())
|
||||||
sqlite
|
sqlite
|
||||||
|
@ -91,18 +91,14 @@ export function processTeamRankings() {
|
||||||
* @module libs/database/processTimeGraph
|
* @module libs/database/processTimeGraph
|
||||||
*/
|
*/
|
||||||
export function processTimeGraph() {
|
export function processTimeGraph() {
|
||||||
|
const maps = sqlite.prepare(`SELECT map FROM maps`)
|
||||||
let currentFinish
|
|
||||||
let currentBest = 0;
|
|
||||||
|
|
||||||
const maps = sqlite.prepare(`SELECT map FROM maps`);
|
|
||||||
const finishes = sqlite.prepare(`SELECT * FROM race WHERE map = ? ORDER BY date`)
|
const finishes = sqlite.prepare(`SELECT * FROM race WHERE map = ? ORDER BY date`)
|
||||||
for (const map of maps.iterate()) {
|
for (const map of maps.iterate()) {
|
||||||
let currentFinish
|
let currentFinish
|
||||||
let currentBest = 0;
|
let currentBest = 0
|
||||||
|
|
||||||
for (const record of finishes.iterate(map.map)) {
|
for (const record of finishes.iterate(map.map)) {
|
||||||
currentFinish = record.Time
|
currentFinish = record.time
|
||||||
if (currentFinish <= currentBest || currentBest == 0) {
|
if (currentFinish <= currentBest || currentBest == 0) {
|
||||||
currentBest = currentFinish
|
currentBest = currentFinish
|
||||||
|
|
||||||
|
@ -112,10 +108,10 @@ export function processTimeGraph() {
|
||||||
map, player, time, date, server
|
map, player, time, date, server
|
||||||
) VALUES (?, ?, ?, ?, ?)
|
) VALUES (?, ?, ?, ?, ?)
|
||||||
`).run(
|
`).run(
|
||||||
map.Map,
|
map.map,
|
||||||
record.name,
|
record.player,
|
||||||
record.time,
|
record.time,
|
||||||
record.timestamp,
|
record.date,
|
||||||
record.server
|
record.server
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user