use serde::{Deserialize, Serialize};
use super::types::MoodVector;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub enum CompoundEmotion {
Love, Optimism, Submission, Awe, Remorse, Contempt, Aggressiveness, }
impl std::fmt::Display for CompoundEmotion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Love => "love",
Self::Optimism => "optimism",
Self::Submission => "submission",
Self::Awe => "awe",
Self::Remorse => "remorse",
Self::Contempt => "contempt",
Self::Aggressiveness => "aggressiveness",
};
f.write_str(s)
}
}
#[cfg_attr(feature = "tracing", tracing::instrument(skip_all))]
#[must_use]
pub fn detect_compound_emotions(mood: &MoodVector, threshold: f32) -> Vec<(CompoundEmotion, f32)> {
let t = threshold;
let mut results = Vec::new();
if mood.joy > t && mood.trust > t {
results.push((CompoundEmotion::Love, (mood.joy + mood.trust) / 2.0));
}
if mood.joy > t && mood.interest > t {
results.push((CompoundEmotion::Optimism, (mood.joy + mood.interest) / 2.0));
}
if mood.trust > t && mood.dominance < -t {
results.push((
CompoundEmotion::Submission,
(mood.trust - mood.dominance) / 2.0,
));
}
if mood.dominance < -t && mood.arousal > t {
results.push((CompoundEmotion::Awe, (-mood.dominance + mood.arousal) / 2.0));
}
if mood.joy < -t && mood.frustration > t {
results.push((
CompoundEmotion::Remorse,
(-mood.joy + mood.frustration) / 2.0,
));
}
if mood.frustration > t && mood.trust < -t {
results.push((
CompoundEmotion::Contempt,
(mood.frustration - mood.trust) / 2.0,
));
}
if mood.frustration > t && mood.interest > t {
results.push((
CompoundEmotion::Aggressiveness,
(mood.frustration + mood.interest) / 2.0,
));
}
results
}