2023-02-01 16:37:43 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require_relative '../../lib/database/sequence'
|
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
# statistic_indices
|
|
|
|
unless StatisticIndex.find_by(es_type_key: 'subscription')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 1, es_type_key: 'subscription', label_i18n_path: 'statistics.subscriptions' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticIndex.find_by(es_type_key: 'machine')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 2, es_type_key: 'machine', label_i18n_path: 'statistics.machines_hours' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticIndex.find_by(es_type_key: 'training')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 3, es_type_key: 'training', label_i18n_path: 'statistics.trainings' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 4, es_type_key: 'event', label_i18n_path: 'statistics.events' }) unless StatisticIndex.find_by(es_type_key: 'event')
|
2023-02-01 17:56:14 +01:00
|
|
|
unless StatisticIndex.find_by(es_type_key: 'account')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 5, es_type_key: 'account', label_i18n_path: 'statistics.registrations', ca: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticIndex.find_by(es_type_key: 'project')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 6, es_type_key: 'project', label_i18n_path: 'statistics.projects', ca: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticIndex.find_by(es_type_key: 'user')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ id: 7, es_type_key: 'user', label_i18n_path: 'statistics.users', table: false, ca: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-02-01 16:37:43 +01:00
|
|
|
Database::Sequence.update_id_seq(StatisticIndex.table_name)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticIndex.create!({ es_type_key: 'space', label_i18n_path: 'statistics.spaces' }) unless StatisticIndex.find_by(es_type_key: 'space')
|
|
|
|
StatisticIndex.create!({ es_type_key: 'order', label_i18n_path: 'statistics.orders' }) unless StatisticIndex.find_by(es_type_key: 'order')
|
2023-02-01 16:37:43 +01:00
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
statistic_index_space = StatisticIndex.find_by(es_type_key: 'space')
|
|
|
|
statistic_index_order = StatisticIndex.find_by(es_type_key: 'order')
|
2023-02-01 16:37:43 +01:00
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
# statistic_fields
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'spaceDates', statistic_index_id: statistic_index_space.id)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'spaceDates', label_i18n_path: 'statistics.space_dates',
|
2023-02-01 17:56:14 +01:00
|
|
|
statistic_index_id: statistic_index_space.id, data_type: 'list' })
|
2023-02-01 16:37:43 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: statistic_index_space.id)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: statistic_index_space.id, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'machineDates', statistic_index_id: 2)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'machineDates', label_i18n_path: 'statistics.machine_dates', statistic_index_id: 2, data_type: 'list' })
|
2023-02-01 16:37:43 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: 2)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 2, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'trainingId', statistic_index_id: 3)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'trainingId', label_i18n_path: 'statistics.training_id', statistic_index_id: 3, data_type: 'index' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'trainingDate', statistic_index_id: 3)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'trainingDate', label_i18n_path: 'statistics.training_date', statistic_index_id: 3, data_type: 'date' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: 3)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 3, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'eventId', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'eventId', label_i18n_path: 'statistics.event_id', statistic_index_id: 4, data_type: 'index' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'eventDate', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'eventDate', label_i18n_path: 'statistics.event_date', statistic_index_id: 4, data_type: 'date' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 4, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: 5)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 5, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'themes', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'themes', label_i18n_path: 'statistics.themes', statistic_index_id: 6, data_type: 'list' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'components', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'components', label_i18n_path: 'statistics.components', statistic_index_id: 6, data_type: 'list' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'machines', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'machines', label_i18n_path: 'statistics.machines', statistic_index_id: 6, data_type: 'list' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'status', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'status', label_i18n_path: 'statistics.project_status', statistic_index_id: 6, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'name', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'name', label_i18n_path: 'statistics.project_name', statistic_index_id: 6, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'projectUserNames', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'projectUserNames', label_i18n_path: 'statistics.project_user_names', statistic_index_id: 6, data_type: 'list' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
|
|
|
unless StatisticField.find_by(key: 'name', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'name', label_i18n_path: 'statistics.event_name', statistic_index_id: 4, data_type: 'text' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'userId', statistic_index_id: 7)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'userId', label_i18n_path: 'statistics.user_id', statistic_index_id: 7, data_type: 'index' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'eventTheme', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'eventTheme', label_i18n_path: 'statistics.event_theme', statistic_index_id: 4, data_type: 'text' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'ageRange', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'ageRange', label_i18n_path: 'statistics.age_range', statistic_index_id: 4, data_type: 'text' })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: 1)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: 1, data_type: 'text' })
|
2023-02-01 16:37:43 +01:00
|
|
|
end
|
2023-09-01 12:43:36 +02:00
|
|
|
unless StatisticField.find_by(key: 'groupName', statistic_index_id: statistic_index_order.id)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticField.create!({ key: 'groupName', label_i18n_path: 'statistics.group', statistic_index_id: statistic_index_order.id, data_type: 'text' })
|
2023-09-01 12:43:36 +02:00
|
|
|
end
|
2023-02-01 16:37:43 +01:00
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
# statistic_types
|
|
|
|
unless StatisticType.find_by(key: 'booking', statistic_index_id: 2)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 2, key: 'booking', label_i18n_path: 'statistics.bookings', graph: true, simple: true })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'hour', statistic_index_id: 2)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 2, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: true, simple: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'booking', statistic_index_id: 3)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 3, key: 'booking', label_i18n_path: 'statistics.bookings', graph: false, simple: true })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'hour', statistic_index_id: 3)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 3, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: false, simple: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'booking', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 4, key: 'booking', label_i18n_path: 'statistics.tickets_number', graph: false, simple: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'hour', statistic_index_id: 4)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 4, key: 'hour', label_i18n_path: 'statistics.hours_number', graph: false, simple: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'member', statistic_index_id: 5)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 5, key: 'member', label_i18n_path: 'statistics.users', graph: true, simple: true })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'project', statistic_index_id: 6)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 6, key: 'project', label_i18n_path: 'statistics.projects', graph: false, simple: true })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'revenue', statistic_index_id: 7)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: 7, key: 'revenue', label_i18n_path: 'statistics.revenue', graph: false, simple: false })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'booking', statistic_index_id: statistic_index_space.id)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: statistic_index_space.id, key: 'booking', label_i18n_path: 'statistics.bookings',
|
2023-02-01 17:56:14 +01:00
|
|
|
graph: true, simple: true })
|
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'hour', statistic_index_id: statistic_index_space.id)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: statistic_index_space.id, key: 'hour', label_i18n_path: 'statistics.hours_number',
|
2023-02-01 17:56:14 +01:00
|
|
|
graph: true, simple: false })
|
|
|
|
end
|
|
|
|
unless StatisticType.find_by(key: 'store', statistic_index_id: statistic_index_order.id)
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticType.create!({ statistic_index_id: statistic_index_order.id, key: 'store', label_i18n_path: 'statistics.store',
|
2023-02-01 17:56:14 +01:00
|
|
|
graph: true, simple: true })
|
|
|
|
end
|
|
|
|
Plan.find_each do |plan|
|
|
|
|
if plan.find_statistic_type.nil?
|
|
|
|
StatisticType.create!(
|
|
|
|
statistic_index_id: 1,
|
|
|
|
key: plan.duration.to_i,
|
|
|
|
label: "#{I18n.t('statistics.duration')} : #{plan.human_readable_duration}",
|
|
|
|
graph: true,
|
|
|
|
simple: true
|
|
|
|
)
|
|
|
|
end
|
2023-02-01 16:37:43 +01:00
|
|
|
end
|
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
# statistic_sub_types
|
|
|
|
unless StatisticSubType.find_by(key: 'created')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticSubType.create!({ key: 'created', label_i18n_path: 'statistics.account_creation',
|
2023-02-01 17:56:14 +01:00
|
|
|
statistic_types: StatisticIndex.find_by(es_type_key: 'account').statistic_types })
|
|
|
|
end
|
|
|
|
unless StatisticSubType.find_by(key: 'published')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticSubType.create!({ key: 'published', label_i18n_path: 'statistics.project_publication',
|
2023-02-01 17:56:14 +01:00
|
|
|
statistic_types: StatisticIndex.find_by(es_type_key: 'project').statistic_types })
|
|
|
|
end
|
|
|
|
unless StatisticSubType.find_by(key: 'paid-processed')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticSubType.create!({ key: 'paid-processed', label_i18n_path: 'statistics.paid-rocessed',
|
2023-02-01 17:56:14 +01:00
|
|
|
statistic_types: statistic_index_order.statistic_types })
|
|
|
|
end
|
|
|
|
unless StatisticSubType.find_by(key: 'aborted')
|
2023-11-03 12:56:13 +01:00
|
|
|
StatisticSubType.create!({ key: 'aborted', label_i18n_path: 'statistics.aborted', statistic_types: statistic_index_order.statistic_types })
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
Plan.find_each do |plan|
|
|
|
|
type = plan.find_statistic_type
|
2023-02-14 16:10:10 +01:00
|
|
|
subtype = StatisticSubType.create_with(label: plan.name).find_or_create_by(key: plan.slug)
|
|
|
|
StatisticTypeSubType.find_or_create_by(statistic_type: type, statistic_sub_type: subtype)
|
|
|
|
end
|
|
|
|
|
|
|
|
statistic_index_machine = StatisticIndex.find_by(es_type_key: 'machine')
|
|
|
|
Machine.find_each do |machine|
|
|
|
|
subtype = StatisticSubType.create_with(label: machine.name).find_or_create_by(key: machine.slug)
|
|
|
|
statistic_index_machine.statistic_types.find_each do |type|
|
|
|
|
StatisticTypeSubType.find_or_create_by(statistic_type: type, statistic_sub_type: subtype)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
statistic_index_training = StatisticIndex.find_by(es_type_key: 'training')
|
|
|
|
Training.find_each do |training|
|
|
|
|
subtype = StatisticSubType.create_with(label: training.name).find_or_create_by(key: training.slug)
|
|
|
|
statistic_index_training.statistic_types.find_each do |type|
|
|
|
|
StatisticTypeSubType.find_or_create_by(statistic_type: type, statistic_sub_type: subtype)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Space.find_each do |space|
|
|
|
|
subtype = StatisticSubType.create_with(label: space.name).find_or_create_by(key: space.slug)
|
|
|
|
statistic_index_space.statistic_types.find_each do |type|
|
|
|
|
StatisticTypeSubType.find_or_create_by(statistic_type: type, statistic_sub_type: subtype)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
statistic_index_user = StatisticIndex.find_by(es_type_key: 'user')
|
|
|
|
Group.find_each do |group|
|
|
|
|
subtype = StatisticSubType.create_with(label: group.name).find_or_create_by(key: group.slug)
|
|
|
|
statistic_index_user.statistic_types.find_each do |type|
|
|
|
|
StatisticTypeSubType.find_or_create_by(statistic_type: type, statistic_sub_type: subtype)
|
|
|
|
end
|
|
|
|
end
|
2023-02-01 17:56:14 +01:00
|
|
|
|
2023-02-14 16:10:10 +01:00
|
|
|
statistic_index_event = StatisticIndex.find_by(es_type_key: 'event')
|
|
|
|
Category.find_each do |category|
|
|
|
|
subtype = StatisticSubType.create_with(label: category.name).find_or_create_by(key: category.slug)
|
|
|
|
statistic_index_event.statistic_types.find_each do |type|
|
|
|
|
StatisticTypeSubType.find_or_create_by(statistic_type: type, statistic_sub_type: subtype)
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
2023-02-01 16:37:43 +01:00
|
|
|
end
|
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
# statistic_graphs
|
|
|
|
StatisticGraph.create!({ statistic_index_id: 1, chart_type: 'stackedAreaChart', limit: 0 }) unless StatisticGraph.find_by(statistic_index_id: 1)
|
|
|
|
StatisticGraph.create!({ statistic_index_id: 2, chart_type: 'stackedAreaChart', limit: 0 }) unless StatisticGraph.find_by(statistic_index_id: 2)
|
|
|
|
StatisticGraph.create!({ statistic_index_id: 3, chart_type: 'discreteBarChart', limit: 10 }) unless StatisticGraph.find_by(statistic_index_id: 3)
|
|
|
|
StatisticGraph.create!({ statistic_index_id: 4, chart_type: 'discreteBarChart', limit: 10 }) unless StatisticGraph.find_by(statistic_index_id: 4)
|
|
|
|
StatisticGraph.create!({ statistic_index_id: 5, chart_type: 'lineChart', limit: 0 }) unless StatisticGraph.find_by(statistic_index_id: 5)
|
|
|
|
StatisticGraph.create!({ statistic_index_id: 7, chart_type: 'discreteBarChart', limit: 10 }) unless StatisticGraph.find_by(statistic_index_id: 7)
|
|
|
|
|
|
|
|
# statistic_custom_aggregations
|
|
|
|
unless StatisticCustomAggregation.find_by(es_type: 'availabilities', field: 'available_hours')
|
2023-02-01 16:37:43 +01:00
|
|
|
# available reservations hours for machines
|
|
|
|
machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: 2)
|
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
StatisticCustomAggregation.create!(
|
2023-02-01 16:37:43 +01:00
|
|
|
statistic_type_id: machine_hours.id,
|
|
|
|
es_index: 'fablab',
|
|
|
|
es_type: 'availabilities',
|
|
|
|
field: 'available_hours',
|
|
|
|
query: '{"size":0, "aggregations":{"%<aggs_name>s":{"sum":{"field":"bookable_hours"}}}, "query":{"bool":{"must":[{"range":' \
|
|
|
|
'{"start_at":{"gte":"%<start_date>s", "lte":"%<end_date>s"}}}, {"match":{"available_type":"machines"}}]}}}'
|
|
|
|
)
|
2023-02-01 17:56:14 +01:00
|
|
|
end
|
|
|
|
unless StatisticCustomAggregation.find_by(es_type: 'availabilities', field: 'available_tickets')
|
2023-02-01 16:37:43 +01:00
|
|
|
# available training tickets
|
|
|
|
training_bookings = StatisticType.find_by(key: 'booking', statistic_index_id: 3)
|
|
|
|
|
2023-02-01 17:56:14 +01:00
|
|
|
StatisticCustomAggregation.create!(
|
2023-02-01 16:37:43 +01:00
|
|
|
statistic_type_id: training_bookings.id,
|
|
|
|
es_index: 'fablab',
|
|
|
|
es_type: 'availabilities',
|
|
|
|
field: 'available_tickets',
|
|
|
|
query: '{"size":0, "aggregations":{"%<aggs_name>s":{"sum":{"field":"nb_total_places"}}}, "query":{"bool":{"must":[{"range":' \
|
|
|
|
'{"start_at":{"gte":"%<start_date>s", "lte":"%<end_date>s"}}}, {"match":{"available_type":"training"}}]}}}'
|
|
|
|
)
|
|
|
|
end
|
2023-02-01 17:56:14 +01:00
|
|
|
unless StatisticCustomAggregation.find_by(es_type: 'order', field: 'average_cart')
|
|
|
|
# available training tickets
|
|
|
|
order_store = StatisticType.find_by(key: 'store', statistic_index_id: statistic_index_order.id)
|
2023-02-01 16:37:43 +01:00
|
|
|
# average cart price for orders
|
2023-02-01 17:56:14 +01:00
|
|
|
StatisticCustomAggregation.create!(
|
|
|
|
statistic_type_id: order_store.id,
|
2023-02-01 16:37:43 +01:00
|
|
|
es_index: 'stats',
|
|
|
|
es_type: 'order',
|
|
|
|
field: 'average_cart',
|
|
|
|
query: '{"size":0, "aggregations":{"%<aggs_name>s":{"avg":{"field":"ca", ' \
|
|
|
|
'"script":"BigDecimal.valueOf(_value).setScale(1, RoundingMode.HALF_UP)", "missing": 0}}}, ' \
|
|
|
|
'"query":{"bool":{"must":[{"range": {"date":{"gte":"%<start_date>s", "lte":"%<end_date>s"}}}]}}}'
|
|
|
|
)
|
|
|
|
end
|