From 2756502131b343fcc564764e17cf6d1bc9a25dc8 Mon Sep 17 00:00:00 2001 From: Du Peng Date: Thu, 4 May 2023 14:15:14 +0200 Subject: [PATCH] (bug) invalid duration for machine/spaces reservations in statistics, when using slots of not 1 hour --- CHANGELOG.md | 3 +++ app/helpers/excel_helper.rb | 2 +- app/models/concerns/stat_concern.rb | 2 +- app/services/statistics/concerns/helpers_concern.rb | 6 +++--- app/services/statistics/fetcher_service.rb | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f780dcd75..85da5d366 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog Fab-manager +- Fix a bug: invalid duration for machine/spaces reservations in statistics, when using slots of not 1 hour +- [TODO DEPLOY] `rails fablab:es:build_stats` THEN `rails fablab:maintenance:regenerate_statistics[2014,1]` + ## v6.0.5 2023 May 2 - Fix a bug: unable to show calendar for Firefox and Safari diff --git a/app/helpers/excel_helper.rb b/app/helpers/excel_helper.rb index 81653b6d2..de4622826 100644 --- a/app/helpers/excel_helper.rb +++ b/app/helpers/excel_helper.rb @@ -41,7 +41,7 @@ module ExcelHelper unless type.simple data.push hit['_source']['stat'] styles.push nil - types.push :string + types.push :float end [data, styles, types] diff --git a/app/models/concerns/stat_concern.rb b/app/models/concerns/stat_concern.rb index 1743af6e4..2b0549ba4 100644 --- a/app/models/concerns/stat_concern.rb +++ b/app/models/concerns/stat_concern.rb @@ -8,7 +8,7 @@ module StatConcern attribute :type, String attribute :subType, String attribute :date, String - attribute :stat, Integer + attribute :stat, Float attribute :userId, Integer attribute :gender, String attribute :age, Integer diff --git a/app/services/statistics/concerns/helpers_concern.rb b/app/services/statistics/concerns/helpers_concern.rb index d851a4eb2..6508fe4b1 100644 --- a/app/services/statistics/concerns/helpers_concern.rb +++ b/app/services/statistics/concerns/helpers_concern.rb @@ -39,11 +39,11 @@ module Statistics::Concerns::HelpersConcern def difference_in_hours(start_at, end_at) if start_at.to_date == end_at.to_date - ((end_at - start_at) / 3600.0).to_i + ((end_at - start_at) / 3600.0).to_f else end_at_to_start_date = end_at.change(year: start_at.year, month: start_at.month, day: start_at.day) - hours = ((end_at_to_start_date - start_at) / 60 / 60).to_i - hours = ((end_at.to_date - start_at.to_date).to_i + 1) * hours if end_at.to_date > start_at.to_date + hours = ((end_at_to_start_date - start_at) / 60 / 60).to_f + hours = ((end_at.to_date - start_at.to_date).to_f + 1) * hours if end_at.to_date > start_at.to_date hours end end diff --git a/app/services/statistics/fetcher_service.rb b/app/services/statistics/fetcher_service.rb index 42eb79817..ee130f4dd 100644 --- a/app/services/statistics/fetcher_service.rb +++ b/app/services/statistics/fetcher_service.rb @@ -57,7 +57,7 @@ class Statistics::FetcherService machine_type: r.reservable.friendly_id, machine_name: r.reservable.name, slot_dates: r.slots.map(&:start_at).map(&:to_date), - nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_i, + nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_f, ca: calcul_ca(r.original_invoice) }.merge(user_info(profile)) yield result end @@ -81,7 +81,7 @@ class Statistics::FetcherService space_name: r.reservable.name, space_type: r.reservable.slug, slot_dates: r.slots.map(&:start_at).map(&:to_date), - nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_i, + nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_f, ca: calcul_ca(r.original_invoice) }.merge(user_info(profile)) yield result end