scuriolus 0.3.0

Scuriolus is a modular trading bot platform.
Documentation
use derive_getters::Getters;
use gtrend_rs::enums::{Category, Country, Period, Property};
use serde::{Deserialize, Serialize};

use crate::provider::{Data, DataBasics, data::DataSpecifier};

/// [`WordTrend`] specifier
#[derive(Debug, PartialEq, Eq, Hash, Clone, Getters)]
pub struct WordTrendSpecifier {
    word: String,
    geo: Country,
    category: Category,
    property: Property,
    reference_period: Period,
}

impl WordTrendSpecifier {
    pub fn new(
        word: String,
        geo: Country,
        category: Category,
        property: Property,
        reference_period: Period,
    ) -> Self {
        Self {
            word,
            geo,
            category,
            property,
            reference_period,
        }
    }

    pub fn with_period(self, period: Period) -> Self {
        Self {
            reference_period: period,
            ..self
        }
    }
}

impl DataSpecifier for WordTrendSpecifier {
    fn name(&self) -> String {
        format!(
            "word_trend-{}-{}-{:?}-{:?}-{:?}",
            self.word, self.geo, self.category, self.property, self.reference_period
        )
    }
}

/// [`WordTrend`] data
///
/// *values* are percents relative to the reference period
/// *note* might specify additional information such as a change in google's calculation methods
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Getters)]
pub struct WordTrend {
    // Percent of use relative to the reference period. //TODO update to perthousand or greater ?
    pub value: u32,
    pub basics: DataBasics,
    pub note: Option<String>,
}

impl Data for WordTrend {
    type Specifier = WordTrendSpecifier;

    fn basics(&self) -> &super::DataBasics {
        &self.basics
    }

    fn mut_basics(&mut self) -> &mut super::DataBasics {
        &mut self.basics
    }
}