mirror of
https://github.com/psforever/PSFPortal.git
synced 2026-07-12 23:14:39 +00:00
More stats and faces
This commit is contained in:
parent
d6c50014dc
commit
9179125e98
112 changed files with 512 additions and 337 deletions
51
api/db.js
51
api/db.js
|
|
@ -68,6 +68,8 @@ export const AVATAR = Object.freeze({
|
|||
NAME: Symbol("name"),
|
||||
BEP: Symbol("bep"),
|
||||
CEP: Symbol("cep"),
|
||||
GENDER: Symbol("gender_id"),
|
||||
HEAD: Symbol("head_id"),
|
||||
});
|
||||
|
||||
export const WEAPONSTAT = Object.freeze({
|
||||
|
|
@ -348,12 +350,24 @@ export async function get_weaponstats_by_avatar(id) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function get_killstats() {
|
||||
export async function get_avatar(id) {
|
||||
try {
|
||||
const kills = await pool.query('SELECT count(killactivity.killer_id), killactivity.killer_id, avatar.name, avatar.bep, avatar.cep, avatar.faction_id' +
|
||||
const avatar = await pool.query('SELECT id, name, faction_id, bep, cep, gender_id, head_id FROM avatar WHERE id=$1', [id])
|
||||
return avatar.rows[0];
|
||||
} catch (e) {
|
||||
if (e.code)
|
||||
e.code = pg_error_inv[e.code]
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function get_top_kills() {
|
||||
try {
|
||||
const kills = await pool.query('SELECT count(killactivity.killer_id), killactivity.killer_id, avatar.name, avatar.bep,' +
|
||||
' avatar.cep, avatar.faction_id, avatar.gender_id, avatar.head_id' +
|
||||
' FROM killactivity' +
|
||||
' INNER JOIN avatar ON killactivity.killer_id = avatar.id' +
|
||||
' GROUP BY killactivity.killer_id, avatar.name, avatar.bep, avatar.cep, avatar.faction_id' +
|
||||
' GROUP BY killactivity.killer_id, avatar.name, avatar.bep, avatar.cep, avatar.faction_id, avatar.gender_id, avatar.head_id' +
|
||||
' ORDER BY count(killer_id) DESC')
|
||||
return kills.rows;
|
||||
} catch (e) {
|
||||
|
|
@ -363,6 +377,37 @@ export async function get_killstats() {
|
|||
}
|
||||
}
|
||||
|
||||
export async function get_avatar_kd_byDate(id) {
|
||||
try {
|
||||
const kd = await pool.query("SELECT TO_CHAR(timestamp, 'FMMon DD, YYYY') AS date," +
|
||||
' SUM(CASE WHEN killer_id = $1 THEN 1 ELSE 0 END)::int AS kills,' +
|
||||
' SUM(CASE WHEN victim_id = $1 THEN 1 ELSE 0 END)::int AS deaths' +
|
||||
' FROM killactivity GROUP BY date HAVING' +
|
||||
' SUM(CASE WHEN killer_id = $1 THEN 1 ELSE 0 END) > 0 OR SUM(CASE WHEN victim_id = $1 THEN 1 ELSE 0 END) > 0' +
|
||||
' ORDER BY date DESC', [id])
|
||||
return kd.rows;
|
||||
} catch (e) {
|
||||
if (e.code)
|
||||
e.code = pg_error_inv[e.code]
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function get_top_kills_byDate() {
|
||||
try {
|
||||
const kills = await pool.query('WITH RankedKills AS (SELECT COUNT(*)::int AS kill_count,' +
|
||||
' killer_id, DATE(timestamp) AS kill_date, ROW_NUMBER() OVER (PARTITION BY killer_id ORDER BY COUNT(*) DESC)::int AS row_num' +
|
||||
' FROM killactivity GROUP BY killer_id, DATE(timestamp)) SELECT rk.kill_count, rk.killer_id,' +
|
||||
" TO_CHAR(rk.kill_date, 'FMMon DD, YYYY') AS f_kill_date, rk.row_num, av.name, av.faction_id FROM RankedKills rk" +
|
||||
' JOIN avatar av ON rk.killer_id = av.id WHERE rk.row_num = 1 ORDER BY rk.kill_count DESC LIMIT 30')
|
||||
return kills.rows;
|
||||
} catch (e) {
|
||||
if (e.code)
|
||||
e.code = pg_error_inv[e.code]
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
export async function get_characters_by_account(account_id) {
|
||||
try {
|
||||
const characters = await pool.query('SELECT * FROM avatar WHERE account_id=$1 AND deleted=false', [account_id])
|
||||
|
|
|
|||
58
api/stats.js
58
api/stats.js
|
|
@ -58,9 +58,9 @@ api.get('/char_stats_cep/:batch', async (req, res, next) => {
|
|||
}
|
||||
});
|
||||
|
||||
api.get('/char_stats_kills', async (req, res, next) => {
|
||||
api.get('/top_kills', async (req, res, next) => {
|
||||
try {
|
||||
const kills = await db.get_killstats();
|
||||
const kills = await db.get_top_kills();
|
||||
res.status(200).json({ kills: kills });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
|
@ -68,4 +68,58 @@ api.get('/char_stats_kills', async (req, res, next) => {
|
|||
}
|
||||
});
|
||||
|
||||
api.get('/top_kills_byDate', async (req, res, next) => {
|
||||
try {
|
||||
const kills = await db.get_top_kills_byDate();
|
||||
res.status(200).json({ kills: kills });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.get('/weaponstats/:avatar', async (req, res, next) => {
|
||||
const avatar = req.params.avatar;
|
||||
|
||||
try {
|
||||
const weapons = await db.get_weaponstats_by_avatar(avatar);
|
||||
res.status(200).json({ weapons: weapons });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.get('/avatar/:avatar', async (req, res, next) => {
|
||||
const avatar = req.params.avatar;
|
||||
|
||||
try {
|
||||
const avatarData = await db.get_avatar(avatar);
|
||||
res.status(200).json({
|
||||
id: avatarData.id,
|
||||
name: avatarData.name,
|
||||
bep: avatarData.bep,
|
||||
cep: avatarData.cep,
|
||||
faction: avatarData.faction_id,
|
||||
gender: avatarData.gender_id,
|
||||
head: avatarData.head_id
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.get('/avatar/:avatar/kd_byDate', async (req, res, next) => {
|
||||
const avatar = req.params.avatar;
|
||||
|
||||
try {
|
||||
const kd = await db.get_avatar_kd_byDate(avatar);
|
||||
res.status(200).json({ kd: kd });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default api;
|
||||
12
api/user.js
12
api/user.js
|
|
@ -62,16 +62,4 @@ api.get('/user/:user/logins', NEED_SESSION, async (req, res, next) => {
|
|||
}
|
||||
});
|
||||
|
||||
api.get('/avatar/:avatar/weaponstats', async (req, res, next) => {
|
||||
const avatar = req.params.avatar;
|
||||
|
||||
try {
|
||||
const weapons = await db.get_weaponstats_by_avatar(avatar);
|
||||
res.status(200).json({ weapons: weapons });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default api;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue