Skip to content
Snippets Groups Projects
Commit bdfb098b authored by Lauri Himanen's avatar Lauri Himanen
Browse files

Added histogram data to the statistics route.

parent de12d1f7
Branches
Tags
2 merge requests!123V0.8.1,!121Encyclopedia api
Pipeline #75768 passed
...@@ -714,6 +714,7 @@ histogram = api.model("histogram", { ...@@ -714,6 +714,7 @@ histogram = api.model("histogram", {
statistics_query = api.model("statistics_query", { statistics_query = api.model("statistics_query", {
"calculations": fields.List(fields.String), "calculations": fields.List(fields.String),
"properties": fields.List(fields.String), "properties": fields.List(fields.String),
"n_histogram_bins": fields.Integer,
}) })
statistics = api.model("statistics", { statistics = api.model("statistics", {
"min": fields.Float, "min": fields.Float,
...@@ -799,13 +800,13 @@ class EncStatisticsResource(Resource): ...@@ -799,13 +800,13 @@ class EncStatisticsResource(Resource):
s = s.extra(**{ s = s.extra(**{
"size": 0, "size": 0,
}) })
n_buckets = 10 n_bins = data["n_histogram_bins"]
for prop in properties: for prop in properties:
stats = getattr(response.aggs, "{}_stats".format(prop)) stats = getattr(response.aggs, "{}_stats".format(prop))
interval = (stats.max - stats.min) / n_buckets interval = (stats.max * 1.001 - stats.min) / n_bins
if interval == 0: if interval == 0:
interval = 1 interval = 1
hist_agg = A("histogram", field=property_map[prop], interval=interval) hist_agg = A("histogram", field=property_map[prop], interval=interval, offset=stats.min, min_doc_count=0)
s.aggs.bucket("{}_hist".format(prop), hist_agg) s.aggs.bucket("{}_hist".format(prop), hist_agg)
response_hist = s.execute() response_hist = s.execute()
...@@ -820,7 +821,7 @@ class EncStatisticsResource(Resource): ...@@ -820,7 +821,7 @@ class EncStatisticsResource(Resource):
"min": stats.min, "min": stats.min,
"max": stats.max, "max": stats.max,
"avg": stats.avg, "avg": stats.avg,
"hist": { "histogram": {
"occurrences": occurrences, "occurrences": occurrences,
"values": values, "values": values,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment