#include <timeseries.h>
Public Member Functions | |
TYPE_DESCRIPTOR ((KEY(blockId, INDEXED), FIELD(used), FIELD(elements))) | |
Public Attributes | |
db_int8 | blockId |
db_int4 | used |
dbArray< T > | elements |
Time series block contaning array of elements. Grouping several elements in one block (record) reduce space overhead and increase processing speed.
Attention! This class is not serialized, so it is can be accessed only by one thread
You are defining your own time series class, for example:
class Stock { public: char const* name; TYPE_DESCRIPTOR((KEY(name, INDEXED))); };
class Quote { public: int4 tickerDate; real4 bid; int4 bidSize; real4 ask; int4 askSize;
time_t time() const { return tickerDate; } // this method should be defined
TYPE_DESCRIPTOR((FIELD(tickerDate), FIELD(bid), FIELD(bidSize), FIELD(ask), FIELD(askSize))); }; typedef dbTimeSeriesBlock<Quote> DailyBlock; REGISTER_TEMPLATE(DailyBlock); REGISTER(Stock);
Now you can work with time series objects in the followin way:
dbDatabase db; if (db.open("mydatabase.dbs")) { dbTimeSeriesProcessor<Quote> proc(db, MIN_ELEMENTS_IN_BLOCK,MAX_ELEMENTS_IN_BLOCK); Quote quote; // initialize quote Stock stock; stock.name = "AAD"; oid_t stockId = insert(stock).getOid(); proc.add(stockId, quote); // add new element in time series
Quote quoteBuf[MAX_QUOTES]; // select quotes for the specified interval int n = proc.getInterval(stockId, fromDate, tillDate, quoteBuf, MAX_QUOTES); for (int i = 0; i < n; i++) { printf("bid=d ask=%d\n", quoteBuf[i].bid, quoteBuf[i].ask); } }