Skip to content

Instantly share code, notes, and snippets.

@gonzaloserrano
Created January 26, 2017 11:57
Show Gist options
  • Save gonzaloserrano/1bbc62aa90426af189813cd41752c2c5 to your computer and use it in GitHub Desktop.
Save gonzaloserrano/1bbc62aa90426af189813cd41752c2c5 to your computer and use it in GitHub Desktop.
(function()
-- simulate omniata derived stuff with func calls
function f1()
return 1485357805
end
function f2()
return 1485357805 + 3600
end
function f3()
return 1485357805 - 3600
end
function f4()
return 0.5
end
function f5()
return 1000
end
function f6()
return 10
end
function f7()
return 0
end
function bench()
user_vars = {
['cuf_offer_system_popup_1ts'] = f1(),
['cuf_offer_system_purchase_1ts'] = f2(),
['cuf_conversion_timestamp'] = f3(),
['cuf_ltv_offer_predicted_iap'] = f4()
}
user_state = {
['revenue'] = f5(),
['delta_revenue'] = f6()
}
event_kvp = {
['revenue'] = f7()
}
-- main logic
purchase_time=math.max(user_vars['cuf_offer_system_popup_1ts'] or 0, user_vars['cuf_offer_system_purchase_1ts'] or 0)
if purchase_time == user_vars['cuf_offer_system_popup_1ts'] then
finish_offer=((user_vars['cuf_offer_system_popup_1ts'] or 0 )+86400)
else
finish_offer=purchase_time
end
if user_vars['cuf_offer_system_popup_1ts']==nil
then finish_offer=user_vars['cuf_conversion_timestamp'] or 0 or event_kvp['om_event_type']
end
if finish_offer == 0
then
return math.max(user_vars['cuf_ltv_offer_predicted_iap'] or 0, (user_state['revenue'] + user_state['delta_revenue'])/100)
end
if finish_offer < os.time()
then
return math.max(user_vars['cuf_ltv_offer_predicted_iap'] or 0, (user_state['revenue'] + user_state['delta_revenue'])/100)
else
return user_vars['cuf_offer_system_purchase_3ltv'] or 0
end
end
for i=200,1,-1 do
bench()
end
return true
end
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment