Compare commits
2 commits
main
...
niumside-p
Author | SHA1 | Date | |
---|---|---|---|
d00c8297e3 | |||
de450af558 |
3 changed files with 79 additions and 3 deletions
|
@ -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) });
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -247,3 +247,78 @@ 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();
|
||||
|
||||
fn extract(root: &Root, team_id: i32) -> i32 {
|
||||
root.pop
|
||||
.iter()
|
||||
.map(|pop| {
|
||||
pop.zones
|
||||
.iter()
|
||||
.map(|zone| {
|
||||
let faction = match zone.factions.iter().find(|faction| {
|
||||
faction.faction_id == team_id || faction.faction_id == 4
|
||||
}) {
|
||||
Some(faction) => faction,
|
||||
None => return 0,
|
||||
};
|
||||
|
||||
match faction.teams.iter().find(|team| team.team_id == team_id) {
|
||||
Some(team) => team.team_population,
|
||||
None => 0,
|
||||
}
|
||||
})
|
||||
.sum::<i32>()
|
||||
})
|
||||
.sum::<i32>()
|
||||
}
|
||||
|
||||
let vs = extract(&response, 1);
|
||||
let nc = extract(&response, 2);
|
||||
let tr = extract(&response, 3);
|
||||
|
||||
Ok(Population {
|
||||
nc,
|
||||
tr,
|
||||
vs,
|
||||
total: nc + tr + vs,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue