add niumside

This commit is contained in:
41666 2023-07-08 01:23:19 -04:00
parent 6b9c879ba7
commit de450af558
3 changed files with 114 additions and 3 deletions

View file

@ -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<Population> = 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) });

View file

@ -43,7 +43,7 @@
<div>
<b>tl;dr:</b><br />
<span class="big-header"
>( fisu + honu + saerro + sanctuary + voidwell ) / 5</span
>( fisu + honu + saerro + sanctuary + voidwell + niumside ) / 6</span
>
</div>
<div class="api-list">

View file

@ -247,3 +247,113 @@ pub async fn sanctuary(world: i32) -> Result<Population, ()> {
+ response.world_population_list[0].population.nso,
})
}
pub async fn niumside(world: i32) -> Result<Population, ()> {
#[derive(serde::Deserialize)]
struct Root {
pub pop: Vec<Pop>,
}
#[derive(serde::Deserialize)]
struct Pop {
pub zones: Vec<Zone>,
}
#[derive(serde::Deserialize)]
struct Zone {
pub factions: Vec<Faction>,
}
#[derive(serde::Deserialize)]
struct Faction {
pub faction_id: i32,
pub teams: Vec<Team>,
}
#[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::<Root>()
.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::<i32>()
})
.sum::<i32>();
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::<i32>()
})
.sum::<i32>();
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::<i32>()
})
.sum::<i32>();
Ok(Population {
nc,
tr,
vs,
total: nc + tr + vs,
})
}