Last active
February 8, 2019 13:16
-
-
Save abhishekgupta5/0225281749acad0248421c9103d0c6ca to your computer and use it in GitHub Desktop.
Revisions
-
Abhishek Gupta revised this gist
Feb 8, 2019 . 1 changed file with 6 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,9 @@ D = cts.split("\n") # To create(spot level) C = saleshouse.split("\n") # spot level B = tv_channels.split("\n") # campaign level A = account_ids.split("\n") #account level values = A.zip(B, C, D) # values = [['A', 'B', 'C', 'D'], ['A2', 'B2', 'C2', 'D2'],.....] keys = ["account_id", "channel", "saleshouse", "Correct TV Saleshouse"] -
Abhishek Gupta created this gist
Feb 8, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,50 @@ values = A.zip(B, C, D) # values = [['A', 'B', 'C', 'D'], ['A2', 'B2', 'C2', 'D2'],.....] keys = ["account_id", "channel", "saleshouse", "Correct TV Saleshouse"] def create_rule(dimension, channel, rule_name, filters) puts "... starting #{rule_name} ..." rule = dimension.rules_for_user_annotators.find_or_initialize_by(name: rule_name, channel: channel) rule.assign_attributes(filters: filters, status: 'ACTIVE', level: 'spot') rule.save! if rule.changed? puts "... ended #{rule_name} ..." end def construct_filter(channel, row) filter = [] #account_id = row[0] account = TvSquaredAdAccount.where(company_id: 411, account_id: row[0]).active.first raise "Account not found with ID #{account_id}" if account.blank? filter << { dimension: 'custom_tags.Account ID.name', operator: '$in', value: [row[0]] } #channel = row[1] #campaign = TvSquaredCampaign.where(tv_squared_ad_account_id: account_id, channel: channel).active.first filter << { dimension: 'custom_tags.TV Channel.name', operator: '$in', value: [row[1]] } #saleshouse = row[2] #spot = TvSquaredSpot.where(tv_squared_ad_account_id: account_id, tv_squared_campaign_id: campaign.id, saleshouse: saleshouse).active.first filter << { dimension: 'custom_tags.Saleshouse.name', operator: '$in', value: [row[2]] } return filter end dimension = UserTagGroupAnnotator.find(606) channel = 'tv_squared' values.each do |row| begin filters = [construct_filter(channel, row)] create_rule(dimension, channel, row[3], filters) rescue => e puts "Couldn't create rule: #{rule_name}, row: #{row}, error: #{e.inspect}" end end