16 #include <core/data/flexible_type/flexible_type.hpp> 17 #include <core/storage/sframe_data/group_aggregate_value.hpp> 18 #include <model_server/lib/toolkit_class_macros.hpp> 19 #include <core/data/sframe/gl_sarray.hpp> 20 #include <core/data/sframe/gl_sframe.hpp> 21 #include <model_server/lib/extensions/model_base.hpp> 22 #include <model_server/extensions/timeseries/grouped_timeseries.hpp> 23 #include <model_server/extensions/timeseries/interpolate_value.hpp> 27 namespace timeseries {
30 EXPORT gl_sarray date_range(
const flexible_type &start_time,
31 const flexible_type &end_time,
32 const flexible_type & period);
34 typedef std::shared_ptr<interpolator_value> interpolator_type;
35 class grouped_timeseries;
42 class EXPORT gl_timeseries :
public model_base {
44 virtual ~gl_timeseries();
47 static constexpr
size_t TIMESERIES_VERSION = 0;
49 bool m_initialized =
false;
51 void _check_if_initialized()
const {
53 throw std::string(
"Timeseries is not initialized.");
57 std::vector<std::string> m_value_col_names;
58 std::string m_index_col_name;
60 gl_sframe get_sframe()
const {
63 void set_sframe(gl_sframe sf) {
67 std::string get_index_col_name()
const {
68 return m_index_col_name;
72 return m_sframe[m_index_col_name].dtype();
75 void set_index_col_name(std::string index_col) {
76 m_index_col_name = index_col;
79 std::vector<std::string> get_value_col_names()
const {
80 return m_value_col_names;
82 void set_value_col_names(std::vector<std::string> val_names) {
83 m_value_col_names = val_names;
88 size_t get_version()
const {
89 return TIMESERIES_VERSION;
96 void save_impl(oarchive& oarc)
const;
102 void load_version(iarchive& iarc,
size_t version);
104 void init(
const gl_sframe & _input_sf,
const std::string & _name,
bool 105 is_sorted=
false,std::vector<int64_t> ranges={-1,-1});
121 gl_timeseries resample(
123 const std::map<std::string,
124 aggregate::groupby_descriptor_type>& operators,
125 interpolator_type interpolation_fn =
126 get_builtin_interpolator(
"__builtin__none__"),
127 const std::string& label =
"left",
128 const std::string& closed =
"right")
const;
144 gl_timeseries resample_wrapper(
148 const std::string& label,
149 const std::string& close)
const;
154 gl_timeseries tshift(
const flex_float & delta);
162 gl_timeseries shift(
const int64_t & steps);
164 gl_timeseries slice(
const flexible_type &start_time,
165 const flexible_type &end_time,
166 const std::string &closed)
const;
179 gl_timeseries index_join(
const gl_timeseries& other_ts,
const 180 std::string& how,
const std::string& index_column_name);
185 gl_timeseries ts_union(
const gl_timeseries& other_ts);
187 gl_grouped_timeseries
group(std::vector<std::string> key_columns);
188 void add_column(
const gl_sarray& data,
const std::string& name=
"");
189 void remove_column(
const std::string& name);
195 "end_time", "closed")
197 "_name", "is_sorted", "ranges")
199 "how", "index_column_name")
205 "downsample_params", "upsample_params", "left", "close")
#define BEGIN_CLASS_MEMBER_REGISTRATION(python_facing_classname)
#define REGISTER_CLASS_MEMBER_FUNCTION(function,...)
sframe group(sframe sframe_in, std::string key_column)
#define REGISTER_SETTER(propname, function)
#define END_CLASS_MEMBER_REGISTRATION
#define REGISTER_GETTER(propname, function)
std::vector< flexible_type > flex_list