1#ifndef HAVE_TOM_TSDB_TIME_SERIES_HPP
2#define HAVE_TOM_TSDB_TIME_SERIES_HPP
4#include <tom-util/time_series.hpp>
5#include <tom-tsdb/types.hpp>
14 class native_calendar_type;
26 factory(
unsigned short int v )
28 if ( ( v >= 1 && v <= 4 ) ||
84 value()
const {
return m_value; }
116 if ( rhs.value() == m_value )
127 return ! ( *
this == rhs );
133 unsigned short int m_value;
141 public std::set<tom::string, std::less<tom::string> >
146 std::less<tom::string>
149 typedef parent_type::iterator iterator;
150 typedef parent_type::const_iterator const_iterator;
161 template <
typename IteratorT>
163 parent_type(
begin,
end ), m_changed(false) { }
169 parent_type(rhs), m_changed( rhs.m_changed ) { }
179 m_changed = rhs.m_changed;
189 if ( size() > 0 && size() == rhs.size() )
193 else if ( size() != rhs.size() )
205 return ! ( *
this == rhs );
220 begin()
const {
return this->parent_type::begin(); }
227 end()
const {
return this->parent_type::end(); }
287 clear( ) { m_changed =
true; this->parent_type::clear(); }
318 typedef std::map< tom::string, tom::string > attribute_map_t;
319 typedef std::set< tom::string > attribute_set_t;
331 tom::calendars::date_int_type from,
332 tom::calendars::date_int_type to
337 friend class ::tom::tsdb::datastore;
372 virtual void save(
bool overwrite =
false );
384 virtual const alias_set &get_alias_set()
const;
395 get_raw_data()
const = 0;
402 const tom::calendars::date_time &
410 const tom::calendars::date_time &
433 alias_set_touched()
const;
440 get_dropped_aliases(
alias_set &dropped )
const;
447 get_added_aliases(
alias_set &added )
const;
458 {
return get_attribute(
tom::String( att_name ), check_datastore ); }
469 {
return get_attribute(
tom::String( att_name ) ); }
479 get_attribute(
const tom::String &att_name,
bool check_datastore =
true )
const;
491 const char *att_value )
533 tom::calendars::date_int_type
542 tom::calendars::date_int_type
553 const attribute_set_t &
554 get_changed_attribute_names()
const {
return m_changed_attributes; }
558 populate_alias_set()
const;
562 set_create_date_time(
const tom::calendars::date_time &) = 0;
566 set_modify_date_time(
const tom::calendars::date_time &) = 0;
570 mutable bool m_alias_set_touched;
573 mutable attribute_map_t m_attributes;
574 attribute_set_t m_changed_attributes;
576 namespace collections {
578 template <
typename T,
typename NATIVE_TYPE>
582 typedef typename T::value_type value_type;
589 const tom::calendars::date_time &modified );
591 template <
typename IteratorT>
594 const tom::calendars::date_time &modified,
595 tom::calendars::date_int_type start,
596 IteratorT begin, IteratorT end );
605 const tom::calendars::date_time &modified,
606 tom::calendars::date_int_type start,
607 tom::calendars::date_int_type end,
608 populate_data_func );
611 virtual const values::data_type &
get_data_type()
const {
return NATIVE_TYPE::Instance(); }
625 virtual const tom::observation &get_observation(
const tom::calendars::date_int_type d )
const;
627 virtual void set_observation(
const tom::calendars::date_int_type d,
const tom::observation & val );
629 virtual void set_observation( tom::calendars::date_int_type d,
const tom::Date & );
631 virtual const tom::observation & operator[ ](
const tom::calendars::date_int_type d )
const;
632 virtual tom::observation & operator[ ](
const tom::calendars::date_int_type d );
635 virtual tom::calendars::date_int_type get_first_date_int()
const;
636 virtual tom::calendars::date_int_type get_last_date_int()
const;
639 tom::calendars::date_int_type
640 get_first_dirty_date_int()
const;
643 tom::calendars::date_int_type
644 get_last_dirty_date_int()
const;
647 virtual std::ostream &print( std::ostream & )
const;
651 const tom::calendars::date_time &
655 const tom::calendars::date_time &
667 if ( m_populate_data_func != NULL )
668 get_observation( get_last_date_int() );
669 return m_data.data();
675 set_create_date_time(
const tom::calendars::date_time &d)
677 m_create_date_time = d;
681 set_modify_date_time(
const tom::calendars::date_time &d)
683 m_modify_date_time = d;
686 aggregation_type m_agg_type;
689 tom::calendars::date_time m_create_date_time;
690 tom::calendars::date_time m_modify_date_time;
696 tom::calendars::date_int_type m_l_first_date_int;
697 tom::calendars::date_int_type m_l_last_date_int;
698 tom::calendars::date_int_type m_first_dirty_date_int;
699 tom::calendars::date_int_type m_last_dirty_date_int;
701 mutable populate_data_func m_populate_data_func;
705 template <
typename T,
typename NATIVE_TYPE>
707 const observation &name, aggregation_type agg_t ) :
708 m_agg_type(agg_t), m_ds(ds), m_name( String( name ).value() ), m_data(cal),
709 m_l_first_date_int( 0 ), m_l_last_date_int(0),
710 m_first_dirty_date_int( 0 ), m_last_dirty_date_int( 0 ),
711 m_populate_data_func(0)
715 template <
typename T,
typename NATIVE_TYPE>
717 const observation &name, aggregation_type agg_t,
718 const tom::calendars::date_time &created,
719 const tom::calendars::date_time &modified ) :
720 m_agg_type(agg_t), m_ds(ds), m_name( String( name ).value() ),
721 m_create_date_time( created ), m_modify_date_time( modified ), m_data(cal),
722 m_l_first_date_int( 0 ), m_l_last_date_int(0),
723 m_first_dirty_date_int( 0 ), m_last_dirty_date_int( 0 ),
724 m_populate_data_func(0)
728 template <
typename T,
typename NATIVE_TYPE>
729 template <
typename IteratorT>
731 aggregation_type agg_t,
732 const tom::calendars::date_time &created,
733 const tom::calendars::date_time &modified,
734 tom::calendars::date_int_type start,
735 IteratorT begin, IteratorT end ) :
736 m_agg_type(agg_t), m_ds(ds), m_name( String(name).value() ), m_create_date_time( created ),
737 m_modify_date_time( modified ), m_data(cal,cal(start), begin,end),
738 m_l_first_date_int( 0 ), m_l_last_date_int(0),
739 m_first_dirty_date_int( 0 ), m_last_dirty_date_int( 0 ),
740 m_populate_data_func(0)
744 template <
typename T,
typename NATIVE_TYPE>
746 aggregation_type agg_t,
const tom::calendars::date_time &created,
747 const tom::calendars::date_time &modified,
748 tom::calendars::date_int_type start,
749 tom::calendars::date_int_type end,
750 populate_data_func callback ) :
751 m_agg_type(agg_t), m_ds(ds), m_name( String(name).value() ), m_create_date_time( created ),
752 m_modify_date_time( modified ), m_data(cal),
753 m_l_first_date_int( start ), m_l_last_date_int(end),
754 m_first_dirty_date_int( 0 ), m_last_dirty_date_int( 0 ),
755 m_populate_data_func( callback )
761 template <
typename T,
typename NATIVE_TYPE>
767 template <
typename T,
typename NATIVE_TYPE>
774 template <
typename T,
typename NATIVE_TYPE>
778 if ( m_populate_data_func != NULL )
781 if ( (m_ds.*m_populate_data_func)( m_data, m_name,
784 static_cast<tom::calendars::date_int_type
> (m_l_first_date_int),
785 static_cast<tom::calendars::date_int_type
>(m_l_last_date_int )) )
786 m_populate_data_func = NULL;
788 return m_data.get_observation( d );
791 template <
typename T,
typename NATIVE_TYPE>
795 return this->get_observation( get_calendar()( d ) );
798 template <
typename T,
typename NATIVE_TYPE>
800 time_series<T,NATIVE_TYPE>::set_observation(
const tom::calendars::date_int_type d,
const tom::observation & val )
802 if ( m_first_dirty_date_int != 0 && d < m_first_dirty_date_int )
803 m_first_dirty_date_int = d;
805 if ( d > m_last_dirty_date_int )
806 m_last_dirty_date_int = d;
808 m_data.set_observation( d, val );
810 template <
typename T,
typename NATIVE_TYPE>
812 time_series<T,NATIVE_TYPE>::set_observation( tom::calendars::date_int_type d,
const tom::Date &v )
814 if ( m_first_dirty_date_int != 0 && d < m_first_dirty_date_int )
815 m_first_dirty_date_int = d;
817 if ( d > m_last_dirty_date_int )
818 m_last_dirty_date_int = d;
820 m_data.set_observation( d, v );
822 template <
typename T,
typename NATIVE_TYPE>
826 set_observation( get_calendar()(d), v );
829 template <
typename T,
typename NATIVE_TYPE>
833 this->set_observation( get_calendar()( d ), val );
836 template <
typename T,
typename NATIVE_TYPE>
838 time_series<T,NATIVE_TYPE>::operator[ ](
const tom::calendars::date_int_type d )
const
840 return this->get_observation(d);
843 template <
typename T,
typename NATIVE_TYPE>
845 time_series<T,NATIVE_TYPE>::operator[ ](
const tom::calendars::date_int_type d )
847 return this->get_observation(d).clone();
850 template <
typename T,
typename NATIVE_TYPE>
854 return this->get_observation(d);
857 template <
typename T,
typename NATIVE_TYPE>
861 return this->get_observation(d).clone();
865 template <
typename T,
typename NATIVE_TYPE>
867 time_series<T,NATIVE_TYPE>::print( std::ostream &os )
const
870 if ( m_populate_data_func != NULL )
871 get_observation( get_last_date_int() );
873 return m_data.print( os );
876 template <
typename T,
typename NATIVE_TYPE>
878 time_series<T,NATIVE_TYPE>::get_calendar( )
const
879 {
return m_data.get_calendar(); }
882 template <
typename T,
typename NATIVE_TYPE>
883 tom::calendars::date_int_type
884 time_series<T,NATIVE_TYPE>::get_first_date_int()
const
886 tom::calendars::date_int_type fd = m_data.get_first_date_int();
888 if ( m_populate_data_func == NULL )
893 if ( m_l_first_date_int != 0 && fd != 0 )
894 return m_l_first_date_int < fd ? m_l_first_date_int : fd;
895 else if ( m_l_first_date_int != 0 )
896 return m_l_first_date_int;
903 template <
typename T,
typename NATIVE_TYPE>
904 tom::calendars::date_int_type
905 time_series<T,NATIVE_TYPE>::get_last_date_int()
const
907 tom::calendars::date_int_type ld = m_data.get_last_date_int();
908 if ( m_populate_data_func == NULL )
913 if ( m_l_last_date_int != 0 && m_l_last_date_int > ld )
914 return m_l_last_date_int;
921 template <
typename T,
typename NATIVE_TYPE>
922 tom::calendars::date_int_type
925 return m_first_dirty_date_int;
929 template <
typename T,
typename NATIVE_TYPE>
930 tom::calendars::date_int_type
933 return m_last_dirty_date_int;
937 template <
typename T,
typename NATIVE_TYPE>
941 return m_data.begin();
945 template <
typename T,
typename NATIVE_TYPE>
963 return ts.print( os );
Definition calendar.hpp:120
Definition calendar.hpp:47
Definition time_series.hpp:309
Definition time_series.hpp:157
Definition time_series.hpp:25
Definition observation.hpp:13
Definition time_series.hpp:22
static aggregation_type begin()
Definition time_series.hpp:41
bool operator==(const aggregation_type &rhs)
Definition time_series.hpp:114
static aggregation_type low()
Definition time_series.hpp:81
static aggregation_type end()
Definition time_series.hpp:49
static aggregation_type averaged()
Definition time_series.hpp:57
static aggregation_type summed()
Definition time_series.hpp:65
const char * name() const
Definition time_series.hpp:90
static aggregation_type high()
Definition time_series.hpp:73
bool operator!=(const aggregation_type &rhs)
Definition time_series.hpp:125
Definition time_series.hpp:142
void clear()
Definition time_series.hpp:287
bool add(const char *)
Definition time_series.cpp:11
alias_set()
Definition time_series.hpp:155
alias_set & operator=(const alias_set &rhs)
Definition time_series.hpp:175
alias_set(const alias_set &rhs)
Definition time_series.hpp:168
const_iterator end() const
Definition time_series.hpp:227
bool operator==(const alias_set &rhs)
Definition time_series.hpp:186
bool remove(const char *)
Definition time_series.cpp:32
bool changed() const
Definition time_series.cpp:52
const_iterator begin() const
Definition time_series.hpp:220
bool operator!=(const alias_set &rhs)
Definition time_series.hpp:203
alias_set(IteratorT begin, IteratorT end)
Definition time_series.hpp:162
Definition time_series.hpp:580
virtual datastore & get_datastore() const
Definition time_series.hpp:610
virtual const tom::string & get_name() const
Definition time_series.hpp:615
virtual aggregation_type get_aggregation_type() const
Definition time_series.hpp:763
virtual const tom::calendars::date_time & get_create_date_time() const
Definition time_series.hpp:652
virtual bool is_sparse_series() const
Definition time_series.hpp:660
virtual void set_aggregation_type(aggregation_type)
Definition time_series.hpp:769
virtual const tom::calendars::date_time & get_modify_date_time() const
Definition time_series.hpp:656
virtual tom::calendars::date_int_type get_last_dirty_date_int() const
Definition time_series.hpp:931
virtual tom::calendars::date_int_type get_first_dirty_date_int() const
Definition time_series.hpp:923
virtual const values::data_type & get_data_type() const
Definition time_series.hpp:611
Definition datastore.hpp:445
static native_data_type factory(unsigned short int t)
Definition types.hpp:57
Definition time_series.hpp:313
virtual void set_aggregation_type(aggregation_type)=0
virtual const tom::calendars::date_time & get_modify_date_time() const =0
virtual tom::tsdb::datastore & get_datastore() const =0
const tom::String & get_attribute(const tom::observation &att_name, bool check_datastore=true) const
Definition time_series.hpp:468
virtual const tom::string & get_name() const =0
virtual aggregation_type get_aggregation_type() const =0
virtual const values::data_type & get_data_type() const =0
virtual tom::calendars::date_int_type get_last_dirty_date_int() const =0
void set_attribute(const char *att_name, const char *att_value)
Definition time_series.hpp:490
virtual bool is_sparse_series() const =0
void set_attribute(const tom::observation &att_name, const tom::observation &att_value)
Definition time_series.hpp:503
const tom::String & get_attribute(const char *att_name, bool check_datastore=true) const
Definition time_series.hpp:457
virtual tom::calendars::date_int_type get_first_dirty_date_int() const =0
virtual const tom::calendars::date_time & get_create_date_time() const =0
Definition value_types.hpp:96