working with docs

This commit is contained in:
Palash Tyagi
2024-11-12 21:31:52 +00:00
parent 91aa5762d6
commit 6bb51905b8
8 changed files with 174 additions and 55 deletions

View File

@@ -1,10 +1,8 @@
use crate::download::oauth_client::OAuthClient;
use crate::download::requester::DQRequester;
use crate::download::timeseries::DQTimeSeries;
use crate::download::timeseries::DQTimeSeriesResponse;
use crate::download::timeseries::DQTimeseriesRequestArgs;
use crate::download::timeseries::JPMaQSIndicator;
use rayon::prelude::*;
use std::error::Error;
const DEFAULT_JPMAQS_METRICS: [&str; 4] = ["value", "grading", "eop_lag", "mop_lag"];
@@ -114,53 +112,21 @@ impl JPMaQSDownload {
let expressions = construct_expressions(download_args.tickers, download_args.metrics);
assert!(all_jpmaq_expressions(expressions.clone()));
let dqts_vec = self.get_expressions(expressions)?;
// println!("Retrieved {} time series", -- sum[dqts_vec.iter().map(|dqts| dqts.len())]);
println!("Retrieved all time series",);
// say pausing for 30 seconds
println!("Pausing for 10 seconds");
std::thread::sleep(std::time::Duration::from_secs(10));
println!("Resuming");
let start = std::time::Instant::now();
let dq_download_args = DQTimeseriesRequestArgs {
expressions: expressions,
start_date: download_args.start_date,
end_date: download_args.end_date,
..Default::default()
};
let indicators = dq_response_vec_to_jpmaqs_indicators(dqts_vec);
let result = self
.requester
.get_timeseries_as_jpmaqs_indicators(dq_download_args);
println!(
"Converted time series to indicators in {:?}",
start.elapsed()
);
println!("Pausing for 10 seconds");
std::thread::sleep(std::time::Duration::from_secs(10));
println!("Resuming");
Ok(indicators)
match result {
Ok(indicators) => Ok(indicators),
Err(e) => Err(e),
}
}
}
// fn dq_response_vec_to_jpmaqs_indicators(
// dqts_vec: Vec<DQTimeSeriesResponse>,
// ) -> Vec<JPMaQSIndicator> {
// let mut indicators: Vec<JPMaQSIndicator> = Vec::new();
// for dqts in dqts_vec {
// indicators.extend(
// dqts.consume_to_grouped_by_ticker() // moves the values to free up memory
// .into_iter()
// .filter_map(|tsv| JPMaQSIndicator::new(tsv).ok()),
// );
// }
// indicators
// }
fn dq_response_vec_to_jpmaqs_indicators(
dqts_vec: Vec<DQTimeSeriesResponse>,
) -> Vec<JPMaQSIndicator> {
dqts_vec
.into_par_iter()
.flat_map(|dqts| {
dqts.consume_to_grouped_by_ticker()
.into_iter()
.filter_map(|tsv| JPMaQSIndicator::new(tsv).ok())
.collect::<Vec<JPMaQSIndicator>>()
})
.collect()
}