KQuery/KRecord 相等与不等比较导出至 python

This commit is contained in:
fasiondog 2023-10-29 18:25:06 +08:00
parent 2c23644593
commit e51f2bfc6c
6 changed files with 52 additions and 31 deletions

View File

@ -29,29 +29,29 @@ const string KQuery::HOUR12("HOUR12");
// const string KQuery::INVALID_KTYPE("Z");
static vector<string> g_all_ktype{KQuery::MIN, KQuery::MIN5, KQuery::MIN15, KQuery::MIN30,
KQuery::MIN60, KQuery::DAY, KQuery::WEEK, KQuery::MONTH,
KQuery::QUARTER, KQuery::HALFYEAR, KQuery::YEAR, KQuery::MIN3,
KQuery::HOUR2, KQuery::HOUR4, KQuery::HOUR6, KQuery::HOUR12};
KQuery::MIN60, KQuery::DAY, KQuery::WEEK, KQuery::MONTH,
KQuery::QUARTER, KQuery::HALFYEAR, KQuery::YEAR, KQuery::MIN3,
KQuery::HOUR2, KQuery::HOUR4, KQuery::HOUR6, KQuery::HOUR12};
static const unordered_map<string, int32_t> g_ktype2min{
{KQuery::MIN, 1},
{KQuery::MIN3, 3},
{KQuery::MIN, 1},
{KQuery::MIN3, 3},
{KQuery::MIN5, 5},
{KQuery::MIN15, 15},
{KQuery::MIN30, 30},
{KQuery::MIN60, 60},
{KQuery::HOUR2, 60 * 2},
{KQuery::HOUR4, 60 * 4},
{KQuery::HOUR6, 60 * 6},
{KQuery::HOUR12, 60 * 12},
{KQuery::MIN5, 5},
{KQuery::MIN15, 15},
{KQuery::MIN30, 30},
{KQuery::MIN60, 60},
{KQuery::HOUR2, 60 * 2},
{KQuery::HOUR4, 60 * 4},
{KQuery::HOUR6, 60 * 6},
{KQuery::HOUR12, 60 * 12},
{KQuery::DAY, 60 * 24},
{KQuery::WEEK, 60 * 24 * 7},
{KQuery::MONTH, 60 * 24 * 30},
{KQuery::QUARTER, 60 * 24 * 30 * 3},
{KQuery::HALFYEAR, 60 * 24 * 30 * 6},
{KQuery::YEAR, 60 * 24 * 365},
{KQuery::DAY, 60 * 24},
{KQuery::WEEK, 60 * 24 * 7},
{KQuery::MONTH, 60 * 24 * 30},
{KQuery::QUARTER, 60 * 24 * 30 * 3},
{KQuery::HALFYEAR, 60 * 24 * 30 * 6},
{KQuery::YEAR, 60 * 24 * 365},
};
// 获取所有的 KType
@ -163,4 +163,16 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KQuery& query) {
return os;
}
bool HKU_API operator!=(const KQuery& q1, const KQuery& q2) {
// cppcheck-suppress [mismatchingContainerExpression]
return q1.start() != q2.start() || q1.end() != q2.end() || q1.queryType() != q2.queryType() ||
q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType();
}
bool HKU_API operator==(const KQuery& q1, const KQuery& q2) {
// cppcheck-suppress [mismatchingContainerExpression]
return q1.start() == q2.start() && q1.end() == q2.end() && q1.queryType() == q2.queryType() &&
q1.kType() == q2.kType() && q1.recoverType() == q2.recoverType();
}
} // namespace hku

View File

@ -244,18 +244,8 @@ HKU_API std::ostream& operator<<(std::ostream& os, const KQuery& query);
// 关系比较函数, 不直接在类中定义是为了支持 Null<>() == dNull可以放在左边
//
///////////////////////////////////////////////////////////////////////////////
bool operator==(const KQuery&, const KQuery&);
bool operator!=(const KQuery&, const KQuery&);
inline bool operator!=(const KQuery& q1, const KQuery& q2) {
// cppcheck-suppress [mismatchingContainerExpression]
return q1.start() != q2.start() || q1.end() != q2.end() || q1.queryType() != q2.queryType() ||
q1.kType() != q2.kType() || q1.recoverType() != q2.recoverType();
}
inline bool operator==(const KQuery& q1, const KQuery& q2) {
return !(q1 != q2);
}
bool HKU_API operator==(const KQuery&, const KQuery&);
bool HKU_API operator!=(const KQuery&, const KQuery&);
/**
* KQuery的Null值

View File

@ -30,4 +30,8 @@ bool HKU_API operator==(const KRecord& d1, const KRecord& d2) {
(std::fabs(d1.transCount - d2.transCount) < 0.0001));
}
bool HKU_API operator!=(const KRecord& d1, const KRecord& d2) {
return !(d1 == d2);
}
} // namespace hku

View File

@ -78,6 +78,12 @@ HKU_API std::ostream& operator<<(std::ostream&, const KRecord&);
*/
bool HKU_API operator==(const KRecord& d1, const KRecord& d2);
/**
* KRecord不等比较
* @ingroup StockManage
*/
bool HKU_API operator!=(const KRecord& d1, const KRecord& d2);
} // namespace hku
#if FMT_VERSION >= 90000

View File

@ -15,6 +15,9 @@ using namespace hku;
KQuery::RecoverType (KQuery::*get_recoverType)() const = &KQuery::recoverType;
void (KQuery::*set_recoverType)(KQuery::RecoverType recoverType) = &KQuery::recoverType;
bool (*kquery_eq)(const KQuery&, const KQuery&) = operator==;
bool (*kquery_ne)(const KQuery&, const KQuery&) = operator!=;
void export_KQuery() {
scope in_Query =
class_<KQuery>("Query", "K线数据查询条件", init<>())
@ -37,6 +40,9 @@ void export_KQuery() {
.add_property("recover_type", get_recoverType, set_recoverType,
"查询的复权类型 Query.RecoverType")
.def("__eq__", kquery_eq)
.def("__ne__", kquery_ne)
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<KQuery>())
#endif

View File

@ -18,6 +18,7 @@ using namespace hku;
#endif
bool (*krecord_eq)(const KRecord&, const KRecord&) = operator==;
bool (*krecord_ne)(const KRecord&, const KRecord&) = operator!=;
void export_KReord() {
class_<KRecord>("KRecord", "K线记录组成K线数据属性可读写", init<>())
@ -35,6 +36,8 @@ void export_KReord() {
.def_readwrite("volume", &KRecord::transCount, "成交量")
.def("__eq__", krecord_eq)
.def("__ne__", krecord_ne)
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<KRecord>())
#endif