moved structs to types.rs
This commit is contained in:
@@ -4,18 +4,18 @@ use chrono::{Local, NaiveDate};
|
||||
use rand::rngs::StdRng;
|
||||
use rand::prelude::{Rng, SeedableRng, IndexedRandom};
|
||||
|
||||
pub fn event_key(e: &CompanyEvent) -> String {
|
||||
pub fn event_key(e: &CompanyEventData) -> String {
|
||||
format!("{}|{}|{}", e.ticker, e.date, e.time)
|
||||
}
|
||||
|
||||
pub fn detect_changes(old: &CompanyEvent, new: &CompanyEvent, today: &str) -> Vec<CompanyEventChange> {
|
||||
pub fn detect_changes(old: &CompanyEventData, new: &CompanyEventData, today: &str) -> Vec<CompanyEventChangeData> {
|
||||
let mut changes = Vec::new();
|
||||
let ts = Local::now().format("%Y-%m-%d %H:%M:%S").to_string();
|
||||
|
||||
if new.date.as_str() <= today { return changes; }
|
||||
|
||||
if old.time != new.time {
|
||||
changes.push(CompanyEventChange {
|
||||
changes.push(CompanyEventChangeData {
|
||||
ticker: new.ticker.clone(),
|
||||
date: new.date.clone(),
|
||||
field_changed: "time".to_string(),
|
||||
@@ -26,7 +26,7 @@ pub fn detect_changes(old: &CompanyEvent, new: &CompanyEvent, today: &str) -> Ve
|
||||
}
|
||||
|
||||
if old.eps_forecast != new.eps_forecast {
|
||||
changes.push(CompanyEventChange {
|
||||
changes.push(CompanyEventChangeData {
|
||||
ticker: new.ticker.clone(),
|
||||
date: new.date.clone(),
|
||||
field_changed: "eps_forecast".to_string(),
|
||||
@@ -37,7 +37,7 @@ pub fn detect_changes(old: &CompanyEvent, new: &CompanyEvent, today: &str) -> Ve
|
||||
}
|
||||
|
||||
if old.eps_actual != new.eps_actual {
|
||||
changes.push(CompanyEventChange {
|
||||
changes.push(CompanyEventChangeData {
|
||||
ticker: new.ticker.clone(),
|
||||
date: new.date.clone(),
|
||||
field_changed: "eps_actual".to_string(),
|
||||
@@ -52,14 +52,6 @@ pub fn detect_changes(old: &CompanyEvent, new: &CompanyEvent, today: &str) -> Ve
|
||||
changes
|
||||
}
|
||||
|
||||
pub fn price_key(p: &CompanyPrice) -> String {
|
||||
if p.time.is_empty() {
|
||||
format!("{}|{}", p.ticker, p.date)
|
||||
} else {
|
||||
format!("{}|{}|{}", p.ticker, p.date, p.time)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse_float(s: &str) -> Option<f64> {
|
||||
s.replace("--", "").replace(",", "").parse::<f64>().ok()
|
||||
}
|
||||
@@ -83,7 +75,7 @@ pub fn choose_random<T: Clone>(items: &[T]) -> T {
|
||||
}
|
||||
|
||||
/// Extract first valid Yahoo ticker from company
|
||||
pub fn extract_first_yahoo_ticker(company: &CompanyCrossPlatformInfo) -> Option<String> {
|
||||
pub fn extract_first_yahoo_ticker(company: &CompanyCrossPlatformData) -> Option<String> {
|
||||
for tickers in company.isin_tickers_map.values() {
|
||||
for ticker in tickers {
|
||||
if ticker.starts_with("YAHOO:")
|
||||
@@ -113,7 +105,7 @@ pub fn sanitize_company_name(name: &str) -> String {
|
||||
/// Load companies from JSONL file
|
||||
pub async fn load_companies_from_jsonl(
|
||||
path: &std::path::Path
|
||||
) -> anyhow::Result<Vec<CompanyCrossPlatformInfo>> {
|
||||
) -> anyhow::Result<Vec<CompanyCrossPlatformData>> {
|
||||
let content = tokio::fs::read_to_string(path).await?;
|
||||
let mut companies = Vec::new();
|
||||
|
||||
@@ -121,7 +113,7 @@ pub async fn load_companies_from_jsonl(
|
||||
if line.trim().is_empty() {
|
||||
continue;
|
||||
}
|
||||
if let Ok(company) = serde_json::from_str::<CompanyCrossPlatformInfo>(line) {
|
||||
if let Ok(company) = serde_json::from_str::<CompanyCrossPlatformData>(line) {
|
||||
companies.push(company);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user