# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

from scipy.stats import randint
import pandas as pd
import revenue_maximization_ranking as rmr
from revenue_maximization_ranking.cascade import full_best_x, expected_revenue


rmr.__version__

g = randint(1, 20)


df = pd.DataFrame({"name": list("abcdefghijklmnop"),
                   "rev": [3.1, 1.1, 5.1, 0.1, 0.3, 0.3, 3.1, 0.4, 0.4, 0.01,
                           0.01, 1.1, 1.08, 3.2, 0.001, 0.1],
                   "prob": [0.05, 0.02, 0.005, 0.01, 0.1, 0.08, 0.12, 0.06,
                            0.05, 1-0, 0.99, 0.1, 0.1, 0.04, 1.0, 0.05]})


df["default_rnk"] = [i + 1 for i in range(df.shape[0])]


rev_default = expected_revenue(df, revenue_col="rev", probability_col="prob", 
                               ranking_col="default_rnk", g=g)


df["ranking"] = full_best_x(df, revenue_col="rev", probability_col="prob",
                            g=g)


df


rev_full_best_x = expected_revenue(df, revenue_col="rev", 
                                   probability_col="prob", 
                                   ranking_col="ranking", g=g)


(rev_full_best_x/rev_default - 1) * 100


StarcoderdataJupyterScriptsDedupFiltered