1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +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,19 +15,20 @@ 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
stat_index = StatisticIndex.find_by_es_type_key("#{path}") if statistic_type and start_date and end_date
stat_type = StatisticType.where(statistic_index_id: stat_index.id, key: statistic_type).first stat_index = StatisticIndex.find_by_es_type_key("#{path}")
client = Elasticsearch::Model.client stat_type = StatisticType.where(statistic_index_id: stat_index.id, key: statistic_type).first
stat_type.statistic_custom_aggregations.each do |custom| client = Elasticsearch::Model.client
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}) stat_type.statistic_custom_aggregations.each do |custom|
results['aggregations'][custom.field] = c_res['aggregations'][custom.field] 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]
end
end end
# return result # return result