1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

(feat) build stats in elasticsearch

This commit is contained in:
Sylvain 2022-10-11 15:14:53 +02:00
parent afc0685585
commit 70f7ef8951
8 changed files with 45 additions and 10 deletions

View File

@ -11,6 +11,7 @@ class Statistics::BuilderService
Statistics::Builders::ReservationsBuilderService.build(options)
Statistics::Builders::MembersBuilderService.build(options)
Statistics::Builders::ProjectsBuilderService.build(options)
Statistics::Builders::StoreOrdersBuilderService.build(options)
end
private

View File

@ -15,6 +15,8 @@ class Statistics::Builders::StoreOrdersBuilderService
ca: o[:ca],
products: o[:order_products],
categories: o[:order_categories],
orderId: o[:order_id],
orderState: o[:order_state],
stat: 1 }.merge(user_info_stat(o)))
end
end

View File

@ -6,6 +6,7 @@ class Statistics::FetcherService
include Statistics::Concerns::HelpersConcern
include Statistics::Concerns::ComputeConcern
include Statistics::Concerns::ProjectsConcern
include Statistics::Concerns::StoreOrdersConcern
class << self
def subscriptions_list(options = default_options)
@ -185,7 +186,8 @@ class Statistics::FetcherService
def store_orders_list(options = default_options)
result = []
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)
.each do |o|
result.push({ date: o.created_at.to_date, ca: calcul_ca(o.invoice) }

View File

@ -116,8 +116,8 @@ order_activity_21:
operator_profile_id:
activity_type: paid
note:
created_at: '2022-10-04 14:35:40.554303'
updated_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: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
order_activity_22:
id: 22
order_id: 15
@ -125,5 +125,5 @@ order_activity_22:
activity_type: ready
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>"
created_at: '2022-10-05 10:04:53.113486'
updated_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: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>

View File

@ -126,5 +126,5 @@ order_item_24:
amount: 3000
quantity: 1
is_offered:
created_at: '2022-10-04 14:35:29.003092'
updated_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: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>

View File

@ -150,8 +150,8 @@ order_15:
reference: '005900-10-22'
state: ready
total: 3000
created_at: '2022-10-04 14:32:28.706806'
updated_at: '2022-10-05 10:04:53.142267'
created_at: <%= DateTime.current.utc.change({:hour => 10}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
updated_at: <%= DateTime.current.utc.change({:hour => 15}).strftime('%Y-%m-%d %H:%M:%S.%9N Z') %>
wallet_amount:
wallet_transaction_id:
payment_method: local

View File

@ -2,7 +2,7 @@
require 'test_helper'
class StatisticServiceTest < ActionDispatch::IntegrationTest
class ReservationSubscriptionStatisticServiceTest < ActionDispatch::IntegrationTest
setup do
@user = User.members.without_subscription.first
@admin = User.with_role(:admin).first

View 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