Exemple #1
0
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);
}
Exemple #2
0
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");

    TParam* tparam = IPKContainer::GetObject()->GetParam( convert_string( base_name + ":" + param ) );
    if( !tparam )
        throw szbase_get_value_error( "Cannot get latest time of param " + param + ", param not found" );

    unsigned t;
    try {
        base->get_last_time( tparam, t );
    } catch( sz4::exception& e) {
        throw szbase_get_value_error( "Cannot get latest time of param " + param + ": " + e.what() );
    }

    /**
     * Round by hand because search returns probes rounded to
     * either 10min or 10sec, not to exact pt
     */
    return t == unsigned( -1 ) ? -1 : round( t , type );
}
Exemple #3
0
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 );
}
Exemple #4
0
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;
}
Exemple #5
0
double SzbaseWrapper:: get_avg_no_sync(
			const std::string& param ,
			time_t start ,
			time_t end ) const
	throw( szbase_init_error, szbase_get_value_error )
{
	if( !SzbaseWrapper::is_initialized() )
		throw szbase_init_error("Szbase not initialized");

	int len = end - start;

	bool is_fixed, ok;
	std::wstring error;
	double val = Szbase::GetObject()->GetValue(
			convert_string( base_name + ":" + param ) ,
			start , PT_CUSTOM , len ,
			&is_fixed , ok , error );

	if( !ok )
		throw szbase_get_value_error("Cannot get value from param " + param + ": " + SC::S2A(error) );

	return val;
}