fix(m1): resolve director follow-ups on earnings curation, quant scan benchmark, and equity gate
This commit is contained in:
parent
d9191304fb
commit
d52aa20bff
14 changed files with 1408 additions and 350 deletions
|
|
@ -28,6 +28,7 @@ use std::io;
|
|||
use bson::raw::RawDocumentBuf;
|
||||
use bson::{Bson, DateTime, Document};
|
||||
|
||||
use crate::bson_eod_prices::{parse_ymd_strict_days, MILLIS_PER_DAY};
|
||||
use crate::bson_stream::{DEFAULT_MAX_DOC_BYTES, MIN_BSON_DOC_BYTES};
|
||||
use crate::events::parse_filing_timefiled;
|
||||
use crate::mongo_safety::{
|
||||
|
|
@ -115,6 +116,17 @@ impl SourceCollection {
|
|||
Self::QmEarnings => Some("reportDate"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` when the collection's [`Self::date_field`] is stored as a
|
||||
/// BSON `DateTime` rather than a `YYYY-MM-DD` / ISO UTF-8 string.
|
||||
///
|
||||
/// Verified empirically against live QA MongoDB (`m1-source-field-shapes.md`):
|
||||
/// `qmEarnings.reportDate` (100% BSON `DateTime`) and `ceoShorts.timestamp`
|
||||
/// (BSON `DateTime`), while `eodPrices.date`, `qmPrices.date`, `qmSplits.date`,
|
||||
/// `qmDividends.date`, and `qmFilings.timefiled` are UTF-8 strings.
|
||||
pub const fn date_field_is_bson_datetime(self) -> bool {
|
||||
matches!(self, Self::QmEarnings | Self::CeoShorts)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for SourceCollection {
|
||||
|
|
@ -1164,8 +1176,8 @@ impl Default for MongoCliOptions {
|
|||
}
|
||||
|
||||
impl MongoCliOptions {
|
||||
/// Builds a [`MongoReadSpec`] for `collection`, attaching `key_eq` and
|
||||
/// optional ISO string date bounds when `apply_date_range` is `true`.
|
||||
/// Builds a [`MongoReadSpec`] for string-dated collections, attaching `key_eq`
|
||||
/// and optional ISO string date bounds when `apply_date_range` is `true`.
|
||||
pub fn to_read_spec(&self, key_eq: Option<String>, apply_date_range: bool) -> MongoReadSpec {
|
||||
let date_range = if apply_date_range && (self.date_gte.is_some() || self.date_lt.is_some())
|
||||
{
|
||||
|
|
@ -1184,6 +1196,40 @@ impl MongoCliOptions {
|
|||
max_doc_bytes: DEFAULT_MAX_DOC_BYTES,
|
||||
}
|
||||
}
|
||||
|
||||
/// Builds a [`MongoReadSpec`] using the collection's native BSON date representation:
|
||||
/// `BsonDateTimeMillis` (UTC midnight) for BSON `DateTime` collections (`qmEarnings`,
|
||||
/// `ceoShorts`) and `IsoString` for string-dated collections (`eodPrices`, `qmPrices`,
|
||||
/// `qmSplits`, `qmDividends`, `qmFilings`).
|
||||
pub fn to_read_spec_for_collection(
|
||||
&self,
|
||||
collection: SourceCollection,
|
||||
key_eq: Option<String>,
|
||||
apply_date_range: bool,
|
||||
) -> MongoReadSpec {
|
||||
if !apply_date_range || (self.date_gte.is_none() && self.date_lt.is_none()) {
|
||||
return self.to_read_spec(key_eq, false);
|
||||
}
|
||||
if !collection.date_field_is_bson_datetime() {
|
||||
return self.to_read_spec(key_eq, true);
|
||||
}
|
||||
let to_dt = |raw: &String| -> FilterDateValue {
|
||||
match parse_ymd_strict_days(raw) {
|
||||
Some(days) => FilterDateValue::BsonDateTimeMillis(i64::from(days) * MILLIS_PER_DAY),
|
||||
None => FilterDateValue::IsoString(raw.clone()),
|
||||
}
|
||||
};
|
||||
MongoReadSpec {
|
||||
key_eq,
|
||||
date_range: Some(MongoDateRange {
|
||||
gte: self.date_gte.as_ref().map(to_dt),
|
||||
lt: self.date_lt.as_ref().map(to_dt),
|
||||
}),
|
||||
batch_size: self.batch_size,
|
||||
limit: self.limit,
|
||||
max_doc_bytes: DEFAULT_MAX_DOC_BYTES,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -1905,3 +1905,37 @@ fn error_redaction_scrubs_repeated_password_occurrences_across_message() {
|
|||
"expected every occurrence to be redacted in Debug: {debug_out}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_to_read_spec_for_collection_uses_bson_datetime_for_qm_earnings_and_iso_string_for_filings() {
|
||||
let opts = super::MongoCliOptions {
|
||||
date_gte: Some("2017-01-01".to_owned()),
|
||||
date_lt: Some("2025-02-13".to_owned()),
|
||||
..super::MongoCliOptions::default()
|
||||
};
|
||||
|
||||
let filings_spec = opts.to_read_spec_for_collection(SourceCollection::QmFilings, None, true);
|
||||
let filings_doc = build_filter_document(SourceCollection::QmFilings, &filings_spec)
|
||||
.expect("qmFilings string filter must succeed");
|
||||
let tf = filings_doc
|
||||
.get_document("timefiled")
|
||||
.expect("timefiled subdocument");
|
||||
assert_eq!(tf.get("$gte"), Some(&Bson::String("2017-01-01".to_owned())));
|
||||
assert_eq!(tf.get("$lt"), Some(&Bson::String("2025-02-13".to_owned())));
|
||||
|
||||
let earnings_spec = opts.to_read_spec_for_collection(SourceCollection::QmEarnings, None, true);
|
||||
let earnings_doc = build_filter_document(SourceCollection::QmEarnings, &earnings_spec)
|
||||
.expect("qmEarnings DateTime filter must succeed");
|
||||
let rd = earnings_doc
|
||||
.get_document("reportDate")
|
||||
.expect("reportDate subdocument");
|
||||
// 2017-01-01T00:00:00Z = 1483228800000 ms; 2025-02-13T00:00:00Z = 1739404800000 ms
|
||||
assert_eq!(
|
||||
rd.get("$gte"),
|
||||
Some(&Bson::DateTime(DateTime::from_millis(1_483_228_800_000)))
|
||||
);
|
||||
assert_eq!(
|
||||
rd.get("$lt"),
|
||||
Some(&Bson::DateTime(DateTime::from_millis(1_739_404_800_000)))
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -440,8 +440,12 @@ pub fn run_curate_shorts_mongo(
|
|||
pub fn run_curate_events_mongo(
|
||||
args: &CurateEventsMongoArgs,
|
||||
) -> Result<CurateEventsRunReport, RunMongoCurateError> {
|
||||
let filings_spec = args.mongo.to_read_spec(None, true);
|
||||
let earnings_spec = args.mongo.to_read_spec(None, true);
|
||||
let filings_spec = args
|
||||
.mongo
|
||||
.to_read_spec_for_collection(SourceCollection::QmFilings, None, true);
|
||||
let earnings_spec = args
|
||||
.mongo
|
||||
.to_read_spec_for_collection(SourceCollection::QmEarnings, None, true);
|
||||
let client = connect_and_validate_specs(
|
||||
&args.mongo,
|
||||
&[
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue