第十版

This commit is contained in:
YuWuKunCheng
2026-06-07 17:02:10 +08:00
parent 4bf9461009
commit 11d897ebaa
8 changed files with 560 additions and 78 deletions
+93 -35
View File
@@ -25,7 +25,7 @@
use crate::kline_py::chan_kline_to_py;
use crate::structure_py::{dashed_to_py, fractal_to_py};
use pyo3::prelude::*;
use pyo3::types::{PyDict, PyType};
use pyo3::types::{PyDict, PyList, PyType};
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::RwLock;
@@ -308,11 +308,13 @@ impl 笔Py {
#[classmethod]
#[pyo3(signature = (当前分型, 分型序列, 笔序列, 缠K序列, 普K序列, 递归层次, 配置))]
/// 笔划分核心递归算法
/// 分型序列/笔序列 原地修改(与 chan.py 行为一致)
/// :return: 递归层次
fn (
_cls: &Bound<'_, PyType>,
: Option<&Bound<'_, Py>>,
: Vec<Py<Py>>,
: Vec<Py<线Py>>,
: &Bound<'_, PyList>,
: &Bound<'_, PyList>,
K序列: Vec<Py<crate::kline_py::K线Py>>,
K序列: Vec<Py<K线Py>>,
: i64,
@@ -321,14 +323,19 @@ impl 笔Py {
) -> PyResult<i64> {
let _ = ; // Python API 兼容参数,核心从0开始计数
let _rc = .map(|f| Arc::clone(&f.borrow().inner));
let mut fr_seq: Vec<Arc<chanlun::structure::fractal_obj::>> =
.iter()
.map(|f| Arc::clone(&f.bind(py).borrow().inner))
.collect();
let mut bi_seq: Vec<Arc<chanlun::structure::dash_line::线>> =
.iter()
.map(|d| Arc::clone(&d.bind(py).borrow().inner))
.collect();
// 从 Python 列表提取
let mut fr_seq = Vec::with_capacity(.len());
for item in .iter() {
let f: PyRef<'_, Py> = item.extract()?;
fr_seq.push(Arc::clone(&f.inner));
}
let mut bi_seq = Vec::with_capacity(.len());
for item in .iter() {
let d: PyRef<'_, 线Py> = item.extract()?;
bi_seq.push(Arc::clone(&d.inner));
}
let ck_list: Vec<Arc<chanlun::kline::chan_kline::K线>> = K序列
.iter()
.map(|k| Arc::clone(&k.bind(py).borrow().inner))
@@ -338,8 +345,8 @@ impl 笔Py {
.map(|k| k.bind(py).borrow().inner.clone())
.collect();
let config = .borrow().to_rust_config(py)?;
match _rc {
Some(fr) => Ok(chanlun::algorithm::bi::::(
let depth = match _rc {
Some(fr) => chanlun::algorithm::bi::::(
fr,
&mut fr_seq,
&mut bi_seq,
@@ -347,9 +354,21 @@ impl 笔Py {
&bar_list,
,
&config,
)),
None => Ok(),
),
None => ,
};
// 写回 Python 列表
.call_method0("clear")?;
for f in fr_seq {
.call_method1("append", (fractal_to_py(py, f),))?;
}
.call_method0("clear")?;
for d in bi_seq {
.call_method1("append", (dashed_to_py(py, d),))?;
}
Ok(depth)
}
#[classmethod]
@@ -502,11 +521,13 @@ impl 线段Py {
}
#[classmethod]
#[pyo3(signature = (笔序列, 线段序列, 配置, 层级 = 0, 关系序列 = None))]
/// 线段划分核心递归算法
/// 线段序列 原地修改(与 chan.py 行为一致)
fn (
_cls: &Bound<'_, PyType>,
: Vec<Py<线Py>>,
线: Vec<Py<线Py>>,
线: &Bound<'_, PyList>,
: &Bound<'_, Py>,
: i64,
: Option<Vec<Py>>,
@@ -516,10 +537,13 @@ impl 线段Py {
.iter()
.map(|d| Arc::clone(&d.bind(py).borrow().inner))
.collect();
let mut seg_seq: Vec<Arc<chanlun::structure::dash_line::线>> = 线
.iter()
.map(|d| Arc::clone(&d.bind(py).borrow().inner))
.collect();
let mut seg_seq = Vec::with_capacity(线.len());
for item in 线.iter() {
let d: PyRef<'_, 线Py> = item.extract()?;
seg_seq.push(Arc::clone(&d.inner));
}
let config = .borrow().to_rust_config(py)?;
let default_rel = vec![
chanlun::types::::,
@@ -535,15 +559,22 @@ impl 线段Py {
,
&rel_list,
);
// 写回 Python 列表
线.call_method0("clear")?;
for d in seg_seq {
线.call_method1("append", (dashed_to_py(py, d),))?;
}
Ok(())
}
#[classmethod]
/// 即同级别分析
/// 线段序列 原地修改(与 chan.py 行为一致)
fn (
_cls: &Bound<'_, PyType>,
线: Vec<Py<线Py>>,
线: Vec<Py<线Py>>,
线: &Bound<'_, PyList>,
: &Bound<'_, Py>,
py: Python<'_>,
) -> PyResult<()> {
@@ -551,12 +582,21 @@ impl 线段Py {
.iter()
.map(|d| Arc::clone(&d.bind(py).borrow().inner))
.collect();
let mut seg_seq: Vec<Arc<chanlun::structure::dash_line::线>> = 线
.iter()
.map(|d| Arc::clone(&d.bind(py).borrow().inner))
.collect();
let mut seg_seq = Vec::with_capacity(线.len());
for item in 线.iter() {
let d: PyRef<'_, 线Py> = item.extract()?;
seg_seq.push(Arc::clone(&d.inner));
}
let config = .borrow().to_rust_config(py)?;
chanlun::algorithm::segment::线::(&dash_list, &mut seg_seq, &config);
// 写回 Python 列表
线.call_method0("clear")?;
for d in seg_seq {
线.call_method1("append", (dashed_to_py(py, d),))?;
}
Ok(())
}
@@ -792,18 +832,26 @@ impl 中枢Py {
}
/// 当基础序列>=9时,从中枢中提取扩展线段中枢
/// 扩展中枢 原地修改(与 chan.py 行为一致)
fn (
&self,
: Vec<Py<Self>>,
: &Bound<'_, PyList>,
: &Bound<'_, crate::config_py::Py>,
py: Python<'_>,
) -> PyResult<()> {
let mut hub_seq: Vec<Arc<chanlun::algorithm::hub::>> =
.iter()
.map(|h| Arc::clone(&h.bind(py).borrow().inner))
.collect();
let mut hub_seq = Vec::with_capacity(.len());
for item in .iter() {
let h: PyRef<'_, Py> = item.extract()?;
hub_seq.push(Arc::clone(&h.inner));
}
let config = .borrow().to_rust_config(.py())?;
self.inner.(&mut hub_seq, &config);
// 写回 Python 列表
.call_method0("clear")?;
for h in hub_seq {
.call_method1("append", (hub_to_py(py, h),))?;
}
Ok(())
}
@@ -889,10 +937,11 @@ impl 中枢Py {
#[classmethod]
#[pyo3(signature = (虚线序列, 中枢序列, 跳过首部 = true, 标识 = "", 层级 = 0))]
/// 中枢识别核心递归算法
/// 中枢序列 原地修改(与 chan.py 行为一致)
fn (
_cls: &Bound<'_, PyType>,
线: Vec<Py<线Py>>,
: Vec<Py<Self>>,
: &Bound<'_, PyList>,
: bool,
: &str,
: i64,
@@ -902,11 +951,20 @@ impl 中枢Py {
.iter()
.map(|d| Arc::clone(&d.bind(py).borrow().inner))
.collect();
let mut hub_seq: Vec<Arc<chanlun::algorithm::hub::>> =
.iter()
.map(|h| Arc::clone(&h.bind(py).borrow().inner))
.collect();
let mut hub_seq = Vec::with_capacity(.len());
for item in .iter() {
let h: PyRef<'_, Py> = item.extract()?;
hub_seq.push(Arc::clone(&h.inner));
}
chanlun::algorithm::hub::::(&rc_list, &mut hub_seq, , , );
// 写回 Python 列表
.call_method0("clear")?;
for h in hub_seq {
.call_method1("append", (hub_to_py(py, h),))?;
}
Ok(())
}
+26 -11
View File
@@ -23,7 +23,7 @@
*/
use pyo3::prelude::*;
use pyo3::types::{PyBytes, PyDict, PyType};
use pyo3::types::{PyBytes, PyDict, PyList, PyType};
use std::collections::HashMap;
use std::sync::Arc;
use std::sync::RwLock;
@@ -663,25 +663,30 @@ impl 缠论K线Py {
#[classmethod]
/// 分析K线,执行指标计算+包含处理+分型判定
/// 缠K序列/普K序列 原地修改(与 chan.py 行为一致)
/// :return: (状态, 分型|None)
fn (
_cls: &Bound<'_, PyType>,
K线: &Bound<'_, K线Py>,
K序列: Vec<Py<Self>>,
K序列: Vec<Py<K线Py>>,
K序列: &Bound<'_, PyList>,
K序列: &Bound<'_, PyList>,
: &Bound<'_, Py>,
py: Python<'_>,
) -> PyResult<(String, Option<Py<PyAny>>)> {
let ck_inner = (*K线.borrow().inner).clone();
let config = .borrow().to_rust_config(py)?;
let mut ck_seq: Vec<_> = K序列
.iter()
.map(|k| std::sync::Arc::clone(&k.bind(py).borrow().inner))
.collect();
let mut bar_seq: Vec<_> = K序列
.iter()
.map(|k| k.bind(py).borrow().inner.clone())
.collect();
// 从 Python 列表提取
let mut ck_seq = Vec::with_capacity(K序列.len());
for item in K序列.iter() {
let ck: PyRef<'_, Self> = item.extract()?;
ck_seq.push(std::sync::Arc::clone(&ck.inner));
}
let mut bar_seq = Vec::with_capacity(K序列.len());
for item in K序列.iter() {
let bar: PyRef<'_, K线Py> = item.extract()?;
bar_seq.push(bar.inner.clone());
}
let (status, fractal) = chanlun::kline::chan_kline::K线::(
ck_inner,
@@ -690,6 +695,16 @@ impl 缠论K线Py {
&config,
);
// 写回 Python 列表(clear + extend
K序列.call_method0("clear")?;
for k in ck_seq {
K序列.call_method1("append", (chan_kline_to_py(py, k),))?;
}
K序列.call_method0("clear")?;
for k in bar_seq {
K序列.call_method1("append", (bar_to_py(py, k),))?;
}
Ok((status, fractal.map(|f| fractal_to_py(py, f).into_any())))
}