修复 中枢一致性

This commit is contained in:
YuWuKunCheng
2026-05-29 20:19:42 +08:00
parent c87fb66d34
commit e50172e923
5 changed files with 57 additions and 32 deletions
+3 -3
View File
@@ -450,12 +450,12 @@ impl 缠论K线Py {
}
#[getter]
fn (&self) -> Option<crate::types_py::Py> {
fn (&self, py: Python<'_>) -> Option<Py<crate::types_py::Py>> {
self.inner
.
.read()
.unwrap()
.map(|f| crate::types_py::Py { inner: f })
.map(|f| crate::types_py::(py, f))
}
#[getter]
@@ -506,7 +506,7 @@ impl 缠论K线Py {
dict.set_item("与RSI匹配", self.RSI匹配())?;
dict.set_item("与KDJ匹配", self.KDJ匹配())?;
if let Some(v) = self.() {
if let Some(v) = self.(py) {
dict.set_item("分型", v)?;
}
Ok(dict.into())
+15 -21
View File
@@ -184,22 +184,18 @@ impl 分型Py {
}
#[getter]
fn (&self) -> Py {
if chanlun::structure::fractal_obj::.load(Ordering::Relaxed) {
Py {
inner: self.inner.,
}
fn (&self, py: Python<'_>) -> Py<Py> {
let inner = if chanlun::structure::fractal_obj::.load(Ordering::Relaxed) {
self.inner.
} else {
Py {
inner: self
.inner
.
.
.read()
.unwrap()
.unwrap_or(chanlun::types::::),
}
}
self.inner
.
.
.read()
.unwrap()
.unwrap_or(chanlun::types::::)
};
crate::types_py::(py, inner)
}
#[getter]
@@ -263,7 +259,7 @@ impl 分型Py {
#[getter]
fn __dict__(&self, py: Python<'_>) -> PyResult<Py<PyDict>> {
let dict = PyDict::new(py);
dict.set_item("结构", self.())?;
dict.set_item("结构", self.(py))?;
dict.set_item("时间戳", self.())?;
dict.set_item("分型特征值", self.())?;
dict.set_item("强度", self.())?;
@@ -1280,17 +1276,15 @@ impl 特征分型Py {
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.,
}
fn (&self, py: Python<'_>) -> Py<Py> {
crate::types_py::(py, self.inner.)
}
/// pandas 兼容 — 返回关键标量字段构成的字典
#[getter]
fn __dict__(&self, py: Python<'_>) -> PyResult<Py<PyDict>> {
let dict = PyDict::new(py);
dict.set_item("结构", self.())?;
dict.set_item("结构", self.(py))?;
Ok(dict.into())
}
+35
View File
@@ -22,10 +22,45 @@
* SOFTWARE.
*/
use std::collections::HashMap;
use std::sync::Mutex;
use pyo3::basic::CompareOp;
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyType};
// ========== 单例缓存 ==========
static _单例缓存: Mutex<Option<HashMap<u8, Py<Py>>>> = Mutex::new(None);
pub fn (
py: Python<'_>,
inner: chanlun::types::,
) -> Py<Py> {
let mut guard = _单例缓存.lock().unwrap();
if let Some(ref map) = *guard {
return map[&(inner as u8)].clone_ref(py);
}
// 首次访问时从类属性加载单例
let module = py.import("chanlun._chanlun").unwrap();
let class = module.getattr("分型结构").unwrap();
let mut map = HashMap::new();
for (name, variant) in &[
("", chanlun::types::::),
("", chanlun::types::::),
("", chanlun::types::::),
("", chanlun::types::::),
("", chanlun::types::::),
] {
let instance: Py<Py> = class.getattr(*name).unwrap().extract().unwrap();
map.insert(*variant as u8, instance);
}
let result = map[&(inner as u8)].clone_ref(py);
*guard = Some(map);
result
}
// ========== 买卖点类型 ==========
/// 买卖点类型 — 缠论的三类买卖点及扩展类型。
+1 -1
View File
@@ -387,7 +387,7 @@ impl 中枢 {
/// 向中枢序列尾部添加
pub fn (
: &mut Vec<Arc<>>, mut : Arc<>
: &mut Vec<Arc<>>, : Arc<>
) {
if let Some() = .last() {
+3 -7
View File
@@ -474,7 +474,7 @@ impl 线段 {
/// 分割序列 — 将线段的基础序列分为前、后、第三买卖线、贯穿伤
pub fn (
: &线,
mut : Option<&mut >,
: Option<&>,
) -> (
Vec<Arc<线>>,
Vec<Arc<线>>,
@@ -517,7 +517,7 @@ impl 线段 {
let mut = None;
if let Some(ref mut ) = {
if let Some(ref ) = {
*._第三买卖线.write().unwrap() = None;
let = if let Some(ref ) = .last() {
..read().unwrap().clone()
@@ -548,8 +548,6 @@ impl 线段 {
} else {
break;
}
} else {
break;
}
}
}
@@ -568,15 +566,13 @@ impl 线段 {
} else {
break;
}
} else {
break;
}
}
}
if !线.is_empty() {
线.reverse();
if let Some(ref mut ) = {
if let Some(ref ) = {
*._第三买卖线.write().unwrap() = Some(Arc::clone(&线[0]));
}
}