#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DimensionWeights {
pub weights: [f64; 8],
}
impl DimensionWeights {
pub fn equal() -> Self {
Self {
weights: [0.125; 8],
}
}
pub fn governance() -> Self {
Self {
weights: [
0.15, 0.10, 0.10, 0.12, 0.18, 0.13, 0.12, 0.10, ],
}
}
pub fn energy_cooperative() -> Self {
Self {
weights: [
0.10, 0.22, 0.18, 0.10, 0.10, 0.12, 0.10, 0.08, ],
}
}
pub fn knowledge_commons() -> Self {
Self {
weights: [
0.22, 0.06, 0.08, 0.08, 0.12, 0.10, 0.14, 0.20, ],
}
}
pub fn care_community() -> Self {
Self {
weights: [
0.08, 0.08, 0.08, 0.10, 0.14, 0.22, 0.20, 0.10, ],
}
}
pub fn is_normalized(&self) -> bool {
let sum: f64 = self.weights.iter().sum();
(sum - 1.0).abs() < 0.01
}
pub fn normalize(&mut self) {
let sum: f64 = self.weights.iter().sum();
if sum > 0.0 {
for w in &mut self.weights {
*w /= sum;
}
}
}
}
impl Default for DimensionWeights {
fn default() -> Self {
Self::governance()
}
}