T-116: M1.2af — data-pipeline: read-only security-master → curate-etl input exporter (provider_mapping.tsv, listing_currencies.tsv, Pass 6 delistings.tsv from PostgreSQL) with tests and local benchmark
This commit is contained in:
parent
88b7f1f020
commit
7c55c97c44
8 changed files with 576 additions and 26 deletions
|
|
@ -3,7 +3,9 @@
|
|||
//! Kept inside the library crate so CLI argument parsing tests run under
|
||||
//! `cargo test --workspace --lib --offline`.
|
||||
|
||||
use std::path::PathBuf;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::bench::{
|
||||
DEFAULT_ADJ_BENCH_EVENTS, DEFAULT_BARS_BENCH_ROWS, DEFAULT_BENCH_ROWS,
|
||||
|
|
@ -83,11 +85,11 @@ pub fn format_usage(name: &str, version: &str) -> String {
|
|||
Usage:\n\
|
||||
{name} [--help | -h]\n\
|
||||
{name} [--version | -V]\n\
|
||||
{name} curate-bars-1d --eod-prices <path> --qm-splits <path> --provider-mapping <path> --listing-currencies <path> --out <dir> [--rel-tolerance <f64>]\n\
|
||||
{name} curate-bars-1d --eod-prices <path> --qm-splits <path> (--curate-inputs <dir> | --provider-mapping <path> --listing-currencies <path>) --out <dir> [--rel-tolerance <f64>]\n\
|
||||
Curate daily bars from BSON + TSV files into bars_1d/year=YYYY/part.parquet (default --rel-tolerance: {DEFAULT_CURATE_BARS_REL_TOLERANCE})\n\
|
||||
{name} curate-adj-factors --qm-splits <path> --qm-dividends <path> --provider-mapping <path> --bars-1d <dir> --out <dir>\n\
|
||||
Curate retrospective adj_factors from BSON + TSV + bars_1d Parquet into adj_factors/part.parquet\n\
|
||||
{name} curate-corporate-actions --qm-splits <path> --qm-dividends <path> --provider-mapping <path> [--delistings <path>] --out <dir>\n\
|
||||
{name} curate-corporate-actions --qm-splits <path> --qm-dividends <path> (--curate-inputs <dir> | --provider-mapping <path> [--delistings <path>]) --out <dir>\n\
|
||||
Curate corporate_actions from BSON + TSV files into corporate_actions/part.parquet\n\
|
||||
{name} curate-fx-1d --eod-prices <path> --te-market-data <path> [--te-symbol <sym>] --out <dir>\n\
|
||||
Curate USD/CAD fx_1d from eodPrices + teMarketData BSON files into fx_1d/part.parquet (default --te-symbol: {DEFAULT_TE_SYMBOL})\n\
|
||||
|
|
@ -133,9 +135,9 @@ pub fn format_usage_stderr(name: &str) -> String {
|
|||
"Usage:\n\
|
||||
{name} [--help | -h]\n\
|
||||
{name} [--version | -V]\n\
|
||||
{name} curate-bars-1d --eod-prices <path> --qm-splits <path> --provider-mapping <path> --listing-currencies <path> --out <dir> [--rel-tolerance <f64>]\n\
|
||||
{name} curate-bars-1d --eod-prices <path> --qm-splits <path> (--curate-inputs <dir> | --provider-mapping <path> --listing-currencies <path>) --out <dir> [--rel-tolerance <f64>]\n\
|
||||
{name} curate-adj-factors --qm-splits <path> --qm-dividends <path> --provider-mapping <path> --bars-1d <dir> --out <dir>\n\
|
||||
{name} curate-corporate-actions --qm-splits <path> --qm-dividends <path> --provider-mapping <path> [--delistings <path>] --out <dir>\n\
|
||||
{name} curate-corporate-actions --qm-splits <path> --qm-dividends <path> (--curate-inputs <dir> | --provider-mapping <path> [--delistings <path>]) --out <dir>\n\
|
||||
{name} curate-fx-1d --eod-prices <path> --te-market-data <path> [--te-symbol <sym>] --out <dir>\n\
|
||||
{name} curate-shorts --ceo-shorts <path> --provider-mapping <path> --out <dir> --shares-short-field <name> [--key-field <name>] [--report-date-field <name>] [--net-change-field <name>] [--pct-float-field <name>] [--mapping-source <name>]\n\
|
||||
{name} curate-events --qm-filings <path> --qm-earnings <path> --provider-mapping <path> --out <dir> --filings-form-type-field <name> [--filings-key-field <name>] [--filings-timefiled-field <name>] [--filings-filing-id-field <name>] [--filings-url-field <name>] [--earnings-key-field <name>] [--earnings-report-date-field <name>] [--earnings-announce-time-field <name>] [--earnings-fiscal-period-end-field <name>] [--earnings-actual-eps-field <name>] [--earnings-revenue-field <name>] [--mapping-source <name>]\n\
|
||||
|
|
@ -171,9 +173,43 @@ pub fn format_usage_stderr(name: &str) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
/// Pins a `curate-inputs` directory to one immutable generation directory before opening any TSV.
|
||||
///
|
||||
/// If `<dir>/current` exists (the atomic symlink published by `run-export-curate-inputs.ts`),
|
||||
/// resolves `<dir>/current` once via [`fs::canonicalize`] so every TSV in this invocation comes
|
||||
/// from that exact generation even if a concurrent export refreshes `current`. Otherwise resolves
|
||||
/// `<dir>` itself (supporting direct generation directories or flat fixture directories).
|
||||
pub fn pin_curate_inputs_dir(dir: &Path) -> Result<PathBuf, String> {
|
||||
let current = dir.join("current");
|
||||
let target = match fs::symlink_metadata(¤t) {
|
||||
Ok(_) => current,
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => dir.to_path_buf(),
|
||||
Err(err) => {
|
||||
return Err(format!(
|
||||
"failed to inspect --curate-inputs '{}': {err}",
|
||||
current.display()
|
||||
));
|
||||
}
|
||||
};
|
||||
let canonical = fs::canonicalize(&target).map_err(|err| {
|
||||
format!(
|
||||
"failed to resolve --curate-inputs '{}': {err}",
|
||||
target.display()
|
||||
)
|
||||
})?;
|
||||
if !canonical.is_dir() {
|
||||
return Err(format!(
|
||||
"--curate-inputs '{}' does not resolve to a directory",
|
||||
dir.display()
|
||||
));
|
||||
}
|
||||
Ok(canonical)
|
||||
}
|
||||
|
||||
fn parse_curate_bars_1d_args(args: &[&str]) -> Result<CurateBars1dArgs, String> {
|
||||
let mut eod_prices: Option<PathBuf> = None;
|
||||
let mut qm_splits: Option<PathBuf> = None;
|
||||
let mut curate_inputs: Option<PathBuf> = None;
|
||||
let mut provider_mapping: Option<PathBuf> = None;
|
||||
let mut listing_currencies: Option<PathBuf> = None;
|
||||
let mut out_dir: Option<PathBuf> = None;
|
||||
|
|
@ -216,6 +252,7 @@ fn parse_curate_bars_1d_args(args: &[&str]) -> Result<CurateBars1dArgs, String>
|
|||
match flag {
|
||||
"--eod-prices" => set_path(&mut eod_prices, "--eod-prices", value)?,
|
||||
"--qm-splits" => set_path(&mut qm_splits, "--qm-splits", value)?,
|
||||
"--curate-inputs" => set_path(&mut curate_inputs, "--curate-inputs", value)?,
|
||||
"--provider-mapping" => set_path(&mut provider_mapping, "--provider-mapping", value)?,
|
||||
"--listing-currencies" => {
|
||||
set_path(&mut listing_currencies, "--listing-currencies", value)?;
|
||||
|
|
@ -245,10 +282,27 @@ fn parse_curate_bars_1d_args(args: &[&str]) -> Result<CurateBars1dArgs, String>
|
|||
let eod_prices =
|
||||
eod_prices.ok_or_else(|| "missing required flag '--eod-prices'".to_string())?;
|
||||
let qm_splits = qm_splits.ok_or_else(|| "missing required flag '--qm-splits'".to_string())?;
|
||||
let provider_mapping =
|
||||
provider_mapping.ok_or_else(|| "missing required flag '--provider-mapping'".to_string())?;
|
||||
let listing_currencies = listing_currencies
|
||||
.ok_or_else(|| "missing required flag '--listing-currencies'".to_string())?;
|
||||
let (provider_mapping, listing_currencies) = if let Some(inputs_dir) = curate_inputs {
|
||||
if provider_mapping.is_some() {
|
||||
return Err("cannot combine '--curate-inputs' with '--provider-mapping'".to_string());
|
||||
}
|
||||
if listing_currencies.is_some() {
|
||||
return Err(
|
||||
"cannot combine '--curate-inputs' with '--listing-currencies'".to_string(),
|
||||
);
|
||||
}
|
||||
let pinned = pin_curate_inputs_dir(&inputs_dir)?;
|
||||
(
|
||||
pinned.join("provider_mapping.tsv"),
|
||||
pinned.join("listing_currencies.tsv"),
|
||||
)
|
||||
} else {
|
||||
let provider_mapping = provider_mapping
|
||||
.ok_or_else(|| "missing required flag '--provider-mapping'".to_string())?;
|
||||
let listing_currencies = listing_currencies
|
||||
.ok_or_else(|| "missing required flag '--listing-currencies'".to_string())?;
|
||||
(provider_mapping, listing_currencies)
|
||||
};
|
||||
let out_dir = out_dir.ok_or_else(|| "missing required flag '--out'".to_string())?;
|
||||
|
||||
Ok(CurateBars1dArgs {
|
||||
|
|
@ -334,6 +388,7 @@ fn parse_curate_corporate_actions_args(
|
|||
) -> Result<CurateCorporateActionsArgs, String> {
|
||||
let mut qm_splits: Option<PathBuf> = None;
|
||||
let mut qm_dividends: Option<PathBuf> = None;
|
||||
let mut curate_inputs: Option<PathBuf> = None;
|
||||
let mut provider_mapping: Option<PathBuf> = None;
|
||||
let mut delistings: Option<PathBuf> = None;
|
||||
let mut out_dir: Option<PathBuf> = None;
|
||||
|
|
@ -375,6 +430,7 @@ fn parse_curate_corporate_actions_args(
|
|||
match flag {
|
||||
"--qm-splits" => set_path(&mut qm_splits, "--qm-splits", value)?,
|
||||
"--qm-dividends" => set_path(&mut qm_dividends, "--qm-dividends", value)?,
|
||||
"--curate-inputs" => set_path(&mut curate_inputs, "--curate-inputs", value)?,
|
||||
"--provider-mapping" => set_path(&mut provider_mapping, "--provider-mapping", value)?,
|
||||
"--delistings" => set_path(&mut delistings, "--delistings", value)?,
|
||||
"--out" => set_path(&mut out_dir, "--out", value)?,
|
||||
|
|
@ -389,8 +445,23 @@ fn parse_curate_corporate_actions_args(
|
|||
let qm_splits = qm_splits.ok_or_else(|| "missing required flag '--qm-splits'".to_string())?;
|
||||
let qm_dividends =
|
||||
qm_dividends.ok_or_else(|| "missing required flag '--qm-dividends'".to_string())?;
|
||||
let provider_mapping =
|
||||
provider_mapping.ok_or_else(|| "missing required flag '--provider-mapping'".to_string())?;
|
||||
let (provider_mapping, delistings) = if let Some(inputs_dir) = curate_inputs {
|
||||
if provider_mapping.is_some() {
|
||||
return Err("cannot combine '--curate-inputs' with '--provider-mapping'".to_string());
|
||||
}
|
||||
if delistings.is_some() {
|
||||
return Err("cannot combine '--curate-inputs' with '--delistings'".to_string());
|
||||
}
|
||||
let pinned = pin_curate_inputs_dir(&inputs_dir)?;
|
||||
(
|
||||
pinned.join("provider_mapping.tsv"),
|
||||
Some(pinned.join("delistings.tsv")),
|
||||
)
|
||||
} else {
|
||||
let provider_mapping = provider_mapping
|
||||
.ok_or_else(|| "missing required flag '--provider-mapping'".to_string())?;
|
||||
(provider_mapping, delistings)
|
||||
};
|
||||
let out_dir = out_dir.ok_or_else(|| "missing required flag '--out'".to_string())?;
|
||||
|
||||
Ok(CurateCorporateActionsArgs {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue