共享固定数值因子字段名
This commit is contained in:
@@ -161,6 +161,8 @@ impl DailyMarketSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
pub type NumericFactorMap = BTreeMap<Cow<'static, str>, f64>;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DailyFactorSnapshot {
|
||||
#[serde(with = "date_format")]
|
||||
@@ -172,7 +174,7 @@ pub struct DailyFactorSnapshot {
|
||||
pub turnover_ratio: Option<f64>,
|
||||
pub effective_turnover_ratio: Option<f64>,
|
||||
#[serde(default)]
|
||||
pub extra_factors: BTreeMap<String, f64>,
|
||||
pub extra_factors: NumericFactorMap,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -3264,11 +3266,15 @@ fn normalize_factor_snapshots(factors: Vec<DailyFactorSnapshot>) -> Vec<DailyFac
|
||||
.extra_factors
|
||||
.into_iter()
|
||||
.filter_map(|(field, value)| {
|
||||
let normalized = normalize_field(&field);
|
||||
if normalized.is_empty() || !value.is_finite() {
|
||||
let trimmed = field.as_ref().trim().trim_matches('"').trim_matches('\'');
|
||||
if trimmed.is_empty() || !value.is_finite() {
|
||||
None
|
||||
} else if trimmed == field.as_ref()
|
||||
&& trimmed.bytes().all(|byte| !byte.is_ascii_uppercase())
|
||||
{
|
||||
Some((field, value))
|
||||
} else {
|
||||
Some((normalized, value))
|
||||
Some((Cow::Owned(trimmed.to_ascii_lowercase()), value))
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
@@ -3962,10 +3968,9 @@ mod tests {
|
||||
.map(|(index, date)| {
|
||||
let mut extra_factors = BTreeMap::new();
|
||||
if let Some(values) = availability {
|
||||
extra_factors
|
||||
.insert("source_daily_volume_available".to_string(), values[index]);
|
||||
extra_factors.insert("source_daily_volume_available".into(), values[index]);
|
||||
if values[index] >= 0.5 {
|
||||
extra_factors.insert("daily_volume".to_string(), volumes[index] as f64);
|
||||
extra_factors.insert("daily_volume".into(), volumes[index] as f64);
|
||||
}
|
||||
}
|
||||
DailyFactorSnapshot {
|
||||
@@ -4140,10 +4145,7 @@ mod tests {
|
||||
pe_ttm: 10.0,
|
||||
turnover_ratio: None,
|
||||
effective_turnover_ratio: None,
|
||||
extra_factors: BTreeMap::from([(
|
||||
"adjustment_factor_backward1".to_string(),
|
||||
factor,
|
||||
)]),
|
||||
extra_factors: BTreeMap::from([("adjustment_factor_backward1".into(), factor)]),
|
||||
})
|
||||
.collect(),
|
||||
Vec::new(),
|
||||
@@ -4243,7 +4245,7 @@ mod tests {
|
||||
extra_factors: if *date == dates[3] {
|
||||
BTreeMap::new()
|
||||
} else {
|
||||
BTreeMap::from([("adjustment_factor_backward1".to_string(), 1.0)])
|
||||
BTreeMap::from([("adjustment_factor_backward1".into(), 1.0)])
|
||||
},
|
||||
})
|
||||
.collect(),
|
||||
|
||||
Reference in New Issue
Block a user