-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: config, demand, ticket, user, campaign
- Loading branch information
1 parent
1094e0b
commit 3a7e5a6
Showing
12 changed files
with
735 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum Airline { | ||
C4_4HR, | ||
C4_8HR, | ||
C4_12HR, | ||
C4_16HR, | ||
C4_20HR, | ||
C4_24HR, | ||
C3_4HR, | ||
C3_8HR, | ||
C3_12HR, | ||
C3_16HR, | ||
C3_20HR, | ||
C3_24HR, | ||
C2_4HR, | ||
C2_8HR, | ||
C2_12HR, | ||
C2_16HR, | ||
C2_20HR, | ||
C2_24HR, | ||
C1_4HR, | ||
C1_8HR, | ||
C1_12HR, | ||
C1_16HR, | ||
C1_20HR, | ||
C1_24HR, | ||
None, | ||
} | ||
|
||
impl Default for Airline { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum Eco { | ||
C4Hr, | ||
C8Hr, | ||
C12Hr, | ||
C16Hr, | ||
C20Hr, | ||
C24Hr, | ||
None, | ||
} | ||
|
||
impl Default for Eco { | ||
fn default() -> Self { | ||
Self::None | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct Campaign { | ||
pub pax_activated: Airline, | ||
pub cargo_activated: Airline, | ||
pub eco_activated: Eco, | ||
} | ||
|
||
impl Campaign { | ||
pub fn new(pax_activated: Airline, cargo_activated: Airline, eco_activated: Eco) -> Self { | ||
Self { | ||
pax_activated, | ||
cargo_activated, | ||
eco_activated, | ||
} | ||
} | ||
|
||
pub fn estimate_pax_reputation(&self, base_reputation: f64) -> f64 { | ||
let mut reputation = base_reputation; | ||
reputation += self._estimate_airline_reputation(self.pax_activated.clone()); | ||
reputation += self._estimate_eco_reputation(self.eco_activated.clone()); | ||
reputation | ||
} | ||
|
||
pub fn estimate_cargo_reputation(&self, base_reputation: f64) -> f64 { | ||
let mut reputation = base_reputation; | ||
reputation += self._estimate_airline_reputation(self.cargo_activated.clone()); | ||
reputation += self._estimate_eco_reputation(self.eco_activated.clone()); | ||
reputation | ||
} | ||
|
||
fn _estimate_airline_reputation(&self, airline: Airline) -> f64 { | ||
match airline { | ||
Airline::C4_4HR | ||
| Airline::C4_8HR | ||
| Airline::C4_12HR | ||
| Airline::C4_16HR | ||
| Airline::C4_20HR | ||
| Airline::C4_24HR => 30.0, | ||
Airline::C3_4HR | ||
| Airline::C3_8HR | ||
| Airline::C3_12HR | ||
| Airline::C3_16HR | ||
| Airline::C3_20HR | ||
| Airline::C3_24HR => 21.5, | ||
Airline::C2_4HR | ||
| Airline::C2_8HR | ||
| Airline::C2_12HR | ||
| Airline::C2_16HR | ||
| Airline::C2_20HR | ||
| Airline::C2_24HR => 14.0, | ||
Airline::C1_4HR | ||
| Airline::C1_8HR | ||
| Airline::C1_12HR | ||
| Airline::C1_16HR | ||
| Airline::C1_20HR | ||
| Airline::C1_24HR => 7.5, | ||
Airline::None => 0.0, | ||
} | ||
} | ||
|
||
fn _estimate_eco_reputation(&self, eco: Eco) -> f64 { | ||
match eco { | ||
Eco::C4Hr | Eco::C8Hr | Eco::C12Hr | Eco::C16Hr | Eco::C20Hr | Eco::C24Hr => 10.0, | ||
Eco::None => 0.0, | ||
} | ||
} | ||
|
||
fn _set(&mut self, s: &str) -> bool { | ||
match s.to_uppercase().as_str() { | ||
"C1" => { | ||
self.pax_activated = Airline::C1_24HR; | ||
self.cargo_activated = Airline::C1_24HR; | ||
true | ||
} | ||
"C2" => { | ||
self.pax_activated = Airline::C2_24HR; | ||
self.cargo_activated = Airline::C2_24HR; | ||
true | ||
} | ||
"C3" => { | ||
self.pax_activated = Airline::C3_24HR; | ||
self.cargo_activated = Airline::C3_24HR; | ||
true | ||
} | ||
"C4" => { | ||
self.pax_activated = Airline::C4_24HR; | ||
self.cargo_activated = Airline::C4_24HR; | ||
true | ||
} | ||
"E" => { | ||
self.eco_activated = Eco::C24Hr; | ||
true | ||
} | ||
_ => false, | ||
} | ||
} | ||
|
||
pub fn parse(s: &str) -> Self { | ||
let mut campaign = Self::default(); | ||
let s_upper = s.to_uppercase().replace(' ', ""); | ||
if s_upper.is_empty() { | ||
return campaign; | ||
} | ||
|
||
if let Some(pos) = s_upper.find(',') { | ||
campaign._set(&s_upper[..pos]); | ||
campaign._set(&s_upper[pos + 1..]); | ||
} else { | ||
campaign._set(&s_upper); | ||
} | ||
campaign | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
use crate::demand::cargo::CargoDemand; | ||
use crate::demand::pax::PaxDemand; | ||
|
||
pub struct CargoConfig { | ||
pub l: u8, | ||
pub h: u8, | ||
pub algorithm: CargoConfigAlgorithm, | ||
} | ||
|
||
pub enum CargoConfigAlgorithm { | ||
Auto, | ||
L, | ||
H, | ||
} | ||
|
||
impl CargoConfig { | ||
fn calc_l_conf( | ||
d_pf: &PaxDemand, | ||
capacity: u32, | ||
l_training: u8, | ||
h_training: u8, | ||
) -> Option<Self> { | ||
let d_pf_cargo = CargoDemand::from(*d_pf); | ||
|
||
let l_cap = capacity as f32 * 0.7 * (1.0 + l_training as f32 / 100.0); | ||
|
||
if d_pf_cargo.l as f32 > l_cap { | ||
return Some(CargoConfig { | ||
l: 100, | ||
h: 0, | ||
algorithm: CargoConfigAlgorithm::L, | ||
}); | ||
} | ||
|
||
let l = d_pf_cargo.l as f32 / l_cap; | ||
let h = 1. - l; | ||
if (d_pf_cargo.h as f32) < capacity as f32 * h * (1.0 + h_training as f32 / 100.0) { | ||
None | ||
} else { | ||
let lu = (l * 100.0) as u8; | ||
|
||
Some(CargoConfig { | ||
l: lu, | ||
h: 100 - lu, | ||
algorithm: CargoConfigAlgorithm::L, | ||
}) | ||
} | ||
} | ||
|
||
fn calc_h_conf( | ||
d_pf: &PaxDemand, | ||
capacity: u32, | ||
l_training: u8, | ||
h_training: u8, | ||
) -> Option<Self> { | ||
let d_pf_cargo = CargoDemand::from(*d_pf); | ||
|
||
let h_cap = capacity as f32 * (1.0 + h_training as f32 / 100.0); | ||
|
||
if d_pf_cargo.h as f32 > h_cap { | ||
return Some(CargoConfig { | ||
l: 0, | ||
h: 100, | ||
algorithm: CargoConfigAlgorithm::H, | ||
}); | ||
} | ||
|
||
let h = d_pf_cargo.h as f32 / h_cap; | ||
let l = 1. - h; | ||
if (d_pf_cargo.l as f32) < capacity as f32 * l * 0.7 * (1.0 + l_training as f32 / 100.0) { | ||
None | ||
} else { | ||
let hu = (h * 100.0) as u8; | ||
|
||
Some(CargoConfig { | ||
l: 100 - hu, | ||
h: hu, | ||
algorithm: CargoConfigAlgorithm::H, | ||
}) | ||
} | ||
} | ||
|
||
pub fn calculate_cargo_config( | ||
d_pf: &PaxDemand, | ||
capacity: u32, | ||
l_training: u8, | ||
h_training: u8, | ||
algorithm: CargoConfigAlgorithm, | ||
) -> Option<Self> { | ||
match algorithm { | ||
CargoConfigAlgorithm::Auto | CargoConfigAlgorithm::L => { | ||
Self::calc_l_conf(d_pf, capacity, l_training, h_training) | ||
} | ||
CargoConfigAlgorithm::H => Self::calc_h_conf(d_pf, capacity, l_training, h_training), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod cargo; | ||
pub mod pax; |
Oops, something went wrong.