mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
subscriptions export with all rows
This commit is contained in:
parent
e8b1c99d2a
commit
b0f7c634ea
@ -18,7 +18,13 @@ class API::StatisticsController < API::ApiController
|
||||
def export_#{path}
|
||||
authorize :statistic, :#{path}?
|
||||
query = MultiJson.load(params[:body])
|
||||
@results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
||||
@results = Elasticsearch::Model.client.search({index: 'stats', type: '#{path}', scroll: '30s', body: query})
|
||||
scroll_id = @results['_scroll_id']
|
||||
while @results['hits']['hits'].size != @results['hits']['total']
|
||||
scroll_res = Elasticsearch::Model.client.scroll(scroll: '30s', scroll_id: scroll_id)
|
||||
@results['hits']['hits'].concat(scroll_res['hits']['hits'])
|
||||
scroll_id = scroll_res['_scroll_id']
|
||||
end
|
||||
render xlsx: 'export_#{path}.xlsx', filename: "#{path}.xlsx"
|
||||
end
|
||||
}
|
||||
@ -26,6 +32,7 @@ class API::StatisticsController < API::ApiController
|
||||
|
||||
def export_global
|
||||
# query all stats with range arguments
|
||||
Elasticsearch::Model.client.search
|
||||
render xls: []
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,13 @@
|
||||
wb = xlsx_package.workbook
|
||||
|
||||
price = wb.styles.add_style :format_code => ''
|
||||
|
||||
wb.add_worksheet(name: "Abonnements") do |sheet|
|
||||
@results[:hits][:hits].each do |hit|
|
||||
sheet.add_row [hit[:_source].date, hit[:_source].userId, hit[:_source].gender, hit[:_source].age, hit[:_source].planId, hit[:_source].groupName, hit[:_source].ca]
|
||||
sheet.add_row ['Entrées', @results['hits']['total']]
|
||||
sheet.add_row ["Chiffre d'affaires", @results['aggregations']['total_ca']['value']]
|
||||
sheet.add_row ['Âge moyen', @results['aggregations']['average_age']['value']]
|
||||
sheet.add_row ['Date', 'ID Utilisateur', 'Genre', 'Âge', 'Type', 'Groupe', "Chiffre d'affaire"]
|
||||
@results['hits']['hits'].each do |hit|
|
||||
sheet.add_row [hit['_source']['date'], hit['_source']['userId'], hit['_source']['gender'], hit['_source']['age'], hit['_source']['planId'], hit['_source']['groupName'], hit['_source']['ca']]
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user