lib/voucher/model/segment.rb in voucher-0.2.1 vs lib/voucher/model/segment.rb in voucher-0.3.0

- old
+ new

@@ -1,104 +1,54 @@ # frozen_string_literal: true -module Voucher - class Segment - include Virtus.model +class Segment + include Virtus.model - COMPOUND_METRICS = %w( - bot_clicks - bot_decision_win_clicks - bot_decision_win_impressions - bot_impressions - bot_loaded_clicks - bot_loaded_impressions - decision_win_clicks - decision_win_impressions - loaded_clicks - loaded_impressions - non_bot_clicks - non_bot_decision_win_clicks - non_bot_decision_win_impressions - non_bot_impressions - non_bot_loaded_clicks - non_bot_loaded_impressions - non_viewable_bot_decision_win_clicks - non_viewable_bot_decision_win_impressions - non_viewable_bot_loaded_clicks - non_viewable_bot_loaded_impressions - non_viewable_clicks - non_viewable_decision_win_clicks - non_viewable_decision_win_impressions - non_viewable_impressions - non_viewable_loaded_clicks - non_viewable_loaded_impressions - non_viewable_non_bot_clicks - non_viewable_non_bot_decision_win_clicks - non_viewable_non_bot_decision_win_impressions - non_viewable_non_bot_impressions - non_viewable_non_bot_loaded_clicks - non_viewable_non_bot_loaded_impressions - viewable_bot_clicks - viewable_bot_decision_win_clicks - viewable_bot_decision_win_impressions - viewable_bot_impressions - viewable_bot_loaded_clicks - viewable_bot_loaded_impressions - viewable_clicks - viewable_decision_win_clicks - viewable_decision_win_impressions - viewable_impressions - viewable_loaded_clicks - viewable_loaded_impressions - viewable_non_bot_clicks - viewable_non_bot_decision_win_clicks - viewable_non_bot_decision_win_impressions - viewable_non_bot_impressions - viewable_non_bot_loaded_clicks - viewable_non_bot_loaded_impressions - ).freeze + GROUP_BY_FIELDS = %w( + advertiser_id + advertisement_id + campaign_id + channel_id + app_id + exchange_id + publisher_id + agency_id + site_id + third_party_id + supply_id + ).freeze - FIELDS = %w( - advertiser_id - agency_id - app_id - campaign_id - channel_id - clicks - conversions - decision_cost - exchange_id - impressions - publisher_id - site_id - supply_id - third_party_id - win_cost - ).sort.freeze + COMPOUND_METRICS + COMPOUND_METRICS_FIELDS = + Config.compound_metric_types.reject { |m| m.include?('render') }.map(&:pluralize) - attribute :advertiser_id, String - attribute :agency_id, String - attribute :app_id, String - attribute :campaign_id, String - attribute :channel_id, String - attribute :clicks, Integer - attribute :conversions, Integer - attribute :decision_cost, Integer - attribute :exchange_id, String - attribute :impressions, Integer - attribute :publisher_id, String - attribute :site_id, String - attribute :supply_id, String - attribute :third_party_id, String - attribute :win_cost, Integer - attribute :shard, Integer - attribute :siblings, Array[String] + AGGREGATED_METRIC_FIELDS = Config.aggregated_metric_types.map(&:pluralize) + COST_METRIC_FIELDS = Config.cost_metrics - COMPOUND_METRICS.each do |metric| - attribute metric.to_sym, Integer - end + VERIFIED_FIELDS = + (GROUP_BY_FIELDS + + AGGREGATED_METRIC_FIELDS + + COMPOUND_METRICS_FIELDS + + COST_METRIC_FIELDS).sort.freeze - def hash - Hashtastic::DictionaryValuesHasher.call(attributes, FIELDS) - end + attribute :shard, Integer + attribute :siblings, Array[String] + + GROUP_BY_FIELDS.each do |f| + attribute f.to_sym, String + end + + AGGREGATED_METRIC_FIELDS.each do |f| + attribute f.to_sym, Integer + end + + COMPOUND_METRICS_FIELDS.each do |f| + attribute f.to_sym, Integer + end + + COST_METRIC_FIELDS.each do |f| + attribute f.to_sym, Float + end + + def hash + Hashtastic::DictionaryValuesHasher.call(attributes, VERIFIED_FIELDS) end end