diff --git a/src/pve_static.rs b/src/pve_static.rs index d131fe3..f8757f3 100644 --- a/src/pve_static.rs +++ b/src/pve_static.rs @@ -19,14 +19,12 @@ pub struct StaticNodeUsage { pub maxmem: usize, } -#[derive(Serialize, Deserialize)] -#[serde(rename_all = "kebab-case")] -/// Static usage information of an HA resource. -pub struct StaticServiceUsage { - /// Number of assigned CPUs or CPU limit. - pub maxcpu: f64, - /// Maximum assigned memory in bytes. - pub maxmem: usize, +impl StaticNodeUsage { + /// Add usage of `service` to the node's usage. + pub fn add_service_usage(&mut self, service: &StaticServiceUsage) { + self.cpu = add_cpu_usage(self.cpu, self.maxcpu as f64, service.maxcpu); + self.mem += service.maxmem; + } } /// Calculate new CPU usage in percent. @@ -39,12 +37,14 @@ fn add_cpu_usage(old: f64, max: f64, add: f64) -> f64 { } } -impl StaticNodeUsage { - /// Add usage of `service` to the node's usage. - pub fn add_service_usage(&mut self, service: &StaticServiceUsage) { - self.cpu = add_cpu_usage(self.cpu, self.maxcpu as f64, service.maxcpu); - self.mem += service.maxmem; - } +#[derive(Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +/// Static usage information of an HA resource. +pub struct StaticServiceUsage { + /// Number of assigned CPUs or CPU limit. + pub maxcpu: f64, + /// Maximum assigned memory in bytes. + pub maxmem: usize, } criteria_struct! { diff --git a/src/topsis.rs b/src/topsis.rs index 3a37353..d86a2b9 100644 --- a/src/topsis.rs +++ b/src/topsis.rs @@ -49,16 +49,6 @@ impl TopsisCriterion { /// A normalized array of `TopsisCriterion`. pub struct TopsisCriteria([TopsisCriterion; N_CRITERIA]); -/// A normalized matrix used for scoring with the TOPSIS algorithm. -pub struct TopsisMatrix(Vec<[f64; N_CRITERIA]>); - -/// Idealized alternatives from a `TopsisMatrix`. That is, the alternative consisting of the best -/// (respectively worst) value among the alternatives in the matrix for each single criterion. -struct TopsisIdealAlternatives { - best: [f64; N_CRITERIA], - worst: [f64; N_CRITERIA], -} - impl TopsisCriteria { /// Create a new instance of normalized TOPSIS criteria. /// @@ -95,6 +85,9 @@ impl TopsisCriteria { } } +/// A normalized matrix used for scoring with the TOPSIS algorithm. +pub struct TopsisMatrix(Vec<[f64; N_CRITERIA]>); + impl TopsisMatrix { /// Values of the matrix for the fixed critierion with index `index`. fn fixed_criterion(&self, index: usize) -> Vec { @@ -136,6 +129,13 @@ impl TopsisMatrix { } } +/// Idealized alternatives from a `TopsisMatrix`. That is, the alternative consisting of the best +/// (respectively worst) value among the alternatives in the matrix for each single criterion. +struct TopsisIdealAlternatives { + best: [f64; N_CRITERIA], + worst: [f64; N_CRITERIA], +} + /// Compute the idealized alternatives from the given `matrix`. The `criteria` are required to know /// if a critierion should be maximized or minimized. fn ideal_alternatives(