Module: VWO::Common::CampaignUtils

Includes:
CONSTANTS, Enums
Included in:
VWO, DecisionService, ProjectConfigManager
Defined in:
lib/vwo/common/campaign_utils.rb

Constant Summary

Constants included from CONSTANTS

VWO::Common::CONSTANTS::API_VERSION, VWO::Common::CONSTANTS::HTTPS_PROTOCOL, VWO::Common::CONSTANTS::HTTP_PROTOCOL, VWO::Common::CONSTANTS::LIBRARY_PATH, VWO::Common::CONSTANTS::MAX_TRAFFIC_PERCENT, VWO::Common::CONSTANTS::MAX_TRAFFIC_VALUE, VWO::Common::CONSTANTS::PLATFORM, VWO::Common::CONSTANTS::SDK_VERSION, VWO::Common::CONSTANTS::SEED_VALUE, VWO::Common::CONSTANTS::STATUS_RUNNING, VWO::Common::CONSTANTS::URL_NAMESPACE

Instance Method Summary collapse

Instance Method Details

#get_campaign(settings_file, campaign_test_key) ⇒ Object

Finds and Returns campaign from given campaign_test_key.

@param :settings_file Settings file for the project @param :campaign_test_key Campaign identifier key @return :campaign object



20
21
22
23
24
# File 'lib/vwo/common/campaign_utils.rb', line 20

def get_campaign(settings_file, campaign_test_key)
  (settings_file['campaigns'] || []).find do |campaign|
    campaign['key'] == campaign_test_key
  end
end

#get_campaign_goal(settings_file, campaign_test_key, goal_identifier) ⇒ Object

Returns goal from given campaign_test_key and gaol_identifier. @param :settings_file Settings file of the project @param :campaign_test_key Campaign identifier key @param :goal_identifier Goal identifier

@return Goal corresponding to Goal_identifier in respective campaign



67
68
69
70
71
72
73
74
75
76
# File 'lib/vwo/common/campaign_utils.rb', line 67

def get_campaign_goal(settings_file, campaign_test_key, goal_identifier)
  return unless settings_file && campaign_test_key && goal_identifier

  campaign = get_campaign(settings_file, campaign_test_key)
  return unless campaign

  campaign['goals'].find do |goal|
    goal['identifier'] == goal_identifier
  end
end

#set_variation_allocation(campaign) ⇒ Object

Sets variation allocation range in the provided campaign

Parameters:

  • : (Hash)

    Campaign object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vwo/common/campaign_utils.rb', line 30

def set_variation_allocation(campaign)
  current_allocation = 0
  campaign['variations'].each do |variation|
    step_factor = get_variation_bucketing_range(variation['weight'])
    if step_factor
      start_range = current_allocation + 1
      end_range = current_allocation + step_factor
      variation['start_variation_allocation'] = start_range
      variation['end_variation_allocation'] = end_range
      current_allocation += step_factor
    else
      variation['start_variation_allocation'] = -1
      variation['end_variation_allocation'] = -1
    end

    CustomLogger.get_instance.log(
      LogLevelEnum::INFO,
      format(
        LogMessageEnum::InfoMessages::VARIATION_RANGE_ALLOCATION,
        file: FileNameEnum::CampaignUtil,
        campaign_test_key: campaign['key'],
        variation_name: variation['name'],
        variation_weight: variation['weight'],
        start: variation['start_variation_allocation'],
        end: variation['end_variation_allocation']
      )
    )
  end
end