mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
hist: json_pack() can handle NaN
This commit is contained in:
parent
bb773ac763
commit
2ab0b1d52a
1 changed files with 16 additions and 11 deletions
27
lib/hist.c
27
lib/hist.c
|
@ -120,12 +120,12 @@ void hist_reset(struct hist *h)
|
|||
|
||||
double hist_mean(struct hist *h)
|
||||
{
|
||||
return (h->total > 0) ? h->_m[0] : 0.0;
|
||||
return (h->total > 0) ? h->_m[0] : NAN;
|
||||
}
|
||||
|
||||
double hist_var(struct hist *h)
|
||||
{
|
||||
return (h->total > 1) ? h->_s[0] / (h->total - 1) : 0.0;
|
||||
return (h->total > 1) ? h->_s[0] / (h->total - 1) : NAN;
|
||||
}
|
||||
|
||||
double hist_stddev(struct hist *h)
|
||||
|
@ -208,18 +208,23 @@ json_t * hist_json(struct hist *h)
|
|||
{
|
||||
json_t *json_buckets, *json_hist;
|
||||
|
||||
json_hist = json_pack("{ s: f, s: f, s: i, s: i, s: i, s: f, s: f, s: f, s: f, s: f }",
|
||||
json_hist = json_pack("{ s: f, s: f, s: i }",
|
||||
"low", h->low,
|
||||
"high", h->high,
|
||||
"total", h->total,
|
||||
"higher", h->higher,
|
||||
"lower", h->lower,
|
||||
"highest", h->highest,
|
||||
"lowest", h->lowest,
|
||||
"mean", hist_mean(h),
|
||||
"variance", hist_var(h),
|
||||
"stddev", hist_stddev(h)
|
||||
"total", h->total
|
||||
);
|
||||
|
||||
if (h->total > 0) {
|
||||
json_object_update(json_hist, json_pack("{ s: i, s: i, s: f, s: f, s: f, s: f, s: f }",
|
||||
"higher", h->higher,
|
||||
"lower", h->lower,
|
||||
"highest", h->highest,
|
||||
"lowest", h->lowest,
|
||||
"mean", hist_mean(h),
|
||||
"variance", hist_var(h),
|
||||
"stddev", hist_stddev(h)
|
||||
));
|
||||
}
|
||||
|
||||
if (h->total - h->lower - h->higher > 0) {
|
||||
json_buckets = json_array();
|
||||
|
|
Loading…
Add table
Reference in a new issue