1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

fix trainings, users, events graphs

This commit is contained in:
Sylvain 2016-11-21 11:45:48 +01:00
parent 6c9fdaaf83
commit 52ad1b2c13

View File

@ -15,13 +15,13 @@ class API::StatisticsController < API::ApiController
statistic_type = request.query_parameters.delete('stat-type') statistic_type = request.query_parameters.delete('stat-type')
start_date = request.query_parameters.delete('start-date') start_date = request.query_parameters.delete('start-date')
end_date = request.query_parameters.delete('end-date') end_date = request.query_parameters.delete('end-date')
puts start_date, end_date
# run main query in elasticSearch # run main query in elasticSearch
query = MultiJson.load(request.body.read) query = MultiJson.load(request.body.read)
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
# run additional custom aggregations, if any # run additional custom aggregations, if any
if statistic_type and start_date and end_date
stat_index = StatisticIndex.find_by_es_type_key("#{path}") stat_index = StatisticIndex.find_by_es_type_key("#{path}")
stat_type = StatisticType.where(statistic_index_id: stat_index.id, key: statistic_type).first stat_type = StatisticType.where(statistic_index_id: stat_index.id, key: statistic_type).first
client = Elasticsearch::Model.client client = Elasticsearch::Model.client
@ -29,6 +29,7 @@ class API::StatisticsController < API::ApiController
c_res = client.search index: custom.es_index, type:custom.es_type, body:sprintf(custom.query, {aggs_name: custom.field, start_date: start_date, end_date: end_date}) c_res = client.search index: custom.es_index, type:custom.es_type, body:sprintf(custom.query, {aggs_name: custom.field, start_date: start_date, end_date: end_date})
results['aggregations'][custom.field] = c_res['aggregations'][custom.field] results['aggregations'][custom.field] = c_res['aggregations'][custom.field]
end end
end
# return result # return result
render json: results render json: results