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

add custom aggs for machine & trainings stats: available bookings

This commit is contained in:
Sylvain 2016-09-06 17:17:15 +02:00
parent 9d599a14e5
commit c2533c0590
6 changed files with 35 additions and 3 deletions

View File

@ -359,7 +359,6 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
##
# Run the elasticSearch query to retreive the /stats/type aggregations
# @param index {String} elasticSearch document type (account|event|machine|project|subscription|training)

View File

@ -235,7 +235,7 @@
<li ng-show="selectedIndex.ca">{{ 'revenue_' | translate }} {{sumCA | currency}}</li>
<li>{{ 'average_age' | translate }} {{averageAge}} {{ 'years_old' | translate }}</li>
<li ng-if="!type.active.simple">{{ 'total' | translate }} {{type.active.label}} : {{sumStat}}</li>
<li ng-repeat="custom in type.active.custom_aggregations">{{ custom.field | translate }} : {{customAggs[custom.field]}}</li>
<li ng-repeat="custom in type.active.custom_aggregations">{{ custom.field | translate }} {{customAggs[custom.field]}}</li>
</ul>
</div>

View File

@ -445,6 +445,8 @@ en:
average_age: "Average age:"
years_old: "Years old"
total: "Total"
available_hours: "Hours available for booking:"
available_tickets: "Tickets available for booking:"
gender: "Gender"
age: "Age"
revenue: "Revenue"

View File

@ -445,6 +445,8 @@ fr:
average_age: "Âge moyen :"
years_old: "ans"
total: "Total"
available_hours: "Heures disponibles à la réservation :"
available_tickets: "Places disponibles à la reservation :"
gender: "Genre"
age: "Âge"
revenue: "Chiffre d'affaires"

View File

@ -0,0 +1,29 @@
class InsertCustomAggregations < ActiveRecord::Migration
def change
# available reservations hours for machines
machine = StatisticIndex.find_by_es_type_key('machine')
machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: machine.id)
available_hours = StatisticCustomAggregation.new({
statistic_type_id: machine_hours.id,
es_index: 'fablab',
es_type: 'availabilities',
field: 'available_hours',
query: '{"size":0, "aggregations":{"%{aggs_name}":{"sum":{"field":"hours_duration"}}}, "query":{"bool":{"must":[{"range":{"start_at":{"gte":"%{start_date}", "lte":"%{end_date}"}}}, {"match":{"available_type":"machines"}}]}}}'
})
available_hours.save!
# available training tickets
training = StatisticIndex.find_by_es_type_key('training')
training_bookings = StatisticType.find_by(key: 'booking', statistic_index_id: training.id)
available_tickets = StatisticCustomAggregation.new({
statistic_type_id: training_bookings.id,
es_index: 'fablab',
es_type: 'availabilities',
field: 'available_tickets',
query: '{"size":0, "aggregations":{"%{aggs_name}":{"sum":{"field":"nb_total_places"}}}, "query":{"bool":{"must":[{"range":{"start_at":{"gte":"%{start_date}", "lte":"%{end_date}"}}}, {"match":{"available_type":"training"}}]}}}'
})
available_tickets.save!
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160906094847) do
ActiveRecord::Schema.define(version: 20160906145713) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"