eis/mix_cc/ihyper_db/read_data_stats.cc

36 lines
1.4 KiB
C++

#include "mix_cc/ihyper_db/read_data_stats.h"
#include "mix_cc/debug.h"
#include "mix_cc/ihyper_db/connection.h"
#include "mix_cc/type/mix_time.h"
mix_cc::fp::maybe<double> mix_cc::ihd::read_data_stats_maybe(
const std::string& tag_name, time_range_t time_range,
HD3_STATS_TYPE hd3_stats_type) {
auto_connect();
return fwd::apply(
read_tag_info_maybe(tag_name),
fwd::lift_maybe([=](HD3TagBasicInfo tag_info) -> maybe<double> {
auto tag_id = tag_info.nTagID;
HD3StRelatedParam stParam;
double q_value = 0.0;
auto time_region = convert_to_hd_tr(time_range);
stParam.pTimeRegions = &time_region;
stParam.nTimeRegionNum = 1;
stParam.fPercentGood = 0;
stParam.nStatsType = hd3_stats_type;
stParam.nSampleType = HD3_STATS_SAMPLE_TYPE_RAW;
strcpy(stParam.szFilterExpr, "");
auto ret_v = st3_tag_stats_calc(tag_id, &stParam, &q_value);
if (ret_v != RD_SUCCESS) {
DEBUG_PRINT_MIX_CC(
"query tag stats failure,tag_id :" + std::to_string(tag_id) +
" tag_name:" + tag_name + ", time range is [" +
mix_time_t(time_range.get_left()).to_formatted_time() + "," +
mix_time_t(time_range.get_right()).to_formatted_time() + ")");
return {};
}
return q_value;
}),
fwd::flatten_maybe());
}