mirror of
https://github.com/Magnus167/msyrs.git
synced 2025-08-20 13:00:01 +00:00
refactor: reorganize DQCatalogueResponse and related structs for clarity
This commit is contained in:
parent
b04a67c1d2
commit
ad92f10633
@ -93,57 +93,6 @@ pub struct DQTimeSeriesResponse {
|
|||||||
instruments: Vec<Instrument>,
|
instruments: Vec<Instrument>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Response from the DataQuery API for a catalogue request.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct DQCatalogueResponse {
|
|
||||||
pub items: u32,
|
|
||||||
pub catalogue_responses: Vec<DQCatalogueSingleResponse>,
|
|
||||||
pub all_instruments: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Methods for DQCatalogueResponse
|
|
||||||
impl DQCatalogueResponse {
|
|
||||||
/// Create a new DQCatalogueResponse from a list of DQCatalogueSingleResponse objects.
|
|
||||||
pub fn new(catalogue_responses: Vec<DQCatalogueSingleResponse>) -> Self {
|
|
||||||
let all_instruments: Vec<String> = catalogue_responses
|
|
||||||
.iter()
|
|
||||||
.flat_map(|response| {
|
|
||||||
response
|
|
||||||
.instruments
|
|
||||||
.iter()
|
|
||||||
.map(|instrument| instrument.instrument_name.clone())
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
DQCatalogueResponse {
|
|
||||||
items: all_instruments.len() as u32,
|
|
||||||
catalogue_responses: catalogue_responses,
|
|
||||||
all_instruments: all_instruments,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Response from the DataQuery API for a single catalogue request (one page).
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct DQCatalogueSingleResponse {
|
|
||||||
pub links: Vec<HashMap<String, Option<String>>>,
|
|
||||||
pub items: u32,
|
|
||||||
pub instruments: Vec<DQCatalogueInstrument>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Representation of DQCatalogueSingleResponse.Instrument
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct DQCatalogueInstrument {
|
|
||||||
#[serde(rename = "instrument-id")]
|
|
||||||
pub instrument_id: String,
|
|
||||||
#[serde(rename = "instrument-name")]
|
|
||||||
pub instrument_name: String,
|
|
||||||
pub item: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Representation of DQResponse.Instrument
|
/// Representation of DQResponse.Instrument
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct Instrument {
|
struct Instrument {
|
||||||
@ -196,6 +145,56 @@ pub struct DQTimeSeries {
|
|||||||
expression: String,
|
expression: String,
|
||||||
time_series: Vec<(String, Option<f64>)>,
|
time_series: Vec<(String, Option<f64>)>,
|
||||||
}
|
}
|
||||||
|
/// Response from the DataQuery API for a catalogue request.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct DQCatalogueResponse {
|
||||||
|
pub items: u32,
|
||||||
|
pub catalogue_responses: Vec<DQCatalogueSingleResponse>,
|
||||||
|
pub all_instruments: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Methods for DQCatalogueResponse
|
||||||
|
impl DQCatalogueResponse {
|
||||||
|
/// Create a new DQCatalogueResponse from a list of DQCatalogueSingleResponse objects.
|
||||||
|
pub fn new(catalogue_responses: Vec<DQCatalogueSingleResponse>) -> Self {
|
||||||
|
let all_instruments: Vec<String> = catalogue_responses
|
||||||
|
.iter()
|
||||||
|
.flat_map(|response| {
|
||||||
|
response
|
||||||
|
.instruments
|
||||||
|
.iter()
|
||||||
|
.map(|instrument| instrument.instrument_name.clone())
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
DQCatalogueResponse {
|
||||||
|
items: all_instruments.len() as u32,
|
||||||
|
catalogue_responses: catalogue_responses,
|
||||||
|
all_instruments: all_instruments,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Response from the DataQuery API for a single catalogue request (one page).
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct DQCatalogueSingleResponse {
|
||||||
|
pub links: Vec<HashMap<String, Option<String>>>,
|
||||||
|
pub items: u32,
|
||||||
|
pub instruments: Vec<DQCatalogueInstrument>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Representation of DQCatalogueSingleResponse.Instrument
|
||||||
|
#[allow(dead_code)]
|
||||||
|
#[derive(Deserialize, Debug)]
|
||||||
|
pub struct DQCatalogueInstrument {
|
||||||
|
#[serde(rename = "instrument-id")]
|
||||||
|
pub instrument_id: String,
|
||||||
|
#[serde(rename = "instrument-name")]
|
||||||
|
pub instrument_name: String,
|
||||||
|
pub item: u32,
|
||||||
|
}
|
||||||
|
|
||||||
/// Representation of a JPMaQS indicator (1 or more time series for a single JPMaQS ticker)
|
/// Representation of a JPMaQS indicator (1 or more time series for a single JPMaQS ticker)
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user