修复 分型时间戳
This commit is contained in:
+14
-14
@@ -336,7 +336,7 @@ impl 笔 {
|
||||
/// 核心笔分析 — 使用显式栈模拟递归
|
||||
///
|
||||
/// 返回: 递归层次数
|
||||
pub fn 分析(
|
||||
pub fn 分析_显式栈(
|
||||
初始分型: Arc<分型>,
|
||||
分型序列: &mut Vec<Arc<分型>>,
|
||||
笔序列: &mut Vec<Arc<虚线>>,
|
||||
@@ -415,7 +415,7 @@ impl 笔 {
|
||||
let 之前分型 = Arc::clone(分型序列.last().unwrap());
|
||||
|
||||
// Python line 2330-2335: 清理无效数据
|
||||
if 之前分型.时间戳 == 当前分型.时间戳
|
||||
if 之前分型.中.时间戳.load(Ordering::Relaxed) == 当前分型.中.时间戳.load(Ordering::Relaxed)
|
||||
|| matches!(之前分型.结构, 分型结构::上 | 分型结构::下)
|
||||
{
|
||||
Self::弹出旧笔(分型序列, 笔序列);
|
||||
@@ -430,7 +430,7 @@ impl 笔 {
|
||||
let 之前分型 = Arc::clone(分型序列.last().unwrap());
|
||||
|
||||
// Python line 2338: 时序检查 — skip out-of-order fractals
|
||||
if 之前分型.时间戳 > 当前分型.时间戳
|
||||
if 之前分型.中.时间戳.load(Ordering::Relaxed) > 当前分型.中.时间戳.load(Ordering::Relaxed)
|
||||
&& 之前分型.中.序号.load(Ordering::Relaxed)
|
||||
- 当前分型.中.序号.load(Ordering::Relaxed)
|
||||
> 1
|
||||
@@ -608,7 +608,7 @@ impl 笔 {
|
||||
/// 核心笔分析 — 递归实现,逐句对照 chan.py 笔.分析 / 笔递归分析
|
||||
///
|
||||
/// 返回: 递归层次数
|
||||
pub fn 分析递归(
|
||||
pub fn 分析(
|
||||
当前分型: Arc<分型>,
|
||||
分型序列: &mut Vec<Arc<分型>>,
|
||||
笔序列: &mut Vec<Arc<虚线>>,
|
||||
@@ -637,7 +637,7 @@ impl 笔 {
|
||||
|
||||
// Python line 2329-2335: 清理无效数据
|
||||
let 之前分型 = Arc::clone(分型序列.last().unwrap());
|
||||
if 之前分型.时间戳 == 当前分型.时间戳
|
||||
if 之前分型.中.时间戳.load(Ordering::Relaxed) == 当前分型.中.时间戳.load(Ordering::Relaxed)
|
||||
|| matches!(之前分型.结构, 分型结构::上 | 分型结构::下)
|
||||
{
|
||||
Self::弹出旧笔(分型序列, 笔序列);
|
||||
@@ -651,7 +651,7 @@ impl 笔 {
|
||||
|
||||
// Python line 2337-2341: 时序检查
|
||||
let 之前分型 = Arc::clone(分型序列.last().unwrap());
|
||||
if 之前分型.时间戳 > 当前分型.时间戳
|
||||
if 之前分型.中.时间戳.load(Ordering::Relaxed) > 当前分型.中.时间戳.load(Ordering::Relaxed)
|
||||
&& 之前分型.中.序号.load(Ordering::Relaxed) - 当前分型.中.序号.load(Ordering::Relaxed)
|
||||
> 1
|
||||
{
|
||||
@@ -674,7 +674,7 @@ impl 笔 {
|
||||
&& 当前分型.结构 == 分型结构::顶);
|
||||
if 破位 {
|
||||
Self::弹出旧笔(分型序列, 笔序列);
|
||||
return Self::分析递归(
|
||||
return Self::分析(
|
||||
当前分型,
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -712,7 +712,7 @@ impl 笔 {
|
||||
if let Some(临时分型) =
|
||||
分型::从缠K序列中获取分型(缠K序列, 文官_k)
|
||||
{
|
||||
let 递归层次 = Self::分析递归(
|
||||
let 递归层次 = Self::分析(
|
||||
Arc::new(临时分型),
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -721,7 +721,7 @@ impl 笔 {
|
||||
递归层次 + 1,
|
||||
配置,
|
||||
);
|
||||
return Self::分析递归(
|
||||
return Self::分析(
|
||||
当前分型,
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -770,7 +770,7 @@ impl 笔 {
|
||||
if let Some(ref 右) = 当前分型.右 {
|
||||
if let Some(临时分型) = 分型::从缠K序列中获取分型(缠K序列, 右)
|
||||
{
|
||||
return Self::分析递归(
|
||||
return Self::分析(
|
||||
Arc::new(临时分型),
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -812,7 +812,7 @@ impl 笔 {
|
||||
let 临时分型_rc = Arc::new(临时分型);
|
||||
|
||||
if !分型序列.is_empty() {
|
||||
let mut 递归层次 = Self::分析递归(
|
||||
let mut 递归层次 = Self::分析(
|
||||
Arc::clone(&临时分型_rc),
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -841,7 +841,7 @@ impl 笔 {
|
||||
)
|
||||
{
|
||||
let 错过分型_rc = Arc::new(错过分型);
|
||||
递归层次 = Self::分析递归(
|
||||
递归层次 = Self::分析(
|
||||
Arc::clone(&错过分型_rc),
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -856,7 +856,7 @@ impl 笔 {
|
||||
}
|
||||
}
|
||||
|
||||
return Self::分析递归(
|
||||
return Self::分析(
|
||||
当前分型,
|
||||
分型序列,
|
||||
笔序列,
|
||||
@@ -873,7 +873,7 @@ impl 笔 {
|
||||
} else if 分型序列.is_empty() {
|
||||
分型::向序列中添加(分型序列, 当前分型);
|
||||
} else {
|
||||
return Self::分析递归(
|
||||
return Self::分析(
|
||||
当前分型,
|
||||
分型序列,
|
||||
笔序列,
|
||||
|
||||
@@ -69,14 +69,14 @@ impl 背驰分析 {
|
||||
|
||||
/// 斜率背驰 — 价格斜率背驰
|
||||
pub fn 斜率背驰(进入段: &虚线, 离开段: &虚线) -> bool {
|
||||
let dx = (进入段.武.read().unwrap().时间戳 - 进入段.文.时间戳) as f64;
|
||||
let dx = (进入段.武.read().unwrap().时间戳() - 进入段.文.时间戳()) as f64;
|
||||
if dx == 0.0 {
|
||||
return false;
|
||||
}
|
||||
let dy = 进入段.武.read().unwrap().分型特征值 - 进入段.文.分型特征值;
|
||||
let 进入斜率 = dy / dx;
|
||||
|
||||
let dx = (离开段.武.read().unwrap().时间戳 - 离开段.文.时间戳) as f64;
|
||||
let dx = (离开段.武.read().unwrap().时间戳() - 离开段.文.时间戳()) as f64;
|
||||
if dx == 0.0 {
|
||||
return false;
|
||||
}
|
||||
@@ -92,11 +92,11 @@ impl 背驰分析 {
|
||||
|
||||
/// 测度背驰 — 价格时间测度背驰
|
||||
pub fn 测度背驰(进入段: &虚线, 离开段: &虚线) -> bool {
|
||||
let dx = (进入段.武.read().unwrap().时间戳 - 进入段.文.时间戳) as f64;
|
||||
let dx = (进入段.武.read().unwrap().时间戳() - 进入段.文.时间戳()) as f64;
|
||||
let dy = 进入段.武.read().unwrap().分型特征值 - 进入段.文.分型特征值;
|
||||
let 进入测度 = (dx * dx + dy * dy).sqrt();
|
||||
|
||||
let dx = (离开段.武.read().unwrap().时间戳 - 离开段.文.时间戳) as f64;
|
||||
let dx = (离开段.武.read().unwrap().时间戳() - 离开段.文.时间戳()) as f64;
|
||||
let dy = 离开段.武.read().unwrap().分型特征值 - 离开段.文.分型特征值;
|
||||
let 离开测度 = (dx * dx + dy * dy).sqrt();
|
||||
|
||||
|
||||
@@ -165,9 +165,9 @@ impl 中枢 {
|
||||
self.标识.read().unwrap(),
|
||||
self.序号.load(Ordering::Relaxed),
|
||||
self.级别.load(Ordering::Relaxed),
|
||||
self.文().时间戳,
|
||||
self.文().时间戳(),
|
||||
crate::utils::format_f64_g(self.文().分型特征值),
|
||||
self.武().时间戳,
|
||||
self.武().时间戳(),
|
||||
crate::utils::format_f64_g(self.武().分型特征值),
|
||||
第三买卖线_str,
|
||||
本级_第三买卖线_str,
|
||||
|
||||
@@ -106,7 +106,7 @@ impl 线段 {
|
||||
return;
|
||||
}
|
||||
if 段.武.read().unwrap().分型特征值 == 武.分型特征值
|
||||
&& 段.武.read().unwrap().时间戳 != 武.时间戳
|
||||
&& 段.武.read().unwrap().时间戳() != 武.时间戳()
|
||||
{
|
||||
eprintln!(
|
||||
"线段.武斗[{}], 发现特征值相等但时间戳不同 {} {}",
|
||||
|
||||
@@ -177,6 +177,7 @@ impl 观察者 {
|
||||
&mut self.笔序列,
|
||||
&self.缠论K线序列,
|
||||
&self.普通K线序列,
|
||||
0,
|
||||
&self.配置,
|
||||
);
|
||||
}
|
||||
@@ -289,6 +290,7 @@ impl 观察者 {
|
||||
&mut self.笔序列,
|
||||
&self.缠论K线序列,
|
||||
&self.普通K线序列,
|
||||
0,
|
||||
&self.配置,
|
||||
);
|
||||
}
|
||||
@@ -434,7 +436,7 @@ impl 观察者 {
|
||||
format!(
|
||||
"分型, {}, {}, {:?}, {}, {}, {}",
|
||||
i,
|
||||
fx.时间戳,
|
||||
fx.时间戳(),
|
||||
fx.结构,
|
||||
fx.分型特征值,
|
||||
fx.中.时间戳.load(Ordering::Relaxed),
|
||||
@@ -640,7 +642,7 @@ mod tests {
|
||||
let 文_ptr = Arc::as_ptr(&bi.文);
|
||||
let 文_found = obs_ref.分型序列.iter().any(|f| Arc::as_ptr(f) == 文_ptr);
|
||||
if !文_found {
|
||||
println!("笔 {}: 文(时间戳={}) 不在分型序列中!", i, bi.文.时间戳);
|
||||
println!("笔 {}: 文(时间戳={}) 不在分型序列中!", i, bi.文.时间戳());
|
||||
}
|
||||
|
||||
let 武_ptr = Arc::as_ptr(&*bi.武.read().unwrap());
|
||||
@@ -649,7 +651,7 @@ mod tests {
|
||||
println!(
|
||||
"笔 {}: 武(时间戳={}) 不在分型序列中!",
|
||||
i,
|
||||
bi.武.read().unwrap().时间戳
|
||||
bi.武.read().unwrap().时间戳()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,9 +239,9 @@ impl 虚线 {
|
||||
self.标识.read().unwrap(),
|
||||
self.序号.load(Ordering::Relaxed),
|
||||
self.级别.load(Ordering::Relaxed),
|
||||
self.文.时间戳,
|
||||
self.文.时间戳(),
|
||||
format_f64_g(self.文.分型特征值),
|
||||
self.武.read().unwrap().时间戳,
|
||||
self.武.read().unwrap().时间戳(),
|
||||
format_f64_g(self.武.read().unwrap().分型特征值),
|
||||
if self.有效性.load(Ordering::Relaxed) {
|
||||
"True"
|
||||
@@ -330,9 +330,9 @@ impl 虚线 {
|
||||
self.标识.read().unwrap(),
|
||||
self.序号.load(Ordering::Relaxed),
|
||||
self.级别.load(Ordering::Relaxed),
|
||||
self.文.时间戳,
|
||||
self.文.时间戳(),
|
||||
format_f64_g(self.文.分型特征值),
|
||||
self.武.read().unwrap().时间戳,
|
||||
self.武.read().unwrap().时间戳(),
|
||||
format_f64_g(self.武.read().unwrap().分型特征值),
|
||||
if self.有效性.load(Ordering::Relaxed) { "True" } else { "False" },
|
||||
self.基础序列.read().unwrap().len(),
|
||||
@@ -1232,7 +1232,7 @@ mod tests {
|
||||
assert_eq!(Arc::as_ptr(&笔.文), 文_ptr_before);
|
||||
|
||||
// 但方向变了(因为武从底1变成底2)
|
||||
let 新武耗时 = 笔.武.read().unwrap().时间戳;
|
||||
let 新武耗时 = 笔.武.read().unwrap().时间戳();
|
||||
assert_eq!(新武耗时, 300);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,13 @@
|
||||
use crate::kline::chan_kline::缠论K线;
|
||||
use crate::types::分型结构;
|
||||
use crate::types::相对方向;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// 分型模式 — True 时使用构造时缓存值(默认),False 时从 中 缠K 实时读取
|
||||
pub static 分型模式: AtomicBool = AtomicBool::new(true);
|
||||
|
||||
/// 分型 — 由三根缠K构成(可能缺左或右)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct 分型 {
|
||||
@@ -56,6 +60,15 @@ impl 分型 {
|
||||
}
|
||||
}
|
||||
|
||||
/// 时间戳 — 根据 分型模式 决定返回缓存值(True)或实时值(False)
|
||||
pub fn 时间戳(&self) -> i64 {
|
||||
if 分型模式.load(Ordering::Relaxed) {
|
||||
self.时间戳
|
||||
} else {
|
||||
self.中.时间戳.load(Ordering::Relaxed)
|
||||
}
|
||||
}
|
||||
|
||||
/// 左中右三组关系
|
||||
pub fn 关系组(&self) -> Option<(相对方向, 相对方向, 相对方向)> {
|
||||
let 左 = self.左.as_ref()?;
|
||||
@@ -215,7 +228,7 @@ impl std::fmt::Display for 分型 {
|
||||
.read()
|
||||
.unwrap()
|
||||
.unwrap_or(crate::types::分型结构::散),
|
||||
self.时间戳,
|
||||
self.时间戳(),
|
||||
crate::utils::format_f64_g(self.分型特征值),
|
||||
if self.左.is_none() { "True" } else { "False" },
|
||||
if self.右.is_none() { "True" } else { "False" },
|
||||
|
||||
@@ -63,7 +63,7 @@ impl 线段特征 {
|
||||
.分型特征值
|
||||
.partial_cmp(&b.文.分型特征值)
|
||||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
.then_with(|| a.文.时间戳.cmp(&b.文.时间戳))
|
||||
.then_with(|| a.文.时间戳().cmp(&b.文.时间戳()))
|
||||
})
|
||||
.map(|x| Arc::clone(&x.文))
|
||||
.unwrap_or_else(|| Arc::clone(&self.元素[0].文))
|
||||
@@ -75,7 +75,7 @@ impl 线段特征 {
|
||||
.分型特征值
|
||||
.partial_cmp(&b.文.分型特征值)
|
||||
.unwrap_or(std::cmp::Ordering::Equal)
|
||||
.then_with(|| b.文.时间戳.cmp(&a.文.时间戳))
|
||||
.then_with(|| b.文.时间戳().cmp(&a.文.时间戳()))
|
||||
})
|
||||
.map(|x| Arc::clone(&x.文))
|
||||
.unwrap_or_else(|| Arc::clone(&self.元素[0].文))
|
||||
@@ -99,8 +99,8 @@ impl 线段特征 {
|
||||
a.武
|
||||
.read()
|
||||
.unwrap()
|
||||
.时间戳
|
||||
.cmp(&b.武.read().unwrap().时间戳)
|
||||
.时间戳()
|
||||
.cmp(&b.武.read().unwrap().时间戳())
|
||||
})
|
||||
})
|
||||
.map(|x| x.武.read().unwrap().clone())
|
||||
@@ -119,8 +119,8 @@ impl 线段特征 {
|
||||
b.武
|
||||
.read()
|
||||
.unwrap()
|
||||
.时间戳
|
||||
.cmp(&a.武.read().unwrap().时间戳)
|
||||
.时间戳()
|
||||
.cmp(&a.武.read().unwrap().时间戳())
|
||||
})
|
||||
})
|
||||
.map(|x| x.武.read().unwrap().clone())
|
||||
@@ -527,7 +527,7 @@ mod tests {
|
||||
|
||||
let 文 = feat.文();
|
||||
// 向上取最大特征值:都是100 → tiebreaker取后时间戳 → 笔2.文(300)
|
||||
assert_eq!(文.时间戳, 300);
|
||||
assert_eq!(文.时间戳(), 300);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -544,7 +544,7 @@ mod tests {
|
||||
|
||||
let 武 = feat.武();
|
||||
// 向上取最大特征值:都是80 → tiebreaker取后时间戳 → 笔2.武(400)
|
||||
assert_eq!(武.时间戳, 400);
|
||||
assert_eq!(武.时间戳(), 400);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
|
||||
Reference in New Issue
Block a user