import%20marimo%0A%0A__generated_with%20%3D%20%220.18.4%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20pandas%20as%20pd%0A%0A%20%20%20%20pd.set_option(%22display.max_rows%22%2C%20None)%0A%20%20%20%20pd.set_option(%22display.max_columns%22%2C%20None)%0A%20%20%20%20pd.set_option(%22display.width%22%2C%20None)%0A%20%20%20%20pd.set_option(%22display.max_colwidth%22%2C%20None)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Goal%20Diff%20%26%20Goal%20Total%20Payoff%20Demo%0A%0A%20%20%20%20This%20notebook%20demonstrates%20how%20payoffs%20change%20as%20you%20vary%20betting%20lines%20using%20interactive%20sliders.%0A%0A%20%20%20%20%23%23%20Goal%20Diff%0A%0A%20%20%20%20-%20**Positive%20line**%3A%20home%20team%20gets%20goals%20added%0A%20%20%20%20-%20**Negative%20line**%3A%20home%20team%20gets%20goals%20subtracted%0A%20%20%20%20-%20**Payoff%20calculation**%3A%20(home_goals%20-%20away_goals)%20%2B%20line%0A%0A%20%20%20%20%23%23%20Goal%20Total%0A%0A%20%20%20%20-%20**Over**%3A%20bet%20wins%20if%20total%20goals%20%3E%20line%0A%20%20%20%20-%20**Under**%3A%20bet%20wins%20if%20total%20goals%20%3C%20line%0A%20%20%20%20-%20**Payoff%20calculation**%3A%20(home_goals%20%2B%20away_goals)%20-%20line%0A%0A%20%20%20%20**Color%20Legend**%3A%0A%0A%20%20%20%20-%20%F0%9F%9F%A2%20**Full%20Win%20(%2B1.0)**%3A%20Dark%20green%0A%20%20%20%20-%20%F0%9F%9F%A2%20**Half%20Win%20(%2B0.5)**%3A%20Light%20green%0A%20%20%20%20-%20%F0%9F%9F%A1%20**Push%20(0.0)**%3A%20Amber%0A%20%20%20%20-%20%F0%9F%94%B4%20**Half%20Loss%20(-0.5)**%3A%20Light%20red%0A%20%20%20%20-%20%F0%9F%94%B4%20**Full%20Loss%20(-1.0)**%3A%20Dark%20red%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_line%2C%20grid_size%2C%20mo%2C%20ou_line)%3A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%23%23%20Interactive%20Controls%0A%0A%20%20%20%20-%20**Grid%20Size**%3A%20%7Bgrid_size.value%7D%20%C3%97%20%7Bgrid_size.value%7D%0A%20%20%20%20-%20**Goal%20Diff%20Line**%3A%20%7Bah_line.value%7D%0A%20%20%20%20-%20**Goal%20Total%20Line**%3A%20%7Bou_line.value%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Set%20GoalGrid%20size%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid_size)%3A%0A%20%20%20%20grid_size%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_payoffs%2C%20mo)%3A%0A%20%20%20%20%23%20Style%20Goal%20Diff%20matrix%0A%20%20%20%20ah_styled%20%3D%20ah_payoffs.style.map(payoff_colors).format(%22%7B%3A%2B.1f%7D%22)%0A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%20Goal%20Diff%0A%0A%20%20%20%20**Rows**%3A%20Away%20team%20goals%20%7C%20**Columns**%3A%20Home%20team%20goals%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(ah_styled%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_line)%3A%0A%20%20%20%20ah_line%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_info%2C%20mo)%3A%0A%20%20%20%20%23%20Goal%20Diff%20line%20info%0A%20%20%20%20ah_type%20%3D%20%22Unit%22%20if%20ah_info%5B%22is_unit%22%5D%20else%20%22Half%22%20if%20ah_info%5B%22is_half%22%5D%20else%20%22Quarter%22%0A%20%20%20%20ah_neighbours%20%3D%20(%0A%20%20%20%20%20%20%20%20f%22%7Bah_info%5B'neighbours'%5D%5B0%5D%7D%20and%20%7Bah_info%5B'neighbours'%5D%5B1%5D%7D%22%20if%20ah_info%5B%22is_quarter%22%5D%20else%20str(ah_info%5B%22value%22%5D)%0A%20%20%20%20)%0A%0A%20%20%20%20mo.md(f%22%22%22%0A%0A%20%20%20%20**Line**%3A%20%7Bah_info%5B%22value%22%5D%7D%20(%7Bah_type%7D%20Line)%0A%20%20%20%20**Calculation**%3A%20Based%20on%20%7Bah_neighbours%7D%0A%20%20%20%20**Push%20Possible**%3A%20%7B%22Yes%22%20if%20ah_info%5B%22is_unit%22%5D%20else%20%22No%22%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_styled)%3A%0A%20%20%20%20ah_styled%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_grid%2C%20ah_line%2C%20mo)%3A%0A%20%20%20%20%23%20Goal%20Diff%20calculation%20breakdown%0A%20%20%20%20ah_diff%20%3D%20ah_grid.home%20-%20ah_grid.away%0A%20%20%20%20ah_adjusted%20%3D%20ah_diff%20%2B%20ah_line.value%0A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%23%23%23%20Calculation%3A%20(Home%20Goals%20-%20Away%20Goals)%20%2B%20%7Bah_line.value%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(ah_adjusted%2C)%0A%0A%0A%40app.cell%0Adef%20_(ah_adjusted)%3A%0A%20%20%20%20ah_adjusted.style.format(%22%7B%3A%2B.2f%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20ou_info)%3A%0A%20%20%20%20%23%20Goal%20Total%20line%20info%0A%20%20%20%20ou_type%20%3D%20%22Unit%22%20if%20ou_info%5B%22is_unit%22%5D%20else%20%22Half%22%20if%20ou_info%5B%22is_half%22%5D%20else%20%22Quarter%22%0A%20%20%20%20ou_neighbours%20%3D%20(%0A%20%20%20%20%20%20%20%20f%22%7Bou_info%5B'neighbours'%5D%5B0%5D%7D%20and%20%7Bou_info%5B'neighbours'%5D%5B1%5D%7D%22%20if%20ou_info%5B%22is_quarter%22%5D%20else%20str(ou_info%5B%22value%22%5D)%0A%20%20%20%20)%0A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%23%20Goal%20Total%20Results%0A%0A%20%20%20%20**Line**%3A%20%7Bou_info%5B%22value%22%5D%7D%20(%7Bou_type%7D%20Line)%0A%20%20%20%20**Calculation**%3A%20Based%20on%20%7Bou_neighbours%7D%0A%20%20%20%20**Push%20Possible**%3A%20%7B%22Yes%22%20if%20ou_info%5B%22is_unit%22%5D%20else%20%22No%22%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ou_line)%3A%0A%20%20%20%20ou_line%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20ou_payoffs)%3A%0A%20%20%20%20%23%20Style%20Goal%20Total%20matrix%0A%20%20%20%20ou_styled%20%3D%20ou_payoffs.style.map(payoff_colors).format(%22%7B%3A%2B.1f%7D%22)%0A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%20Goal%20Total%20Payoff%20Matrix%0A%0A%20%20%20%20**Rows**%3A%20Away%20team%20goals%20%7C%20**Columns**%3A%20Home%20team%20goals%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(ou_styled%2C)%0A%0A%0A%40app.cell%0Adef%20_(ou_styled)%3A%0A%20%20%20%20ou_styled%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo%2C%20ou_grid%2C%20ou_line)%3A%0A%20%20%20%20%23%20Goal%20Total%20calculation%20breakdown%0A%20%20%20%20ou_total%20%3D%20ou_grid.home%20%2B%20ou_grid.away%0A%20%20%20%20ou_adjusted%20%3D%20ou_total%20-%20ou_line.value%0A%0A%20%20%20%20mo.md(f%22%22%22%0A%20%20%20%20%23%23%23%20Calculation%3A%20(Home%20Goals%20%2B%20Away%20Goals)%20-%20%7Bou_line.value%7D%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%20(ou_adjusted%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ou_adjusted)%3A%0A%20%20%20%20ou_adjusted.style.format(%22%7B%3A%2B.2f%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Key%20Insights%0A%0A%20%20%20%20%23%23%20Goal%20Diff%0A%20%20%20%20-%20**Unit%20Lines**%20(0%2C%20%C2%B11%2C%20%C2%B12)%3A%20Can%20result%20in%20pushes%20when%20adjusted%20difference%20%3D%200%0A%20%20%20%20-%20**Half%20Lines**%20(%C2%B10.5%2C%20%C2%B11.5)%3A%20No%20pushes%20possible%2C%20always%20win%20or%20lose%0A%20%20%20%20-%20**Quarter%20Lines**%20(%C2%B10.25%2C%20%C2%B10.75)%3A%20Blend%20between%20adjacent%20half-lines%2C%20fractional%20payoffs%20(%C2%B10.5)%0A%20%20%20%20-%20**Strategy**%3A%20Positive%20handicaps%20favor%20home%20team%2C%20negative%20favor%20away%20team%0A%0A%20%20%20%20%23%23%20Goal%20Total%0A%20%20%20%20-%20**Unit%20Lines**%20(1%2C%202%2C%203)%3A%20Can%20result%20in%20pushes%20when%20total%20goals%20%3D%20line%0A%20%20%20%20-%20**Half%20Lines**%20(0.5%2C%201.5%2C%202.5)%3A%20No%20pushes%20possible%0A%20%20%20%20-%20**Quarter%20Lines**%20(0.25%2C%201.75)%3A%20Blend%20between%20adjacent%20half-lines%0A%20%20%20%20-%20**Strategy**%3A%20Consider%20team%20attacking%2Fdefensive%20styles%20and%20game%20context%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20import%20pyrf%20as%20rf%0A%20%20%20%20return%20(rf%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20%23%20Grid%20size%20slider%20(shared%20by%20both%20sections)%0A%20%20%20%20grid_size%20%3D%20mo.ui.slider(start%3D3%2C%20stop%3D20%2C%20step%3D1%2C%20value%3D10%2C%20label%3D%22Goal%20Grid%20Size%20(max%20goals%20per%20team)%22)%0A%20%20%20%20return%20(grid_size%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(ah_line%2C%20grid_size%2C%20rf)%3A%0A%20%20%20%20%23%20Create%20Goal%20Diff%20data%0A%20%20%20%20ah_grid%20%3D%20rf.GoalGrid(n%3Dgrid_size.value)%0A%20%20%20%20ah_bet%20%3D%20rf.AsianHandicap(line%3Dah_line.value)%0A%20%20%20%20ah_payoffs%20%3D%20ah_bet.grid_payoff(grid%3Dah_grid)%0A%0A%20%20%20%20%23%20Line%20info%0A%20%20%20%20ah_info%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22value%22%3A%20ah_bet.line.value%2C%0A%20%20%20%20%20%20%20%20%22is_unit%22%3A%20ah_bet.line.is_unit_line()%2C%0A%20%20%20%20%20%20%20%20%22is_half%22%3A%20ah_bet.line.is_half_line()%2C%0A%20%20%20%20%20%20%20%20%22is_quarter%22%3A%20ah_bet.line.is_quarter_line()%2C%0A%20%20%20%20%20%20%20%20%22neighbours%22%3A%20ah_bet.line.neighbours()%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20ah_grid%2C%20ah_info%2C%20ah_payoffs%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid_size%2C%20mo)%3A%0A%20%20%20%20%23%20Goal%20Diff%20line%20slider%0A%20%20%20%20ah_line%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D-grid_size.value%2C%0A%20%20%20%20%20%20%20%20stop%3Dgrid_size.value%2C%0A%20%20%20%20%20%20%20%20step%3D0.25%2C%0A%20%20%20%20%20%20%20%20value%3D0.25%2C%0A%20%20%20%20%20%20%20%20label%3D%22Goal%20Diff%20Line%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(ah_line%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid_size%2C%20ou_line%2C%20rf)%3A%0A%20%20%20%20%23%20Create%20Goal%20Total%20data%0A%20%20%20%20ou_grid%20%3D%20rf.GoalGrid(n%3Dgrid_size.value)%0A%20%20%20%20ou_bet%20%3D%20rf.TotalGoals(line%3Dou_line.value)%0A%20%20%20%20ou_payoffs%20%3D%20ou_bet.grid_payoff(grid%3Dou_grid)%0A%0A%20%20%20%20%23%20Line%20info%0A%20%20%20%20ou_info%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22value%22%3A%20ou_bet.line.value%2C%0A%20%20%20%20%20%20%20%20%22is_unit%22%3A%20ou_bet.line.is_unit_line()%2C%0A%20%20%20%20%20%20%20%20%22is_half%22%3A%20ou_bet.line.is_half_line()%2C%0A%20%20%20%20%20%20%20%20%22is_quarter%22%3A%20ou_bet.line.is_quarter_line()%2C%0A%20%20%20%20%20%20%20%20%22neighbours%22%3A%20ou_bet.line.neighbours()%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20ou_grid%2C%20ou_info%2C%20ou_payoffs%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(grid_size%2C%20mo)%3A%0A%20%20%20%20%23%20Goal%20Total%20line%20slider%0A%20%20%20%20ou_line%20%3D%20mo.ui.slider(%0A%20%20%20%20%20%20%20%20start%3D0%2C%0A%20%20%20%20%20%20%20%20stop%3D2%20*%20grid_size.value%2C%0A%20%20%20%20%20%20%20%20step%3D0.25%2C%0A%20%20%20%20%20%20%20%20value%3Dgrid_size.value%2C%0A%20%20%20%20%20%20%20%20label%3D%22Goal%20Total%20Goal%20Total%20Line%22%2C%0A%20%20%20%20)%0A%20%20%20%20return%20(ou_line%2C)%0A%0A%0A%40app.function(hide_code%3DTrue)%0A%23%20Color%20styling%20function%0Adef%20payoff_colors(val)%3A%0A%20%20%20%20%22%22%22Color%20styling%20function%20for%20payoff%20values.%22%22%22%0A%20%20%20%20if%20val%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20return%20%22background-color%3A%20%234CAF50%3B%20color%3A%20white%3B%20font-weight%3A%20bold%22%20%20%23%20Full%20green%0A%20%20%20%20elif%20val%20%3D%3D%200.5%3A%0A%20%20%20%20%20%20%20%20return%20%22background-color%3A%20%23C8E6C9%3B%20color%3A%20black%3B%20font-weight%3A%20bold%22%20%20%23%20Light%20green%0A%20%20%20%20elif%20val%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20return%20%22background-color%3A%20%23FFE0B2%3B%20color%3A%20black%3B%20font-weight%3A%20bold%22%20%20%23%20Amber%0A%20%20%20%20elif%20val%20%3D%3D%20-0.5%3A%0A%20%20%20%20%20%20%20%20return%20%22background-color%3A%20%23FFCDD2%3B%20color%3A%20black%3B%20font-weight%3A%20bold%22%20%20%23%20Light%20red%0A%20%20%20%20elif%20val%20%3D%3D%20-1%3A%0A%20%20%20%20%20%20%20%20return%20%22background-color%3A%20%23F44336%3B%20color%3A%20white%3B%20font-weight%3A%20bold%22%20%20%23%20Full%20red%0A%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20return%20%22background-color%3A%20%23FFFFFF%3B%20color%3A%20black%3B%20font-weight%3A%20bold%22%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
cfddcfd74ca3834558e754e661c50462