restructure for equatorprice
This commit is contained in:
58
src/model/personal/equatorprice.rs
Normal file
58
src/model/personal/equatorprice.rs
Normal file
@ -0,0 +1,58 @@
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize)]
|
||||
enum Level {
|
||||
BRONZE,
|
||||
SILVER,
|
||||
GOLD,
|
||||
DIAMOND,
|
||||
DONE,
|
||||
}
|
||||
|
||||
impl Level {
|
||||
fn required_km(&self) -> i32 {
|
||||
match self {
|
||||
Level::BRONZE => 40000,
|
||||
Level::SILVER => 80000,
|
||||
Level::GOLD => 100000,
|
||||
Level::DIAMOND => 200000,
|
||||
Level::DONE => 0,
|
||||
}
|
||||
}
|
||||
|
||||
fn next_level(km: i32) -> Self {
|
||||
if km < Level::BRONZE.required_km() {
|
||||
Level::BRONZE
|
||||
} else if km < Level::SILVER.required_km() {
|
||||
Level::SILVER
|
||||
} else if km < Level::GOLD.required_km() {
|
||||
Level::GOLD
|
||||
} else if km < Level::DIAMOND.required_km() {
|
||||
Level::BRONZE
|
||||
} else {
|
||||
Level::DONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub(crate) struct Next {
|
||||
level: Level,
|
||||
missing_km: i32,
|
||||
required_km: i32,
|
||||
rowed_km: i32,
|
||||
}
|
||||
|
||||
impl Next {
|
||||
pub(crate) fn rowed_km(km: i32) -> Self {
|
||||
let level = Level::next_level(km);
|
||||
let required_km = level.required_km();
|
||||
let missing_km = required_km - km;
|
||||
Self {
|
||||
level,
|
||||
missing_km,
|
||||
required_km,
|
||||
rowed_km: km,
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user