use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Sentiment {
pub market_id: String,
pub long_position_percentage: f64,
pub short_position_percentage: f64,
}
#[cfg(feature = "polars")]
impl crate::dataframe::IntoDataFrame for Vec<Sentiment> {
fn to_dataframe(&self) -> crate::Result<polars::prelude::DataFrame> {
use polars::prelude::*;
let market_id: Vec<&str> = self.iter().map(|s| s.market_id.as_str()).collect();
let long_position_percentage: Vec<f64> =
self.iter().map(|s| s.long_position_percentage).collect();
let short_position_percentage: Vec<f64> =
self.iter().map(|s| s.short_position_percentage).collect();
DataFrame::new(vec![
Column::new("market_id".into(), market_id),
Column::new("long_position_percentage".into(), long_position_percentage),
Column::new(
"short_position_percentage".into(),
short_position_percentage,
),
])
.map_err(|e| crate::Error::Config(format!("polars conversion failed: {e}")))
}
}