Now all stats can be fetched...

This commit is contained in:
BurnyLlama 2023-04-15 21:07:44 +02:00
parent f25ff85276
commit 34b35e0795
4 changed files with 54 additions and 14 deletions

View File

@ -7,7 +7,7 @@ use crate::database::DatabaseHandler;
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)] #[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
pub struct Map { pub struct Map {
pub map: String, pub map: String,
pub mapper: String, pub mappers: Vec<String>,
pub category: String, pub category: String,
pub points: i16, pub points: i16,
pub stars: i16, pub stars: i16,
@ -22,7 +22,7 @@ impl Map {
sqlx::query_as!( sqlx::query_as!(
Map, Map,
" "
SELECT record_maps.map, category, points, stars, mapper, release, width, height, SELECT record_maps.map, category, points, stars, mappers, release, width, height,
string_to_array(CONCAT_WS(',', string_to_array(CONCAT_WS(',',
CASE WHEN DEATH = '1' THEN 'DEATH' END, CASE WHEN DEATH = '1' THEN 'DEATH' END,
CASE WHEN THROUGH = '1' THEN 'THROUGH' END, CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
@ -75,7 +75,7 @@ impl Map {
sqlx::query_as!( sqlx::query_as!(
Map, Map,
" "
SELECT record_maps.map, category, points, stars, mapper, release, width, height, SELECT record_maps.map, category, points, stars, mappers, release, width, height,
string_to_array(CONCAT_WS(',', string_to_array(CONCAT_WS(',',
CASE WHEN DEATH = '1' THEN 'DEATH' END, CASE WHEN DEATH = '1' THEN 'DEATH' END,
CASE WHEN THROUGH = '1' THEN 'THROUGH' END, CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
@ -133,7 +133,7 @@ impl Map {
sqlx::query_as!( sqlx::query_as!(
Map, Map,
" "
SELECT record_maps.map, category, points, stars, mapper, release, width, height, SELECT record_maps.map, category, points, stars, mappers, release, width, height,
string_to_array(CONCAT_WS(',', string_to_array(CONCAT_WS(',',
CASE WHEN DEATH = '1' THEN 'DEATH' END, CASE WHEN DEATH = '1' THEN 'DEATH' END,
CASE WHEN THROUGH = '1' THEN 'THROUGH' END, CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
@ -191,7 +191,7 @@ impl Map {
sqlx::query_as!( sqlx::query_as!(
Map, Map,
" "
SELECT record_maps.map, category, points, stars, mapper, release, width, height, SELECT record_maps.map, category, points, stars, mappers, release, width, height,
string_to_array(CONCAT_WS(',', string_to_array(CONCAT_WS(',',
CASE WHEN DEATH = '1' THEN 'DEATH' END, CASE WHEN DEATH = '1' THEN 'DEATH' END,
CASE WHEN THROUGH = '1' THEN 'THROUGH' END, CASE WHEN THROUGH = '1' THEN 'THROUGH' END,
@ -234,7 +234,7 @@ impl Map {
CASE WHEN PLASMAE = '1' THEN 'PLASMAE' END, CASE WHEN PLASMAE = '1' THEN 'PLASMAE' END,
CASE WHEN PLASMAU = '1' THEN 'PLASMAU' END), ',') AS tiles CASE WHEN PLASMAU = '1' THEN 'PLASMAU' END), ',') AS tiles
FROM record_maps JOIN record_mapinfo ON record_maps.map = record_mapinfo.map FROM record_maps JOIN record_mapinfo ON record_maps.map = record_mapinfo.map
WHERE mapper = $1; WHERE $1 = ANY(mappers)
", ",
mapper mapper
) )

View File

@ -1,2 +1,3 @@
pub mod map; pub mod map;
pub mod race; pub mod race;
pub mod teamrace;

View File

@ -5,14 +5,14 @@ use crate::database::DatabaseHandler;
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)] #[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
pub struct Race { pub struct Race {
name: Option<String>, pub name: String,
map: Option<String>, pub map: String,
time: Option<f64>, pub time: f32,
timestamp: Option<NaiveDateTime>, pub timestamp: NaiveDateTime,
server: Option<String>, pub server: String,
checkpoints: Option<Vec<f64>>, pub checkpoints: Option<Vec<f64>>,
gameid: Option<String>, pub gameid: Option<String>,
ddnet7: Option<i16>, pub ddnet7: i16,
} }
impl Race { impl Race {

View File

@ -0,0 +1,39 @@
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use crate::database::DatabaseHandler;
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
pub struct Teamrace {
pub players: Vec<String>,
pub map: String,
pub time: f32,
pub timestamp: NaiveDateTime,
}
impl Teamrace {
pub async fn get_teamrace_by_player(
db: &DatabaseHandler,
player: &str,
) -> Result<Vec<Teamrace>, sqlx::Error> {
sqlx::query_as!(
Teamrace,
"SELECT players, map, time, timestamp FROM record_teamrace_array WHERE $1 = ANY(players)",
player
).fetch_all(&db.pool)
.await
}
pub async fn get_teamrace_by_map(
db: &DatabaseHandler,
map: &str,
) -> Result<Vec<Teamrace>, sqlx::Error> {
sqlx::query_as!(
Teamrace,
"SELECT players, map, time, timestamp FROM record_teamrace_array WHERE map = $1",
map
)
.fetch_all(&db.pool)
.await
}
}