mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-21 15:54:22 +01:00
(wip) slot date in stats
This commit is contained in:
parent
001d024948
commit
71579e7465
@ -3,6 +3,7 @@
|
|||||||
- Updated shakapaker to 6.5.5
|
- Updated shakapaker to 6.5.5
|
||||||
- Fix a bug: unable to create a recurrent event
|
- Fix a bug: unable to create a recurrent event
|
||||||
- Fix a bug: unable to create a non-rolling plan
|
- Fix a bug: unable to create a non-rolling plan
|
||||||
|
- Fix a bug: invalid duration for machine/spaces reservations in statistics, when using slots of not 1 hour
|
||||||
- Fix a bug: invalid month in date format
|
- Fix a bug: invalid month in date format
|
||||||
- Fix a bug: do not show theme and age-range fields in event form if no options were set
|
- Fix a bug: do not show theme and age-range fields in event form if no options were set
|
||||||
- Fix a bug: do not show catgory select in plan form if no options were set
|
- Fix a bug: do not show catgory select in plan form if no options were set
|
||||||
|
@ -48,6 +48,7 @@ class API::TrainingsController < API::ApiController
|
|||||||
head :no_content
|
head :no_content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# This endpoint is used to get a list of trainings to validate
|
||||||
def availabilities
|
def availabilities
|
||||||
authorize Training
|
authorize Training
|
||||||
@training = Training.find(params[:id])
|
@training = Training.find(params[:id])
|
||||||
|
@ -647,7 +647,7 @@ Application.Controllers.controller('StatisticsController', ['$scope', '$state',
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return angular.forEach($scope.selectedIndex.additional_fields, function (field) {
|
angular.forEach($scope.selectedIndex.additional_fields, function (field) {
|
||||||
const filter = { key: field.key, label: field.label, values: [] };
|
const filter = { key: field.key, label: field.label, values: [] };
|
||||||
switch (field.data_type) {
|
switch (field.data_type) {
|
||||||
case 'index': filter.values.push('input_number'); break;
|
case 'index': filter.values.push('input_number'); break;
|
||||||
|
@ -7,4 +7,5 @@ class Stats::Machine
|
|||||||
include StatReservationConcern
|
include StatReservationConcern
|
||||||
|
|
||||||
attribute :machineId, Integer
|
attribute :machineId, Integer
|
||||||
|
attribute :machineDates, Array
|
||||||
end
|
end
|
||||||
|
@ -7,4 +7,5 @@ class Stats::Space
|
|||||||
include StatReservationConcern
|
include StatReservationConcern
|
||||||
|
|
||||||
attribute :spaceId, Integer
|
attribute :spaceId, Integer
|
||||||
|
attribute :spaceDates, Array
|
||||||
end
|
end
|
||||||
|
@ -30,6 +30,8 @@ class Statistics::Builders::ReservationsBuilderService
|
|||||||
|
|
||||||
def add_custom_attributes(category, stat, reservation_data)
|
def add_custom_attributes(category, stat, reservation_data)
|
||||||
stat = add_event_attributes(category, stat, reservation_data)
|
stat = add_event_attributes(category, stat, reservation_data)
|
||||||
|
stat = add_machine_attributes(category, stat, reservation_data)
|
||||||
|
stat = add_space_attributes(category, stat, reservation_data)
|
||||||
add_training_attributes(category, stat, reservation_data)
|
add_training_attributes(category, stat, reservation_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,5 +52,21 @@ class Statistics::Builders::ReservationsBuilderService
|
|||||||
|
|
||||||
stat
|
stat
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_machine_attributes(category, stat, reservation_data)
|
||||||
|
return stat unless category == 'machine'
|
||||||
|
|
||||||
|
stat[:machineDates] = reservation_data[:slot_dates]
|
||||||
|
|
||||||
|
stat
|
||||||
|
end
|
||||||
|
|
||||||
|
def add_space_attributes(category, stat, reservation_data)
|
||||||
|
return stat unless category == 'space'
|
||||||
|
|
||||||
|
stat[:spaceDates] = reservation_data[:slot_dates]
|
||||||
|
|
||||||
|
stat
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,7 @@ module Statistics::Concerns::HelpersConcern
|
|||||||
|
|
||||||
def difference_in_hours(start_at, end_at)
|
def difference_in_hours(start_at, end_at)
|
||||||
if start_at.to_date == end_at.to_date
|
if start_at.to_date == end_at.to_date
|
||||||
((end_at - start_at) / 60 / 60).to_i
|
((end_at - start_at) / 3600.0).to_i
|
||||||
else
|
else
|
||||||
end_at_to_start_date = end_at.change(year: start_at.year, month: start_at.month, day: start_at.day)
|
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_start_date - start_at) / 60 / 60).to_i
|
||||||
|
@ -54,7 +54,8 @@ class Statistics::FetcherService
|
|||||||
machine_id: r.reservable.id,
|
machine_id: r.reservable.id,
|
||||||
machine_type: r.reservable.friendly_id,
|
machine_type: r.reservable.friendly_id,
|
||||||
machine_name: r.reservable.name,
|
machine_name: r.reservable.name,
|
||||||
nb_hours: r.slots.size,
|
slot_dates: r.slots.map(&:start_at).map(&:to_date),
|
||||||
|
nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_i,
|
||||||
ca: calcul_ca(r.original_invoice) }.merge(user_info(profile)))
|
ca: calcul_ca(r.original_invoice) }.merge(user_info(profile)))
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
@ -75,7 +76,8 @@ class Statistics::FetcherService
|
|||||||
space_id: r.reservable.id,
|
space_id: r.reservable.id,
|
||||||
space_name: r.reservable.name,
|
space_name: r.reservable.name,
|
||||||
space_type: r.reservable.slug,
|
space_type: r.reservable.slug,
|
||||||
nb_hours: r.slots.size,
|
slot_dates: r.slots.map(&:start_at).map(&:to_date),
|
||||||
|
nb_hours: (r.slots.map(&:duration).map(&:to_i).reduce(:+) / 3600.0).to_i,
|
||||||
ca: calcul_ca(r.original_invoice) }.merge(user_info(profile)))
|
ca: calcul_ca(r.original_invoice) }.merge(user_info(profile)))
|
||||||
end
|
end
|
||||||
result
|
result
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
json.array!(@statistics) do |s|
|
json.array!(@statistics) do |s|
|
||||||
json.extract! s, :id, :es_type_key, :label, :table, :ca
|
json.extract! s, :id, :es_type_key, :label, :table, :ca
|
||||||
json.additional_fields s.statistic_fields do |f|
|
json.additional_fields s.statistic_fields do |f|
|
||||||
@ -12,8 +14,10 @@ json.array!(@statistics) do |s|
|
|||||||
json.extract! st, :id, :key, :label
|
json.extract! st, :id, :key, :label
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
json.graph do
|
if s.statistic_graph
|
||||||
json.chart_type s.statistic_graph.chart_type
|
json.graph do
|
||||||
json.limit s.statistic_graph.limit
|
json.chart_type s.statistic_graph.chart_type
|
||||||
end if s.statistic_graph
|
json.limit s.statistic_graph.limit
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -435,6 +435,8 @@ en:
|
|||||||
statistics:
|
statistics:
|
||||||
subscriptions: "Subscriptions"
|
subscriptions: "Subscriptions"
|
||||||
machines_hours: "Machines slots"
|
machines_hours: "Machines slots"
|
||||||
|
machine_dates: "Slots dates"
|
||||||
|
space_dates: "Slots dates"
|
||||||
spaces: "Spaces"
|
spaces: "Spaces"
|
||||||
orders: "Orders"
|
orders: "Orders"
|
||||||
trainings: "Trainings"
|
trainings: "Trainings"
|
||||||
|
@ -16,7 +16,7 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
test 'build stats' do
|
test 'build stats' do
|
||||||
# Create a reservation to generate an invoice (2 days ago)
|
# Create a reservation to generate an invoice (2 days ago)
|
||||||
machine = Machine.find(1)
|
machine = Machine.find(1)
|
||||||
slot = Availability.find(19).slots.first
|
machine_slot = Availability.find(19).slots.first
|
||||||
travel_to(2.days.ago)
|
travel_to(2.days.ago)
|
||||||
post '/api/local_payment/confirm_payment', params: {
|
post '/api/local_payment/confirm_payment', params: {
|
||||||
customer_id: @user.id,
|
customer_id: @user.id,
|
||||||
@ -27,7 +27,7 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
reservable_type: machine.class.name,
|
reservable_type: machine.class.name,
|
||||||
slots_reservations_attributes: [
|
slots_reservations_attributes: [
|
||||||
{
|
{
|
||||||
slot_id: slot.id
|
slot_id: machine_slot.id
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -72,8 +72,8 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
}.to_json, headers: default_headers
|
}.to_json, headers: default_headers
|
||||||
travel_back
|
travel_back
|
||||||
|
|
||||||
# Crate another machine reservation (today)
|
# Create another machine reservation (today)
|
||||||
slot = Availability.find(19).slots.last
|
machine_slot2 = Availability.find(19).slots.last
|
||||||
post '/api/local_payment/confirm_payment', params: {
|
post '/api/local_payment/confirm_payment', params: {
|
||||||
customer_id: @user.id,
|
customer_id: @user.id,
|
||||||
items: [
|
items: [
|
||||||
@ -83,7 +83,7 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
reservable_type: machine.class.name,
|
reservable_type: machine.class.name,
|
||||||
slots_reservations_attributes: [
|
slots_reservations_attributes: [
|
||||||
{
|
{
|
||||||
slot_id: slot.id
|
slot_id: machine_slot2.id
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -106,6 +106,7 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
{ term: { type: 'booking' } }] } }).first
|
{ term: { type: 'booking' } }] } }).first
|
||||||
assert_not_nil stat_booking
|
assert_not_nil stat_booking
|
||||||
assert_equal machine.friendly_id, stat_booking['subType']
|
assert_equal machine.friendly_id, stat_booking['subType']
|
||||||
|
assert_equal 1, stat_booking['stat']
|
||||||
check_statistics_on_user(stat_booking)
|
check_statistics_on_user(stat_booking)
|
||||||
|
|
||||||
stat_hour = Stats::Machine.search(query: { bool: { must: [{ term: { date: 2.days.ago.to_date.iso8601 } },
|
stat_hour = Stats::Machine.search(query: { bool: { must: [{ term: { date: 2.days.ago.to_date.iso8601 } },
|
||||||
@ -113,6 +114,8 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
|
|
||||||
assert_not_nil stat_hour
|
assert_not_nil stat_hour
|
||||||
assert_equal machine.friendly_id, stat_hour['subType']
|
assert_equal machine.friendly_id, stat_hour['subType']
|
||||||
|
assert_equal (machine_slot.duration.to_i / 3600.0).to_i, stat_hour['stat']
|
||||||
|
assert_includes stat_hour['machineDates'], machine_slot.start_at.to_date.iso8601
|
||||||
check_statistics_on_user(stat_hour)
|
check_statistics_on_user(stat_hour)
|
||||||
|
|
||||||
# second machine reservation (today)
|
# second machine reservation (today)
|
||||||
@ -120,6 +123,7 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
{ term: { type: 'booking' } }] } }).first
|
{ term: { type: 'booking' } }] } }).first
|
||||||
assert_not_nil stat_booking
|
assert_not_nil stat_booking
|
||||||
assert_equal machine.friendly_id, stat_booking['subType']
|
assert_equal machine.friendly_id, stat_booking['subType']
|
||||||
|
assert_equal 1, stat_booking['stat']
|
||||||
check_statistics_on_user(stat_booking)
|
check_statistics_on_user(stat_booking)
|
||||||
|
|
||||||
stat_hour = Stats::Machine.search(query: { bool: { must: [{ term: { date: DateTime.current.to_date.iso8601 } },
|
stat_hour = Stats::Machine.search(query: { bool: { must: [{ term: { date: DateTime.current.to_date.iso8601 } },
|
||||||
@ -127,6 +131,8 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
|
|
||||||
assert_not_nil stat_hour
|
assert_not_nil stat_hour
|
||||||
assert_equal machine.friendly_id, stat_hour['subType']
|
assert_equal machine.friendly_id, stat_hour['subType']
|
||||||
|
assert_equal (machine_slot2.duration.to_i / 3600.0).to_i, stat_hour['stat']
|
||||||
|
assert_includes stat_hour['machineDates'], machine_slot2.start_at.to_date.iso8601
|
||||||
check_statistics_on_user(stat_hour)
|
check_statistics_on_user(stat_hour)
|
||||||
|
|
||||||
# training
|
# training
|
||||||
@ -136,6 +142,7 @@ class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationT
|
|||||||
{ term: { type: 'booking' } }] } }).first
|
{ term: { type: 'booking' } }] } }).first
|
||||||
assert_not_nil stat_training
|
assert_not_nil stat_training
|
||||||
assert_equal training.friendly_id, stat_training['subType']
|
assert_equal training.friendly_id, stat_training['subType']
|
||||||
|
assert_equal tr_slot.start_at.to_date.iso8601, stat_training['trainingDate']
|
||||||
check_statistics_on_user(stat_training)
|
check_statistics_on_user(stat_training)
|
||||||
|
|
||||||
# subscription
|
# subscription
|
||||||
|
Loading…
x
Reference in New Issue
Block a user