TimeLine更名TimeLineList

This commit is contained in:
fasiondog 2019-02-11 16:33:55 +08:00
parent 047bbcb7b9
commit d3547889cb
18 changed files with 127 additions and 79 deletions

View File

@ -643,9 +643,9 @@ DatetimeList Stock::getDatetimeList(const KQuery& query) const {
}
TimeLine Stock::getTimeLine(const KQuery& query) const {
return isNull() ? TimeLine()
:m_kdataDriver->getTimeLine(market(), code(), query);
TimeLineList Stock::getTimeLineList(const KQuery& query) const {
return isNull() ? TimeLineList()
:m_kdataDriver->getTimeLineList(market(), code(), query);
}

View File

@ -156,7 +156,7 @@ public:
DatetimeList getDatetimeList(const KQuery& query) const;
/** 获取分时线 */
TimeLine getTimeLine(const KQuery& query) const;
TimeLineList getTimeLineList(const KQuery& query) const;
/** 设置权息信息 */
void setWeightList(const StockWeightList&);

View File

@ -21,8 +21,8 @@ HKU_API std::ostream & operator<<(std::ostream& os, const TimeLineRecord& record
return os;
}
HKU_API std::ostream& operator <<(std::ostream &os, const TimeLine& data) {
os << "TimeLine{\n size : " << data.size()
HKU_API std::ostream& operator <<(std::ostream &os, const TimeLineList& data) {
os << "TimeLineList{\n size : " << data.size()
<< "\n start: " << data.front().datetime
<< "\n last : " << data.back().datetime
<< "\n }";

View File

@ -32,11 +32,11 @@ public:
* 线
* @ingroup StockManage
*/
typedef vector<TimeLineRecord> TimeLine;
typedef vector<TimeLineRecord> TimeLineList;
/** @ingroup StockManage */
typedef shared_ptr<TimeLine> TimeLinePtr;
typedef shared_ptr<TimeLineList> TimeLineListPtr;
/**
@ -57,7 +57,7 @@ HKU_API std::ostream & operator<<(std::ostream &, const TimeLineRecord&);
* </pre>
* @ingroup StockManage
*/
HKU_API std::ostream& operator <<(std::ostream &os, const TimeLine&);
HKU_API std::ostream& operator <<(std::ostream &os, const TimeLineList&);
/**

View File

@ -25,10 +25,10 @@ public:
AUCTION = 2 /**< 集合竞价 */
};
Datetime datetime; //时间
price_t price; //成交均价
price_t vol; //成交量
DIRECT direct; //买卖盘性质1--sell 0--buy 2--集合竞价
Datetime datetime; //时间
price_t price; //成交均价
price_t vol; //成交量
DIRECT direct; //买卖盘性质1--sell 0--buy 2--集合竞价
TransRecord();
TransRecord(const Datetime& datetime, price_t price, price_t vol, DIRECT);

View File

@ -91,10 +91,11 @@ getKRecord(const string& market, const string& code,
return Null<KRecord>();
}
TimeLine KDataDriver::getTimeLine(const string& market, const string& code,
TimeLineList KDataDriver
::getTimeLineList(const string& market, const string& code,
const KQuery& query) {
HKU_INFO("This driver not support time-line!");
return TimeLine();
return TimeLineList();
}
} /* namespace hku */

View File

@ -91,7 +91,7 @@ public:
* @param query
* @return
*/
virtual TimeLine getTimeLine(const string& market, const string& code,
virtual TimeLineList getTimeLineList(const string& market, const string& code,
const KQuery& query);
private:

View File

@ -781,8 +781,8 @@ _getOtherIndexRangeByDate(const string& market, const string& code,
}
TimeLine H5KDataDriver::getTimeLine(const string& market, const string& code,
const KQuery& query) {
TimeLineList H5KDataDriver
::getTimeLineList(const string& market, const string& code, const KQuery& query) {
return query.queryType() == KQuery::INDEX
? _getTimeLine(market, code, query.start(), query.end())
: _getTimeLine(market, code,
@ -790,9 +790,10 @@ TimeLine H5KDataDriver::getTimeLine(const string& market, const string& code,
}
TimeLine H5KDataDriver::_getTimeLine(const string& market, const string& code,
TimeLineList H5KDataDriver
::_getTimeLine(const string& market, const string& code,
hku_int64 start_ix, hku_int64 end_ix) {
TimeLine result;
TimeLineList result;
H5FilePtr h5file;
H5::Group group;
if (!_getH5FileAndGroup(market, code, "TIME", h5file, group)) {
@ -859,10 +860,10 @@ TimeLine H5KDataDriver::_getTimeLine(const string& market, const string& code,
}
TimeLine H5KDataDriver
TimeLineList H5KDataDriver
::_getTimeLine(const string& market, const string& code,
const Datetime& start, const Datetime& end) {
TimeLine result;
TimeLineList result;
if (start >= end || start > Datetime::max()) {
return result;
}

View File

@ -28,7 +28,7 @@ public:
const KQuery& query, size_t& out_start, size_t& out_end);
virtual KRecord getKRecord(const string& market, const string& code,
size_t pos, KQuery::KType kType);
virtual TimeLine getTimeLine(const string& market, const string& code,
virtual TimeLineList getTimeLineList(const string& market, const string& code,
const KQuery& query);
private:
@ -57,9 +57,9 @@ private:
bool _getOtherIndexRangeByDate(const string&, const string&, const KQuery&,
size_t& out_start, size_t& out_end);
TimeLine _getTimeLine(const string& market, const string& code,
TimeLineList _getTimeLine(const string& market, const string& code,
hku_int64 start, hku_int64 end);
TimeLine _getTimeLine(const string& market, const string& code,
TimeLineList _getTimeLine(const string& market, const string& code,
const Datetime& start, const Datetime& end);

View File

@ -0,0 +1,45 @@
/*
* TimeLineRecord_serialization.h
*
* Created on: 2019-2-11
* Author: fasiondog
*/
#ifndef TRANSRECORD_SERIALIZATION_H_
#define TRANSRECORD_SERIALIZATION_H_
#include "../config.h"
#include "../TransRecord.h"
#if HKU_SUPPORT_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
namespace boost {
namespace serialization {
template<class Archive>
void save(Archive & ar, const hku::TransRecord& record, unsigned int version) {
hku::hku_uint64 datetime = record.datetime.number();
ar & BOOST_SERIALIZATION_NVP(datetime);
ar & make_nvp("price", record.price);
ar & make_nvp("vol", record.vol);
ar & make_nvp("direct", record.direct);
}
template<class Archive>
void load(Archive & ar, hku::TransRecord& record, unsigned int version) {
hku::hku_uint64 datetime;
ar & BOOST_SERIALIZATION_NVP(datetime);
record.datetime = hku::Datetime(datetime);
ar & make_nvp("price", record.price);
ar & make_nvp("vol", record.vol);
ar & make_nvp("direct", record.direct);
}
}} /* namespace boost::serailization */
BOOST_SERIALIZATION_SPLIT_FREE(hku::TransRecord)
#endif /* HKU_SUPPORT_SERIALIZATION */
#endif /* TRANSRECORD_SERIALIZATION_H_ */

View File

@ -13,6 +13,7 @@
#include "KQuery_serialization.h"
#include "KRecord_serialization.h"
#include "TimeLineRecord_serialization.h"
#include "TransRecord_serialization.h"
#include "MarketInfo_serialization.h"
#include "Stock_serialization.h"
#include "Block_serialization.h"

View File

@ -28,45 +28,45 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_index ) {
StockManager& sm = StockManager::instance();
Stock stock = sm["sz000001"];
KQuery query;
TimeLine result;
TimeLineList result;
/** @arg start == end > 0*/
query = KQuery(1, 1);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg start == end < 0*/
query = KQuery(-1, -1);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg start == end == 0*/
query = KQuery(-1, -1);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg start > end > 0*/
query = KQuery(1, 3);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201812030931), 10.57, 26962));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201812030932), 10.53, 15407));
/** @arg start < end < 0*/
query = KQuery(-3, -1);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg start < end == 0*/
query = KQuery(-3, 0);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg 未指定start, end*/
query = KQuery();
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 10320);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201812030930), 10.61, 83391));
BOOST_CHECK(result[6516] == TimeLineRecord(Datetime(201901111006), 10.18, 2823));
@ -74,14 +74,14 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_index ) {
/** @arg 未指定end*/
query = KQuery(-3);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
BOOST_CHECK(result[2] == TimeLineRecord(Datetime(201902011459), 11.20, 20572));
query = KQuery(10317);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
@ -89,7 +89,7 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_index ) {
/** @arg end 等于总数*/
query = KQuery(10317, 10320);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
@ -97,14 +97,14 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_index ) {
/** @arg end 比总数少1*/
query = KQuery(10317, 10319);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg end 大于总数*/
query = KQuery(10317, 10321);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
@ -112,30 +112,30 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_index ) {
/** @arg start 等于总数*/
query = KQuery(10320);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg start 比总数少1*/
query = KQuery(10319);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 1);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011459), 11.20, 20572));
/** @arg start 大于总数*/
query = KQuery(10321);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg start>0, end<0, 且两者有交集*/
query = KQuery(10317, -1);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg start<0, end>0, 且两者有交集*/
query = KQuery(-3, 10319);
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
@ -147,11 +147,11 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_date ) {
StockManager& sm = StockManager::instance();
Stock stock = sm["sz000001"];
KQuery query;
TimeLine result;
TimeLineList result;
/** @arg start 小于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201812030000));
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 10320);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201812030930), 10.61, 83391));
BOOST_CHECK(result[6516] == TimeLineRecord(Datetime(201901111006), 10.18, 2823));
@ -159,7 +159,7 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_date ) {
/** @arg start 等于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201812030930));
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 10320);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201812030930), 10.61, 83391));
BOOST_CHECK(result[6516] == TimeLineRecord(Datetime(201901111006), 10.18, 2823));
@ -167,7 +167,7 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_date ) {
/** @arg start大于数据起始日期未指定end*/
query = KQueryByDate(Datetime(201902011457));
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
@ -175,19 +175,19 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_query_by_date ) {
/** @arg start 等于 end*/
query = KQueryByDate(Datetime(201902011457), Datetime(201902011457));
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 0);
/** @arg start, end 都在数据范围内, 且end为最后一条记录日期 */
query = KQueryByDate(Datetime(201902011457), Datetime(201902011459));
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 2);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));
/** @arg start 在数据范围内, end大于最后一条记录日期 */
query = KQueryByDate(Datetime(201902011457), Datetime(201902020000));
result = stock.getTimeLine(query);
result = stock.getTimeLineList(query);
BOOST_CHECK(result.size() == 3);
BOOST_CHECK(result[0] == TimeLineRecord(Datetime(201902011457), 11.20, 46));
BOOST_CHECK(result[1] == TimeLineRecord(Datetime(201902011458), 11.20, 0));

