Compare commits
2 commits
main
...
niumside-p
Author | SHA1 | Date | |
---|---|---|---|
d00c8297e3 | |||
de450af558 |
6 changed files with 450 additions and 335 deletions
666
Cargo.lock
generated
666
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
27
nomad/agg-population.nomad.hcl
Normal file
27
nomad/agg-population.nomad.hcl
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
job "agg-population" {
|
||||||
|
type = "service"
|
||||||
|
|
||||||
|
update {
|
||||||
|
max_parallel = 1
|
||||||
|
stagger = "10s"
|
||||||
|
}
|
||||||
|
|
||||||
|
group "api" {
|
||||||
|
count = 1
|
||||||
|
|
||||||
|
network {
|
||||||
|
port "http" {
|
||||||
|
static = 3000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task "api" {
|
||||||
|
driver = "docker"
|
||||||
|
|
||||||
|
config {
|
||||||
|
image = "ghcr.io/genudine/agg-population/agg-population:latest"
|
||||||
|
ports = ["http"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
sources::{fisu, honu, saerro, sanctuary, voidwell},
|
sources::{fisu, honu, niumside, saerro, sanctuary, voidwell},
|
||||||
types::{Population, Response},
|
types::{Population, Response},
|
||||||
};
|
};
|
||||||
use axum::{
|
use axum::{
|
||||||
|
@ -52,9 +52,10 @@ pub async fn get_world(
|
||||||
let mut populations: Vec<Population> = Vec::new();
|
let mut populations: Vec<Population> = Vec::new();
|
||||||
|
|
||||||
let mut set = JoinSet::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 { ("honu", honu(world).await) });
|
||||||
set.spawn(async move { ("fisu", fisu(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 { ("voidwell", voidwell(world).await) });
|
||||||
set.spawn(async move { ("sanctuary", sanctuary(world).await) });
|
set.spawn(async move { ("sanctuary", sanctuary(world).await) });
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
<div>
|
<div>
|
||||||
<b>tl;dr:</b><br />
|
<b>tl;dr:</b><br />
|
||||||
<span class="big-header"
|
<span class="big-header"
|
||||||
>( fisu + honu + saerro + sanctuary + voidwell ) / 5</span
|
>( fisu + honu + saerro + sanctuary + voidwell + niumside ) / 6</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<div class="api-list">
|
<div class="api-list">
|
||||||
|
|
10
src/main.rs
10
src/main.rs
|
@ -49,14 +49,8 @@ async fn main() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let addr = SocketAddr::from((
|
let addr = SocketAddr::from(([0, 0, 0, 0], 3000));
|
||||||
[0, 0, 0, 0],
|
tracing::debug!("listening on {}", addr);
|
||||||
std::env::var("PORT")
|
|
||||||
.unwrap_or("3000".to_string())
|
|
||||||
.parse()
|
|
||||||
.unwrap(),
|
|
||||||
));
|
|
||||||
tracing::debug!("listening on http://{}", addr);
|
|
||||||
axum::Server::bind(&addr)
|
axum::Server::bind(&addr)
|
||||||
.serve(app.into_make_service())
|
.serve(app.into_make_service())
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -247,3 +247,78 @@ pub async fn sanctuary(world: i32) -> Result<Population, ()> {
|
||||||
+ response.world_population_list[0].population.nso,
|
+ 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