From de450af5587be04313180949d6b60e706b44e846 Mon Sep 17 00:00:00 2001 From: Katalina Okano Date: Sat, 8 Jul 2023 01:23:19 -0400 Subject: [PATCH] add niumside --- src/handlers.rs | 5 +- src/html/index.html | 2 +- src/sources.rs | 110 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+), 3 deletions(-) diff --git a/src/handlers.rs b/src/handlers.rs index 2d7ba0b..4db3142 100644 --- a/src/handlers.rs +++ b/src/handlers.rs @@ -1,5 +1,5 @@ use crate::{ - sources::{fisu, honu, saerro, sanctuary, voidwell}, + sources::{fisu, honu, niumside, saerro, sanctuary, voidwell}, types::{Population, Response}, }; use axum::{ @@ -52,9 +52,10 @@ pub async fn get_world( let mut populations: Vec = Vec::new(); let mut set = JoinSet::new(); - set.spawn(async move { ("saerro", saerro(world).await) }); set.spawn(async move { ("honu", honu(world).await) }); set.spawn(async move { ("fisu", fisu(world).await) }); + set.spawn(async move { ("saerro", saerro(world).await) }); + set.spawn(async move { ("niumside", niumside(world).await) }); set.spawn(async move { ("voidwell", voidwell(world).await) }); set.spawn(async move { ("sanctuary", sanctuary(world).await) }); diff --git a/src/html/index.html b/src/html/index.html index ce23ca2..8205065 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -43,7 +43,7 @@
tl;dr:
( fisu + honu + saerro + sanctuary + voidwell ) / 5( fisu + honu + saerro + sanctuary + voidwell + niumside ) / 6
diff --git a/src/sources.rs b/src/sources.rs index 872bb04..4a71e62 100644 --- a/src/sources.rs +++ b/src/sources.rs @@ -247,3 +247,113 @@ pub async fn sanctuary(world: i32) -> Result { + response.world_population_list[0].population.nso, }) } + +pub async fn niumside(world: i32) -> Result { + #[derive(serde::Deserialize)] + struct Root { + pub pop: Vec, + } + + #[derive(serde::Deserialize)] + struct Pop { + pub zones: Vec, + } + + #[derive(serde::Deserialize)] + struct Zone { + pub factions: Vec, + } + + #[derive(serde::Deserialize)] + struct Faction { + pub faction_id: i32, + pub teams: Vec, + } + + #[derive(serde::Deserialize)] + struct Team { + pub team_id: i32, + pub team_population: i32, + } + + let url = format!( + "https://niumside-poptracker.shuttleapp.rs/api/population?world={}", + world + ); + let response = reqwest::get(url) + .await + .unwrap() + .json::() + .await + .unwrap(); + + let vs: i32 = response + .pop + .iter() + .map(|pop| { + pop.zones + .iter() + .map(|zone| { + zone.factions + .iter() + .find(|faction| faction.faction_id == 1 || faction.faction_id == 4) + .unwrap() + .teams + .iter() + .find(|team| team.team_id == 1) + .unwrap() + .team_population + }) + .sum::() + }) + .sum::(); + + let nc: i32 = response + .pop + .iter() + .map(|pop| { + pop.zones + .iter() + .map(|zone| { + zone.factions + .iter() + .find(|faction| faction.faction_id == 2 || faction.faction_id == 4) + .unwrap() + .teams + .iter() + .find(|team| team.team_id == 2) + .unwrap() + .team_population + }) + .sum::() + }) + .sum::(); + + let tr: i32 = response + .pop + .iter() + .map(|pop| { + pop.zones + .iter() + .map(|zone| { + zone.factions + .iter() + .find(|faction| faction.faction_id == 3 || faction.faction_id == 4) + .unwrap() + .teams + .iter() + .find(|team| team.team_id == 3) + .unwrap() + .team_population + }) + .sum::() + }) + .sum::(); + + Ok(Population { + nc, + tr, + vs, + total: nc + tr + vs, + }) +}