第三版

This commit is contained in:
YuWuKunCheng
2026-05-26 09:06:28 +08:00
parent bf96517c9d
commit 7416bfc73a
17 changed files with 4622 additions and 1 deletions
+825
View File
@@ -0,0 +1,825 @@
use pyo3::prelude::*;
use pyo3::types::PyType;
use std::collections::HashMap;
use std::rc::Rc;
use crate::config_py::Py;
use crate::kline_py::{K线Py, K线Py};
use crate::types_py::{Py, Py, Py};
// ========== 分型 ==========
#[pyclass(name = "分型", unsendable)]
#[derive(Clone)]
pub struct Py {
pub(crate) inner: Rc<chanlun::structure::fractal_obj::>,
}
#[pymethods]
impl Py {
#[new]
fn new(
: Option<&Bound<'_, K线Py>>,
: &Bound<'_, K线Py>,
: Option<&Bound<'_, K线Py>>,
) -> Self {
Self {
inner: Rc::new(chanlun::structure::fractal_obj::::new(
.map(|k| Rc::clone(&k.borrow().inner)),
Rc::clone(&.borrow().inner),
.map(|k| Rc::clone(&k.borrow().inner)),
)),
}
}
#[getter]
fn (&self) -> Option<K线Py> {
self.inner..as_ref().map(|k| K线Py {
inner: Rc::clone(k),
})
}
#[getter]
fn (&self) -> K线Py {
K线Py {
inner: Rc::clone(&self.inner.),
}
}
#[getter]
fn (&self) -> Option<K线Py> {
self.inner..as_ref().map(|k| K线Py {
inner: Rc::clone(k),
})
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.,
}
}
#[getter]
fn (&self) -> i64 {
self.inner.
}
#[getter]
fn (&self) -> f64 {
self.inner.
}
fn __str__(&self) -> String {
format!("{}", self.inner)
}
fn __repr__(&self) -> String {
self.__str__()
}
#[getter]
fn (&self) -> Option<(Py, Py, Py)> {
self.inner.().map(|(a, b, c)| {
(
Py { inner: a },
Py { inner: b },
Py { inner: c },
)
})
}
#[getter]
fn (&self) -> String {
self.inner.().to_string()
}
#[getter]
fn MACD柱子分型匹配(&self) -> bool {
self.inner.MACD柱子分型匹配()
}
#[classmethod]
#[pyo3(signature = (左, 右, 模式 = ""))]
fn (
_cls: &Bound<'_, PyType>,
: &Bound<'_, Self>,
: &Bound<'_, Self>,
: &str,
) -> bool {
chanlun::structure::fractal_obj::::(
&.borrow().inner,
&.borrow().inner,
,
)
}
#[staticmethod]
fn K序列中获取分型(
K线序列: Vec<Py<K线Py>>,
: &Bound<'_, K线Py>,
py: Python<'_>,
) -> Option<Self> {
let ck_seq: Vec<Rc<chanlun::kline::chan_kline::K线>> = K线序列
.iter()
.map(|k| Rc::clone(&k.bind(py).borrow().inner))
.collect();
chanlun::structure::fractal_obj::::K序列中获取分型(
&ck_seq,
&.borrow().inner,
)
.map(|inner| Self {
inner: Rc::new(inner),
})
}
#[staticmethod]
fn (
: &Bound<'_, PyAny>, : &Bound<'_, Self>
) -> PyResult<()> {
let py = .py();
let inner = Rc::clone(&.borrow().inner);
let wrapper = Py::new(
py,
Self {
inner: Rc::clone(&inner),
},
)?;
.call_method1("append", (wrapper,))?;
Ok(())
}
}
// ========== 虚线 ==========
#[pyclass(name = "虚线", unsendable)]
#[derive(Clone)]
pub struct 线Py {
pub(crate) inner: Rc<chanlun::structure::dash_line::线>,
}
#[pymethods]
impl 线Py {
#[new]
#[pyo3(signature = (序号, 标识, 文, 武, 级别, 有效性 = true))]
fn new(
: i64,
: String,
: &Bound<'_, Py>,
: &Bound<'_, Py>,
: i64,
: bool,
) -> Self {
Self {
inner: Rc::new(chanlun::structure::dash_line::线::new(
,
,
Rc::clone(&.borrow().inner),
Rc::clone(&.borrow().inner),
,
,
)),
}
}
// ---- 基础 getters ----
#[getter]
fn (&self) -> String {
self.inner..clone()
}
#[getter]
fn (&self) -> i64 {
self.inner.
}
#[getter]
fn (&self) -> i64 {
self.inner.
}
#[getter]
fn (&self) -> Py {
Py {
inner: Rc::clone(&self.inner.),
}
}
#[getter]
fn (&self) -> Py {
Py {
inner: Rc::clone(&self.inner.),
}
}
#[getter]
fn (&self) -> bool {
self.inner.
}
#[getter]
fn (&self) -> String {
self.inner..clone()
}
#[getter]
fn _特征序列_显示(&self) -> bool {
self.inner._特征序列_显示
}
#[getter]
fn (&self) -> bool {
self.inner.
}
#[getter]
fn K线(&self) -> Option<K线Py> {
self.inner.K线.as_ref().map(|k| K线Py {
inner: Rc::clone(k),
})
}
#[getter]
fn (&self) -> Option<Py> {
self.inner..map(|q| Py { inner: q })
}
#[getter]
fn (&self) -> Option<Self> {
self.inner..as_ref().map(|d| Self {
inner: Rc::clone(d),
})
}
// ---- 序列 getters ----
#[getter]
fn (&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
let list = pyo3::types::PyList::empty(py);
for d in &self.inner. {
list.append(Py::new(
py,
Self {
inner: Rc::clone(d),
},
)?)?;
}
Ok(list.into())
}
// 实_中枢序列 / 虚_中枢序列 / 合_中枢序列 — deferred to Phase 6 (中枢Py not yet available)
// ---- 计算属性 ----
#[getter]
fn (&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
let list = pyo3::types::PyList::empty(py);
for d in self.inner.() {
list.append(Py::new(
py,
Self {
inner: Rc::clone(d),
},
)?)?;
}
Ok(list.into())
}
#[getter]
fn (&self) -> String {
self.inner.()
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.(),
}
}
#[getter]
fn (&self) -> f64 {
self.inner.()
}
#[getter]
fn (&self) -> f64 {
self.inner.()
}
fn (&self, : &Bound<'_, Self>) -> bool {
self.inner.(&.borrow().inner)
}
fn (&self, : &Bound<'_, Self>) -> bool {
self.inner.(&.borrow().inner)
}
fn K序列(&self, K序列: Vec<Py<K线Py>>, py: Python<'_>) -> PyResult<Py<PyAny>> {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
let result = self.inner.K序列(&rc_list);
let list = pyo3::types::PyList::empty(py);
for k in &result {
list.append(K线Py {
inner: (**k).clone(),
})?;
}
Ok(list.into())
}
fn K序列(
&self, K序列: Vec<Py<K线Py>>, py: Python<'_>
) -> PyResult<Py<PyAny>> {
let rc_list: Vec<Rc<chanlun::kline::chan_kline::K线>> = K序列
.iter()
.map(|k| Rc::clone(&k.bind(py).borrow().inner))
.collect();
let result = self.inner.K序列(&rc_list);
let list = pyo3::types::PyList::empty(py);
for k in &result {
list.append(K线Py {
inner: Rc::clone(k),
})?;
}
Ok(list.into())
}
#[getter]
fn (&self) -> String {
self.inner.()
}
fn __str__(&self) -> String {
format!("{}", self.inner)
}
fn __repr__(&self) -> String {
self.__str__()
}
// ---- 静态工厂方法 ----
#[classmethod]
fn (
_cls: &Bound<'_, PyType>,
: &Bound<'_, Py>,
: &Bound<'_, Py>,
: bool,
) -> Self {
Self {
inner: Rc::new(chanlun::structure::dash_line::线::(
Rc::clone(&.borrow().inner),
Rc::clone(&.borrow().inner),
,
)),
}
}
#[classmethod]
fn 线(_cls: &Bound<'_, PyType>, 线: Vec<Py<Self>>, py: Python<'_>) -> Self {
let rc_list: Vec<Rc<chanlun::structure::dash_line::线>> = 线
.iter()
.map(|d| Rc::clone(&d.bind(py).borrow().inner))
.collect();
Self {
inner: Rc::new(chanlun::structure::dash_line::线::线(
&rc_list,
)),
}
}
// ---- 买卖点模式匹配 ----
#[classmethod]
fn K买卖点模式(
_cls: &Bound<'_, PyType>,
: &str,
K: &Bound<'_, K线Py>,
: &Bound<'_, Py>,
py: Python<'_>,
) -> PyResult<bool> {
let config = .borrow().to_rust_config(py)?;
Ok(chanlun::structure::dash_line::线::K买卖点模式(
,
&K.borrow().inner,
&config,
))
}
#[classmethod]
fn (
_cls: &Bound<'_, PyType>,
K: &Bound<'_, K线Py>,
: &Bound<'_, Py>,
py: Python<'_>,
) -> PyResult<bool> {
let config = .borrow().to_rust_config(py)?;
Ok(chanlun::structure::dash_line::线::(
&K.borrow().inner,
&config,
))
}
#[classmethod]
fn (_cls: &Bound<'_, PyType>, K: &Bound<'_, K线Py>) -> bool {
chanlun::structure::dash_line::线::(&K.borrow().inner)
}
#[classmethod]
fn (_cls: &Bound<'_, PyType>, K: &Bound<'_, K线Py>) -> bool {
chanlun::structure::dash_line::线::(&K.borrow().inner)
}
#[classmethod]
fn (_cls: &Bound<'_, PyType>, K: &Bound<'_, K线Py>) -> bool {
chanlun::structure::dash_line::线::(&K.borrow().inner)
}
// ---- MACD 相关 classmethods ----
#[classmethod]
fn MACD柱子均值(
_cls: &Bound<'_, PyType>,
K序列: Vec<Py<K线Py>>,
线: &Bound<'_, Self>,
py: Python<'_>,
) -> f64 {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::MACD柱子均值(
&rc_list,
&线.borrow().inner,
)
}
#[classmethod]
fn MACD均值(
_cls: &Bound<'_, PyType>,
K序列: Vec<Py<K线Py>>,
线: &Bound<'_, Self>,
py: Python<'_>,
) -> bool {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::MACD均值(
&rc_list,
&线.borrow().inner,
)
}
#[classmethod]
fn MACD均值(
_cls: &Bound<'_, PyType>,
K序列: Vec<Py<K线Py>>,
线: &Bound<'_, Self>,
py: Python<'_>,
) -> bool {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::MACD均值(&rc_list, &线.borrow().inner)
}
#[classmethod]
fn MACD极值(
_cls: &Bound<'_, PyType>,
K序列: Vec<Py<K线Py>>,
线: &Bound<'_, Self>,
py: Python<'_>,
) -> bool {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::MACD极值(&rc_list, &线.borrow().inner)
}
#[classmethod]
fn K线序列MACD趋向背驰(
_cls: &Bound<'_, PyType>,
K序列: Vec<Py<K线Py>>,
: &Bound<'_, Py>,
py: Python<'_>,
) -> [bool; 3] {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::K线序列MACD趋向背驰(
&rc_list,
.borrow().inner,
)
}
#[classmethod]
fn MACD柱子分段(
_cls: &Bound<'_, PyType>,
k线序列: Vec<Py<K线Py>>,
py: Python<'_>,
) -> Vec<Vec<f64>> {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = k线序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::MACD柱子分段(&rc_list)
}
#[classmethod]
fn (
_cls: &Bound<'_, PyType>,
: Vec<i32>,
: usize,
: usize,
) -> Vec<(usize, usize, usize)> {
chanlun::structure::dash_line::线::(
&,
,
,
)
}
#[classmethod]
fn MACD行为(
_cls: &Bound<'_, PyType>,
K序列: Vec<Py<K线Py>>,
: usize,
: usize,
py: Python<'_>,
) -> HashMap<String, String> {
let rc_list: Vec<Rc<chanlun::kline::bar::K线>> = K序列
.iter()
.map(|k| Rc::new(k.bind(py).borrow().inner.clone()))
.collect();
chanlun::structure::dash_line::线::MACD行为(&rc_list, , )
}
// 买卖意义 — deferred to Phase 7 (needs observer)
}
// ========== 线段特征 ==========
#[pyclass(name = "线段特征", unsendable)]
#[derive(Clone)]
pub struct 线Py {
pub(crate) inner: Rc<chanlun::structure::segment_feat::线>,
}
#[pymethods]
impl 线Py {
#[new]
fn new(
: String,
: Vec<Py<线Py>>,
线: &Bound<'_, Py>,
py: Python<'_>,
) -> Self {
let rc_list: Vec<Rc<chanlun::structure::dash_line::线>> =
.iter()
.map(|d| Rc::clone(&d.bind(py).borrow().inner))
.collect();
Self {
inner: Rc::new(chanlun::structure::segment_feat::线::new(
,
rc_list,
线.borrow().inner,
)),
}
}
// ---- getters ----
#[getter]
fn (&self) -> i64 {
self.inner.
}
#[getter]
fn (&self) -> String {
self.inner..clone()
}
#[getter]
fn 线(&self) -> Py {
Py {
inner: self.inner.线,
}
}
#[getter]
fn (&self, py: Python<'_>) -> PyResult<Py<PyAny>> {
let list = pyo3::types::PyList::empty(py);
for d in &self.inner. {
list.append(Py::new(
py,
线Py {
inner: Rc::clone(d),
},
)?)?;
}
Ok(list.into())
}
fn __str__(&self) -> String {
format!("{}", self.inner)
}
fn __repr__(&self) -> String {
self.__str__()
}
// ---- instance methods ----
#[getter]
fn (&self) -> String {
self.inner.()
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.(),
}
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.(),
}
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.(),
}
}
#[getter]
fn (&self) -> f64 {
self.inner.()
}
#[getter]
fn (&self) -> f64 {
self.inner.()
}
fn (&mut self, 线: &Bound<'_, 线Py>) -> PyResult<()> {
let inner = Rc::make_mut(&mut self.inner);
inner
.(Rc::clone(&线.borrow().inner))
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e))
}
fn (&mut self, 线: &Bound<'_, 线Py>) -> PyResult<()> {
let inner = Rc::make_mut(&mut self.inner);
inner
.(&Rc::clone(&线.borrow().inner))
.map_err(|e| pyo3::exceptions::PyValueError::new_err(e))
}
// ---- classmethods ----
#[classmethod]
fn (
_cls: &Bound<'_, PyType>,
线: Vec<Py<线Py>>,
线: &Bound<'_, Py>,
py: Python<'_>,
) -> Self {
let rc_list: Vec<Rc<chanlun::structure::dash_line::线>> = 线
.iter()
.map(|d| Rc::clone(&d.bind(py).borrow().inner))
.collect();
Self {
inner: Rc::new(chanlun::structure::segment_feat::线::(
rc_list,
线.borrow().inner,
)),
}
}
#[classmethod]
fn (
_cls: &Bound<'_, PyType>,
线: Vec<Py<线Py>>,
线: &Bound<'_, Py>,
: &str,
: bool,
py: Python<'_>,
) -> Vec<Self> {
let rc_list: Vec<Rc<chanlun::structure::dash_line::线>> = 线
.iter()
.map(|d| Rc::clone(&d.bind(py).borrow().inner))
.collect();
chanlun::structure::segment_feat::线::(
&rc_list,
线.borrow().inner,
,
,
)
.into_iter()
.map(|inner| Self { inner })
.collect()
}
#[classmethod]
fn (
_cls: &Bound<'_, PyType>,
: Vec<Py<Self>>,
py: Python<'_>,
) -> Vec<Py> {
let rc_list: Vec<Rc<chanlun::structure::segment_feat::线>> =
.iter()
.map(|s| Rc::clone(&s.bind(py).borrow().inner))
.collect();
chanlun::structure::segment_feat::线::(&rc_list)
.into_iter()
.map(|inner| Py {
inner: Rc::new(inner),
})
.collect()
}
}
// ========== 特征分型 ==========
#[pyclass(name = "特征分型", unsendable)]
#[derive(Clone)]
pub struct Py {
pub(crate) inner: Rc<chanlun::structure::feat_fractal::>,
}
#[pymethods]
impl Py {
#[new]
fn new(
: &Bound<'_, 线Py>,
: &Bound<'_, 线Py>,
: &Bound<'_, 线Py>,
: &Bound<'_, Py>,
) -> Self {
Self {
inner: Rc::new(chanlun::structure::feat_fractal::::new(
Rc::clone(&.borrow().inner),
Rc::clone(&.borrow().inner),
Rc::clone(&.borrow().inner),
.borrow().inner,
)),
}
}
#[getter]
fn (&self) -> 线Py {
线Py {
inner: Rc::clone(&self.inner.),
}
}
#[getter]
fn (&self) -> 线Py {
线Py {
inner: Rc::clone(&self.inner.),
}
}
#[getter]
fn (&self) -> 线Py {
线Py {
inner: Rc::clone(&self.inner.),
}
}
#[getter]
fn (&self) -> Py {
Py {
inner: self.inner.,
}
}
fn __str__(&self) -> String {
format!("{}", self.inner)
}
fn __repr__(&self) -> String {
self.__str__()
}
}
pub fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Py>()?;
m.add_class::<线Py>()?;
m.add_class::<线Py>()?;
m.add_class::<Py>()?;
Ok(())
}