View File

@ -59,7 +59,7 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_serialize ) {
string filename(StockManager::instance().tmpdir());
filename += "/TimeLine.xml";
TimeLine line1;
TimeLineList line1;
line1.push_back(TimeLineRecord(Datetime(201101010000), 10.0, 80));
line1.push_back(TimeLineRecord(Datetime(201101020000), 20.0, 90));
line1.push_back(TimeLineRecord(Datetime(201101030000), 20.0, 100));
@ -69,7 +69,7 @@ BOOST_AUTO_TEST_CASE( test_TimeLine_serialize ) {
oa << BOOST_SERIALIZATION_NVP(line1);
}
TimeLine line2;
TimeLineList line2;
{
std::ifstream ifs(filename);
boost::archive::xml_iarchive ia(ifs);

View File

@ -67,8 +67,8 @@ KData.__repr__ = reprFunc
TimeLineRecord.__unicode__ = unicodeFunc
TimeLineRecord.__repr__ = reprFunc
TimeLine.__unicode__ = unicodeFunc
TimeLine.__repr__ = reprFunc
TimeLineList.__unicode__ = unicodeFunc
TimeLineList.__repr__ = reprFunc
Stock.__unicode__ = unicodeFunc
Stock.__repr__ = reprFunc
@ -292,7 +292,7 @@ PriceList.__getitem__ = list_getitem
DatetimeList.__getitem__ = list_getitem
StringList.__getitem__ = list_getitem
BlockList.__getitem__ = list_getitem
TimeLine.__getitem__ = list_getitem
TimeLineList.__getitem__ = list_getitem
#------------------------------------------------------------------
@ -356,8 +356,8 @@ try:
"""转化为pandas的DataFrame"""
return pd.DataFrame.from_records(TimeLine_to_np(kdata), index='datetime')
TimeLine.to_np = TimeLine_to_np
TimeLine.to_df = TimeLine_to_df
TimeLineList.to_np = TimeLine_to_np
TimeLineList.to_df = TimeLine_to_df
except:
pass
@ -393,7 +393,7 @@ __all__ = [#类
'StockWeightList',
'StringList',
'TimeLineRecord',
'TimeLine',
'TimeLineList',
#变量
'constant',

View File

@ -733,8 +733,8 @@ TimeLineRecord.datetime.__doc__ = """时间"""
TimeLineRecord.price.__doc__ = """价格"""
TimeLineRecord.vol.__doc__ = """成交量"""
TimeLine.__doc__ = """
Stock.getTimeLine 线 TimeLineRecord list
TimeLineList.__doc__ = """
Stock.getTimeLineList 线 TimeLineRecord list
"""
@ -849,13 +849,13 @@ getDatetimeList(start, end, ktype)
:rtype: DatetimeList
"""
Stock.getTimeLine.__doc__ = """
getTimeLine(self, query)
Stock.getTimeLineList.__doc__ = """
getTimeLineList(self, query)
线
:param Query query: K线类型
:rtype: TimeLine
:rtype: TimeLineList
"""
Stock.getWeight.__doc__ = """

View File

@ -50,7 +50,7 @@ void export_Stock() {
.def("isNull", &Stock::isNull)
.def("isBuffer", &Stock::isBuffer)
.def("getKData", &Stock::getKData)
.def("getTimeLine", &Stock::getTimeLine)
.def("getTimeLineList", &Stock::getTimeLineList)
.def("getCount", &Stock::getCount, getCount_overloads())
.def("getMarketValue", &Stock::getMarketValue)
.def("getKRecord", &Stock::getKRecord, getRecord_overloads())

View File

@ -27,20 +27,20 @@ void export_TimeLineReord() {
#endif
;
TimeLine::const_reference (TimeLine::*TimeLine_at)(TimeLine::size_type) const = &TimeLine::at;
void (TimeLine::*append)(const TimeLineRecord&) = &TimeLine::push_back;
class_<TimeLine>("TimeLine")
TimeLineList::const_reference (TimeLineList::*TimeLine_at)(TimeLineList::size_type) const = &TimeLineList::at;
void (TimeLineList::*append)(const TimeLineRecord&) = &TimeLineList::push_back;
class_<TimeLineList>("TimeLineList")
.def(self_ns::str(self))
.def("__iter__", iterator<TimeLine>())
.def("size", &TimeLine::size)
.def("__len__", &TimeLine::size)
.def("__iter__", iterator<TimeLineList>())
.def("size", &TimeLineList::size)
.def("__len__", &TimeLineList::size)
.def("get", TimeLine_at, return_value_policy<copy_const_reference>())
.def("append", append)
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<TimeLine>())
.def_pickle(normal_pickle_suite<TimeLineList>())
#endif
;
register_ptr_to_python<TimeLinePtr>();
register_ptr_to_python<TimeLineListPtr>();
}

View File

@ -134,18 +134,18 @@ public:
return this->KDataDriver::getKRecord(market, code, pos, ktype);
}
TimeLine getTimeLine(const string& market, const string& code,
TimeLineList getTimeLineList(const string& market, const string& code,
const KQuery& query) {
if (override call = get_override("getTimeLine")) {
if (override call = get_override("getTimeLineList")) {
return call(market, code, query);
} else {
return KDataDriver::getTimeLine(market, code, query);
return KDataDriver::getTimeLineList(market, code, query);
}
}
TimeLine default_getTimeLine(const string& market, const string& code,
TimeLineList default_getTimeLineList(const string& market, const string& code,
const KQuery& query) {
return this->KDataDriver::getTimeLine(market, code, query);
return this->KDataDriver::getTimeLineList(market, code, query);
}
};
@ -171,8 +171,8 @@ void export_KDataDriver() {
&KDataDriverWrap::_getIndexRangeByDate,
&KDataDriverWrap::default_getIndexRangeByDate)
.def("getTimeLine",
&KDataDriverWrap::getTimeLine,
&KDataDriverWrap::default_getTimeLine)
&KDataDriverWrap::getTimeLineList,
&KDataDriverWrap::default_getTimeLineList)
;
register_ptr_to_python<KDataDriverPtr>();