diff --git a/app/models/stats/event.rb b/app/models/stats/event.rb index e2d77cb1f..9ad73a6a7 100644 --- a/app/models/stats/event.rb +++ b/app/models/stats/event.rb @@ -6,5 +6,7 @@ module Stats attribute :eventId, Integer attribute :eventDate, String + attribute :ageRange, String + attribute :eventTheme, String end end diff --git a/app/services/statistic_service.rb b/app/services/statistic_service.rb index cdd42a100..6f7b9e771 100644 --- a/app/services/statistic_service.rb +++ b/app/services/statistic_service.rb @@ -68,7 +68,9 @@ class StatisticService eventId: r.event_id, name: r.event_name, eventDate: r.event_date, - reservationId: r.reservation_id + reservationId: r.reservation_id, + eventTheme: r.event_theme, + ageRange: r.age_range }.merge(user_info_stat(r))) stat.stat = (type == 'booking' ? r.nb_places : r.nb_hours) stat.save @@ -201,6 +203,8 @@ class StatisticService event_type: r.reservable.categories.first.name, event_name: r.reservable.name, event_date: slot.start_at.to_date, + event_theme: (r.reservable.event_themes.first ? r.reservable.event_themes.first.name : ''), + age_range: (r.reservable.age_range_id ? r.reservable.age_range.name : ''), nb_places: r.nb_reserve_places + r.nb_reserve_reduced_places, nb_hours: difference_in_hours(slot.start_at, slot.end_at), ca: calcul_ca(r.invoice) diff --git a/config/locales/en.yml b/config/locales/en.yml index a28ace25a..c679aa256 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -244,6 +244,8 @@ en: event_id: "Event ID" event_date: "Event Date" event_name: "Event Name" + event_theme: "Theme" + age_range: "Age Range" themes: "Themes" components: "Components" machines: "Machines" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 03a2c8822..6ed88231b 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -244,6 +244,8 @@ fr: event_id: "ID Évènement" event_date: "Date Évènement" event_name: "Nom Évènement" + event_theme: "Thématique" + age_range: "Tranche d'âge" themes: "Thèmes" components: "Composants" machines: "Machines" diff --git a/db/migrate/20160630100137_add_event_theme_and_age_range_to_statistic_field.rb b/db/migrate/20160630100137_add_event_theme_and_age_range_to_statistic_field.rb new file mode 100644 index 000000000..79495cfdb --- /dev/null +++ b/db/migrate/20160630100137_add_event_theme_and_age_range_to_statistic_field.rb @@ -0,0 +1,6 @@ +class AddEventThemeAndAgeRangeToStatisticField < ActiveRecord::Migration + def change + StatisticField.create!({key:'eventTheme', label:I18n.t('statistics.event_theme'), statistic_index_id: 4, data_type: 'text'}) + StatisticField.create!({key:'ageRange', label:I18n.t('statistics.age_range'), statistic_index_id: 4, data_type: 'text'}) + end +end diff --git a/db/schema.rb b/db/schema.rb index 4a3f17e06..b1a1ff5a6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160630083759) do +ActiveRecord::Schema.define(version: 20160630100137) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" diff --git a/db/seeds.rb b/db/seeds.rb index e52806b80..b702f6865 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -27,7 +27,9 @@ if StatisticField.count == 0 {key:'components', label:I18n.t('statistics.components'), statistic_index_id: 6, data_type: 'list'}, {key:'machines', label:I18n.t('statistics.machines'), statistic_index_id: 6, data_type: 'list'}, {key:'name', label:I18n.t('statistics.event_name'), statistic_index_id: 4, data_type: 'text'}, - {key:'userId', label:I18n.t('statistics.user_id'), statistic_index_id: 7, data_type: 'index'} + {key:'userId', label:I18n.t('statistics.user_id'), statistic_index_id: 7, data_type: 'index'}, + {key:'eventTheme', label:I18n.t('statistics.event_theme'), statistic_index_id: 4, data_type: 'text'}, + {key:'ageRange', label:I18n.t('statistics.age_range'), statistic_index_id: 4, data_type: 'text'} ]) end diff --git a/doc/elasticsearch.md b/doc/elasticsearch.md index e15495713..32275f8be 100644 --- a/doc/elasticsearch.md +++ b/doc/elasticsearch.md @@ -408,6 +408,14 @@ http://localhost:9200/stats/_mapping?pretty }, "userId" : { "type" : "long" + }, + "ageRange" : { + "type" : "string", + "index" : "not_analyzed" + }, + "eventTheme" : { + "type" : "string", + "index" : "not_analyzed" } } } diff --git a/test/fixtures/statistic_fields.yml b/test/fixtures/statistic_fields.yml index 644d66006..76ac90c1a 100644 --- a/test/fixtures/statistic_fields.yml +++ b/test/fixtures/statistic_fields.yml @@ -88,3 +88,23 @@ statistic_field_10: created_at: 2016-04-04 14:11:33.423307000 Z updated_at: 2016-04-04 14:11:33.423307000 Z data_type: text + +statistic_field_11: + id: 11 + statistic_index_id: 4 + key: ageRange + label: Tranche d'âge + created_at: 2016-06-30 12:10:49.812226000 Z + updated_at: 2016-06-30 12:10:49.812226000 Z + data_type: text + + +statistic_field_12: + id: 12 + statistic_index_id: 4 + key: eventTheme + label: Thématique + created_at: 2016-06-30 12:10:49.814331000 Z + updated_at: 2016-06-30 12:10:49.814331000 Z + data_type: text +