display optimization for float and double types when setting bias

This commit is contained in:
xiang.zhou
2024-06-13 13:59:47 +08:00
parent a872ad3460
commit 682b499279
6 changed files with 20 additions and 5 deletions
+1
View File
@@ -68,6 +68,7 @@ typedef struct neu_json_elem {
enum neu_json_type t;
union neu_json_value v;
uint8_t precision;
double bias;
} neu_json_elem_t;
#define NEU_JSON_ELEM_SIZE(elems) sizeof(elems) / sizeof(neu_json_elem_t)
+1
View File
@@ -53,6 +53,7 @@ typedef struct {
uint8_t precision;
int n_meta;
neu_json_tag_meta_t *metas;
neu_datatag_t datatag;
} neu_json_read_resp_tag_t;
typedef struct {
+3
View File
@@ -670,6 +670,7 @@ typedef struct neu_resp_tag_value_meta {
char tag[NEU_TAG_NAME_LEN];
neu_dvalue_t value;
neu_tag_meta_t metas[NEU_TAG_META_SIZE];
neu_datatag_t datatag;
} neu_resp_tag_value_meta_t;
static inline UT_icd *neu_resp_tag_value_meta_icd()
@@ -872,6 +873,8 @@ static inline void neu_tag_value_to_json(neu_resp_tag_value_meta_t *tag_value,
}
neu_json_metas_to_json(tag_value->metas, NEU_TAG_META_SIZE, tag_json);
tag_json->datatag.bias = tag_value->datatag.bias;
switch (tag_value->value.type) {
case NEU_TYPE_ERROR:
tag_json->t = NEU_JSON_INT;
+10 -3
View File
@@ -2119,6 +2119,8 @@ static void read_report_group(int64_t timestamp, int64_t timeout,
}
strcpy(tag_value.tag, tag->name);
tag_value.datatag.bias = tag->bias;
if (value.value.type == NEU_TYPE_ERROR) {
tag_value.value = value.value;
@@ -2255,7 +2257,8 @@ static void read_report_group(int64_t timestamp, int64_t timeout,
break;
}
}
if (tag->precision == 0 && tag->type == NEU_TYPE_DOUBLE) {
if (tag->precision == 0 && tag->bias == 0 &&
tag->type == NEU_TYPE_DOUBLE) {
format_tag_value(&tag_value.value);
}
}
@@ -2276,6 +2279,8 @@ static void read_group(int64_t timestamp, int64_t timeout,
strcpy(tag_value.tag, tag->name);
tag_value.datatag.bias = tag->bias;
if (neu_driver_cache_meta_get(cache, group, tag->name, &value,
tag_value.metas,
NEU_TAG_META_SIZE) != 0) {
@@ -2416,7 +2421,8 @@ static void read_group(int64_t timestamp, int64_t timeout,
}
}
if (tag->precision == 0 && tag->type == NEU_TYPE_DOUBLE) {
if (tag->precision == 0 && tag->bias == 0 &&
tag->type == NEU_TYPE_DOUBLE) {
format_tag_value(&tag_value.value);
}
}
@@ -2587,7 +2593,8 @@ static void read_group_paginate(int64_t timestamp, int64_t timeout,
}
}
if (tag->precision == 0 && tag->type == NEU_TYPE_DOUBLE) {
if (tag->precision == 0 && tag->bias == 0 &&
tag->type == NEU_TYPE_DOUBLE) {
format_tag_value(&tag_value.value);
}
}
+3
View File
@@ -59,6 +59,7 @@ int neu_json_encode_read_resp(void *json_object, void *param)
tag_elems[1].t = p_tag->t;
tag_elems[1].v = p_tag->value;
tag_elems[1].precision = p_tag->precision;
tag_elems[1].bias = p_tag->datatag.bias;
if (p_tag->t == NEU_JSON_FLOAT || p_tag->t == NEU_JSON_DOUBLE) {
if_precision = 1;
@@ -145,6 +146,7 @@ int neu_json_encode_read_paginate_resp(void *json_object, void *param)
tag_elems[8].t = p_tag->t;
tag_elems[8].v = p_tag->value;
tag_elems[8].precision = p_tag->precision;
tag_elems[8].bias = p_tag->datatag.bias;
if (p_tag->t == NEU_JSON_FLOAT || p_tag->t == NEU_JSON_DOUBLE) {
if_precision = 1;
@@ -235,6 +237,7 @@ int neu_json_encode_read_resp1(void *json_object, void *param)
tag_elem.t = p_tag->t;
tag_elem.v = p_tag->value;
tag_elem.precision = p_tag->precision;
tag_elem.bias = p_tag->datatag.bias;
neu_json_encode_field(values, &tag_elem, 1);
} else {
tag_elem.name = p_tag->name;
+2 -2
View File
@@ -83,7 +83,7 @@ static json_t *encode_object_value(neu_json_elem_t *ele)
break;
case NEU_JSON_FLOAT: {
double t = ele->v.val_float;
if (ele->precision == 0) {
if (ele->precision == 0 && ele->bias == 0) {
t = format_tag_value(ele->v.val_float);
}
ob = json_realp(t, ele->precision);
@@ -115,7 +115,7 @@ static json_t *encode_object(json_t *object, neu_json_elem_t ele)
break;
case NEU_JSON_FLOAT: {
double t = ele.v.val_float;
if (ele.precision == 0) {
if (ele.precision == 0 && ele.bias == 0) {
t = format_tag_value(ele.v.val_float);
}
json_object_set_new(ob, ele.name, json_realp(t, ele.precision));