Last active
January 9, 2020 11:38
-
-
Save adriang133/3b546598cf0c7e58cc793b3bac71fe94 to your computer and use it in GitHub Desktop.
Multiplier adjustment vs budget fill rate interactive graph
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
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib.widgets import Slider | |
BUDGET_FILLING_CAP_THRESHOLD = 0.97 | |
BUDGET_FILL_ROLLING_WINDOW = 30 | |
def ease_in_out_sine(x): | |
return (1 + np.sin(np.pi * x - np.pi / 2)) / 2 | |
def ease_in_sine(x): | |
return np.sin((x - 1) * np.pi / 2) + 1 | |
DAYS_DEFAULT = 15 | |
def get_multiplier_adjustment(budget_filling, days_since_last_adjustment, top=3, bottom=0.8): | |
budget_filling = min(budget_filling, 1) | |
if budget_filling < BUDGET_FILLING_CAP_THRESHOLD: | |
#adjusted_top = 1 + (top - 1) * (float(days_since_last_adjustment) / BUDGET_FILL_ROLLING_WINDOW) | |
adjusted_top = 1 + (top - 1) * ease_in_sine(float(days_since_last_adjustment) / BUDGET_FILL_ROLLING_WINDOW) | |
factor = (1 - ease_in_out_sine(budget_filling)) * (adjusted_top - 1) + 1 | |
else: | |
factor = ( | |
1 - ease_in_out_sine(float(days_since_last_adjustment) / BUDGET_FILL_ROLLING_WINDOW) | |
) * (1 - bottom) + bottom | |
return factor | |
fig, ax = plt.subplots() | |
plt.subplots_adjust(left=0.2, bottom=0.25) | |
xs = [i / 100 for i in range(105)] | |
l, = plt.plot(xs, [get_multiplier_adjustment(x, DAYS_DEFAULT) for x in xs]) | |
plt.axis([0, 1.1, 0.6, 3.2]) | |
axx = plt.axes([0.35, 0.1, 0.55, 0.03], facecolor='lightgoldenrodyellow') | |
days_slider = Slider(axx, 'Days since last adjustment', 0.0, 30.0, valinit=DAYS_DEFAULT) | |
def update(evt): | |
days = days_slider.val | |
l.set_ydata([get_multiplier_adjustment(x, days) for x in xs]) | |
fig.canvas.draw_idle() | |
days_slider.on_changed(update) | |
ax.set_xlabel('Budget fill rate') | |
ax.set_ylabel('Multiplier Adjustment') | |
ax.grid() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment