Created
December 10, 2013 14:56
-
-
Save dmexe/7891938 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
save_customers false | |
save_events true | |
total :unique_customers_count, :sum | |
total :events_count, :sum | |
total :events_sum, :sum | |
total :events_bonus_sum, :sum | |
total :events_discount_sum, :sum | |
total :events_discount_percentage, :avg, type: "numeric(16,2)" | |
total :avg_events_sum, :avg, type: "numeric(16,2)" | |
total :avg_payments_per_customer, :avg, type: "numeric(16,2)" | |
attribute :group_by_method, as: :string, values: | |
%w{ hour day week month customer_type event_customer customer_node | |
customer_purchases avg_sum_customer_purchases node promo customer_purchase_order } | |
source :outer do | |
from :inner | |
to ->(c) { c.outer_table_name } | |
all_columns | |
column :group_by_column, :group_by_column_field_value | |
where :outer_conditions | |
end | |
source do | |
from :outer | |
column :group_by_column | |
column :group_by_column_title, :group_by_column_field_title | |
column :unique_customers_count, "COUNT(DISTINCT customer_id)" | |
column :events_count, "COUNT(event_id)" | |
column :events_sum, "(SUM(event_sum))::numeric(16,2)" | |
column :events_bonus_sum, "(SUM(event_bonuses))::numeric(16,2)" | |
column :events_discount_sum, "(SUM(event_discount))::numeric(16,2)" | |
column :events_discount_percentage, %{ | |
( | |
100.0 * ( | |
SUM(event_discount) / SUM(event_sum) | |
) | |
)::numeric(16,2) | |
} | |
column :avg_events_sum, "(AVG(event_sum) / 100.0)::numeric(16,2)" | |
column :avg_payments_per_customer, %{ | |
(COUNT(event_id)::float / COUNT(DISTINCT customer_id)::float)::numeric(16,2) | |
} | |
column :event_ids, "ARRAY_AGG(event_id)" | |
column :position, "ROW_NUMBER() OVER (ORDER BY group_by_column)" | |
group_by "group_by_column, group_by_column_title" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment