mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-30 19:52:20 +01:00
(feat) build stats in elasticsearch
This commit is contained in:
parent
afc0685585
commit
70f7ef8951
@ -11,6 +11,7 @@ class Statistics::BuilderService
|
|||||||
Statistics::Builders::ReservationsBuilderService.build(options)
|
Statistics::Builders::ReservationsBuilderService.build(options)
|
||||||
Statistics::Builders::MembersBuilderService.build(options)
|
Statistics::Builders::MembersBuilderService.build(options)
|
||||||
Statistics::Builders::ProjectsBuilderService.build(options)
|
Statistics::Builders::ProjectsBuilderService.build(options)
|
||||||
|
Statistics::Builders::StoreOrdersBuilderService.build(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -15,6 +15,8 @@ class Statistics::Builders::StoreOrdersBuilderService
|
|||||||
ca: o[:ca],
|
ca: o[:ca],
|
||||||
products: o[:order_products],
|
products: o[:order_products],
|
||||||
categories: o[:order_categories],
|
categories: o[:order_categories],
|
||||||
|
orderId: o[:order_id],
|
||||||
|
orderState: o[:order_state],
|
||||||
stat: 1 }.merge(user_info_stat(o)))
|
stat: 1 }.merge(user_info_stat(o)))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,6 +6,7 @@ class Statistics::FetcherService
|
|||||||
include Statistics::Concerns::HelpersConcern
|
include Statistics::Concerns::HelpersConcern
|
||||||
include Statistics::Concerns::ComputeConcern
|
include Statistics::Concerns::ComputeConcern
|
||||||
include Statistics::Concerns::ProjectsConcern
|
include Statistics::Concerns::ProjectsConcern
|
||||||
|
include Statistics::Concerns::StoreOrdersConcern
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def subscriptions_list(options = default_options)
|
def subscriptions_list(options = default_options)
|
||||||
@ -185,7 +186,8 @@ class Statistics::FetcherService
|
|||||||
def store_orders_list(options = default_options)
|
def store_orders_list(options = default_options)
|
||||||
result = []
|
result = []
|
||||||
Order.includes(order_items: [:orderable])
|
Order.includes(order_items: [:orderable])
|
||||||
.where('order_items.orderable_type == "Product"')
|
.joins(:order_items)
|
||||||
|
.where("order_items.orderable_type = 'Product'")
|
||||||
.where('orders.created_at >= :start_date AND orders.created_at <= :end_date', options)
|
.where('orders.created_at >= :start_date AND orders.created_at <= :end_date', options)
|
||||||
.each do |o|
|
.each do |o|
|
||||||
result.push({ date: o.created_at.to_date, ca: calcul_ca(o.invoice) }
|
result.push({ date: o.created_at.to_date, ca: calcul_ca(o.invoice) }
|
||||||
|
8
test/fixtures/order_activities.yml
vendored
8
test/fixtures/order_activities.yml
vendored
@ -116,8 +116,8 @@ order_activity_21:
|
|||||||
operator_profile_id:
|
operator_profile_id:
|
||||||
activity_type: paid
|
activity_type: paid
|
||||||
note:
|
note:
|
||||||
created_at: '2022-10-04 14:35:40.554303'
|
created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
updated_at: '2022-10-04 14:35:40.554303'
|
updated_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
order_activity_22:
|
order_activity_22:
|
||||||
id: 22
|
id: 22
|
||||||
order_id: 15
|
order_id: 15
|
||||||
@ -125,5 +125,5 @@ order_activity_22:
|
|||||||
activity_type: ready
|
activity_type: ready
|
||||||
note: "<p>Votre <em>commande</em> est prête, merci de venir la récupérer <strong>jeudi</strong>
|
note: "<p>Votre <em>commande</em> est prête, merci de venir la récupérer <strong>jeudi</strong>
|
||||||
<u>après 14 h</u>.</p>"
|
<u>après 14 h</u>.</p>"
|
||||||
created_at: '2022-10-05 10:04:53.113486'
|
created_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
updated_at: '2022-10-05 10:04:53.113486'
|
updated_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
|
4
test/fixtures/order_items.yml
vendored
4
test/fixtures/order_items.yml
vendored
@ -126,5 +126,5 @@ order_item_24:
|
|||||||
amount: 3000
|
amount: 3000
|
||||||
quantity: 1
|
quantity: 1
|
||||||
is_offered:
|
is_offered:
|
||||||
created_at: '2022-10-04 14:35:29.003092'
|
created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
updated_at: '2022-10-04 14:35:29.003092'
|
updated_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
|
4
test/fixtures/orders.yml
vendored
4
test/fixtures/orders.yml
vendored
@ -150,8 +150,8 @@ order_15:
|
|||||||
reference: '005900-10-22'
|
reference: '005900-10-22'
|
||||||
state: ready
|
state: ready
|
||||||
total: 3000
|
total: 3000
|
||||||
created_at: '2022-10-04 14:32:28.706806'
|
created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
updated_at: '2022-10-05 10:04:53.142267'
|
updated_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
|
||||||
wallet_amount:
|
wallet_amount:
|
||||||
wallet_transaction_id:
|
wallet_transaction_id:
|
||||||
payment_method: local
|
payment_method: local
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class StatisticServiceTest < ActionDispatch::IntegrationTest
|
class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
@user = User.members.without_subscription.first
|
@user = User.members.without_subscription.first
|
||||||
@admin = User.with_role(:admin).first
|
@admin = User.with_role(:admin).first
|
30
test/services/statistics/store_statistic_service_test.rb
Normal file
30
test/services/statistics/store_statistic_service_test.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class StoreStatisticServiceTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@order = Order.find(15)
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'build stats about orders' do
|
||||||
|
# Build the stats for the last 3 days, we expect the above invoices (reservations+subscription) to appear in the resulting stats
|
||||||
|
::Statistics::BuilderService.generate_statistic({ start_date: DateTime.current.beginning_of_day,
|
||||||
|
end_date: DateTime.current.end_of_day })
|
||||||
|
|
||||||
|
Stats::StoreOrder.refresh_index!
|
||||||
|
|
||||||
|
# we should find order id 15 (created today)
|
||||||
|
stat_order = Stats::StoreOrder.search(query: { bool: { must: [{ term: { date: DateTime.current.to_date.iso8601 } },
|
||||||
|
{ term: { type: 'order' } }] } }).first
|
||||||
|
assert_not_nil stat_order
|
||||||
|
assert_equal @order.id, stat_order['orderId']
|
||||||
|
check_statistics_on_user(stat_order)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_statistics_on_user(stat)
|
||||||
|
assert_equal @order.statistic_profile.str_gender, stat['gender']
|
||||||
|
assert_equal @order.statistic_profile.age.to_i, stat['age']
|
||||||
|
assert_equal @order.statistic_profile.group.slug, stat['group']
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user