Created
September 26, 2012 13:51
-
-
Save infectious/3788171 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
-- This is a PSEUDO code for calculating the Bid price according to events e.g clicks/conversion or what IM deem an event (except impressions/auctions) | |
-- This code has not been TESTED and should be a guide line | |
-- Using this code for dev or prod is at the risk of however is using/deploying this :) | |
-- Ant! | |
--- Equation in the documentation | |
--Bde = 1000 x Event_rate x deal_goal x lookback_window_price | |
local impressions = 0 -- number of impressions | |
local event_value = 0 -- number of event. can be number of clicks, impressions, post_view_conversions, post_click_conversions. | |
local bid_price = 0 -- result of the calculation. | |
local event_rate = 0 -- This is the event rate or Events / Impressions. | |
local deal_goal = 200 -- The goal of the deal or target cost per event the ad belongs to. | |
-- The value is in money and in currency. So 200 equals to £200 or if currency is in ruble then it is in 200 rubles | |
-- need to clarify how the system deals with currency. Do we just have 1 currency accross the system or allow the system to handle | |
-- multiple currency. | |
local lookback_window_price = 1 -- The average difference between bid price and win price over a lookback Window | |
-- At the moment this will not be implemented I presume so we can use a constant of 1 | |
-- 1 because bid price / win price is the same (schimple) | |
-- Retrieve attributes --THIS IS/ARE FICTITIOUS query!!!!!!!!! | |
local goal_type = 0 --described below | |
deal_goal, goal_type = unpack(redis.call('hmget', "deal::" .. deal, "goal", "goal_type")) -- get the goal of the deal | |
-- Pure paranoia: ensure we get number back | |
deal_goal = tonumber(deal_goal) or 0 | |
goal_type = tonumber(goal_type) or 1 --type of goal e.g CPM (impressions) == 1 , CPC ( clicks==2 ), CPA( post_click_conversion==3, post_view_conversion==4 ) | |
--for sake of clarification on CPA: | |
--post_click_conversions : conversion happens after user has seen clicks impression | |
--post_view_conversions : conversion happens after user has seen an impression but did NOT click on the impression | |
local event_name = "impressions" | |
if goal_type == 2 then event_name = "clicks" end | |
if goal_type == 3 then event_name = "post_click_conversions" end | |
if goal_type == 4 then event_name = "post_view_conversions" end | |
---Getting impression and event values | |
if event_name != "impressions" then | |
impressions, event_value = unpack(redis.call('hmget', "ad::" .. ad, "impressions", event_name)) | |
if impressions > 0 then | |
event_rate = event_value / impressions | |
end | |
else | |
impressions = unpack(redis.call('hmget', "ad::" .. ad, "impressions")) | |
event_rate = 1 | |
end | |
bid_price = 1000 * event_rate * deal_goal * lookback_window_price | |
--The bid price is in the currency and we need to convert it to Micros!!!! | |
-- Store bid_price | |
redis.call('zadd', 'ad::'..ad, bid_price) | |
return bid_price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment