std::string SzbaseWrapper::get_data( const std::string& param , const std::string& from , const std::string& to , ValueType value_type , TimeType time_type , ProbeType pt ) const throw( szbase_init_error, szbase_error ) { std::ostringstream ss; TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) ); if( !tparam ) throw szbase_error( "Param " + param + ", does not exist." ); try { switch (time_type) { case TimeType::NANOSECOND: ::get_data<sz4::nanosecond_time_t>( base , tparam , from , to , value_type , pt.get_szarp_pt() , ss ); break; case TimeType::SECOND: ::get_data<sz4::second_time_t> ( base , tparam , from , to , value_type , pt.get_szarp_pt() , ss ); break; } } catch ( sz4::exception& e ) { throw szbase_error( "Cannot get data for param " + param + ": " + e.what() ); } return ss.str(); }
double SzbaseWrapper::get_avg( const std::string& param , time_t time , ProbeType type ) const throw( szbase_init_error, szbase_get_value_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) ); if( !tparam ) throw szbase_get_value_error( "Cannot get value from param " + param + ", param not found" ); sz4::weighted_sum<double, unsigned> sum; try { base->get_weighted_sum( tparam , unsigned( time ) , unsigned( next( time , type , 1 ) ) , type.get_szarp_pt() , sum ); } catch( sz4::exception& e ) { throw szbase_get_value_error( "Cannot get value from param " + param + ": " + e.what() ); } return sz4::scale_value(sum.avg(), tparam); }
time_t SzbaseWrapper::get_latest( const std::string& param , ProbeType type ) const throw( szbase_init_error, szbase_get_value_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); bool ok; std::wstring error; /** * It looks like szbase has different aruments for "search all" in * case of 10sec and other probles */ time_t start = type == ProbeType( ProbeType::Type::LIVE ) ? -1 : std::numeric_limits<time_t>::max(); auto t = Szbase::GetObject()->Search( convert_string( base_name + ":" + param ) , start , time_t(-1) , -1 , type.get_szarp_pt() , ok , error ); if( !ok ) throw szbase_get_value_error("Cannot get latest time of param " + param + ": " + SC::S2A(error) ); /** * Round by hand because Szbase::Search returns probes rounded to * either 10min or 10sec, not to exact pt */ return round( t , type ); }
double SzbaseWrapper::get_avg_no_sync( const std::string& param , time_t time , ProbeType type ) const throw( szbase_init_error, szbase_get_value_error ) { if( !SzbaseWrapper::is_initialized() ) throw szbase_init_error("Szbase not initialized"); bool is_fixed, ok; std::wstring error; double val = Szbase::GetObject()->GetValue( convert_string( base_name + ":" + param ) , time , type.get_szarp_pt() , type.get_len() , &is_fixed , ok , error ); if( !ok ) throw szbase_get_value_error("Cannot get value from param " + param + ": " + SC::S2A(error) ); return val; }
time_t SzbaseWrapper::round( time_t t , ProbeType pt ) { return szb_round_time( t , pt.get_szarp_pt() , pt.get_len() ); }
time_t SzbaseWrapper::next( time_t t , ProbeType pt , int num ) { return szb_move_time( t , num , pt.get_szarp_pt() , pt.get_len() ); }