Spaces:
Running
Running
James McCool
commited on
Commit
·
eb1f225
1
Parent(s):
8189661
Initial commit for dockerization
Browse files- .streamlit/secrets.toml +1 -0
- Dockerfile +13 -0
- requirements.txt +8 -3
- src/streamlit_app.py +818 -37
.streamlit/secrets.toml
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
mongo_uri = "mongodb+srv://multichem:[email protected]/?retryWrites=true&w=majority&appName=TestCluster"
|
Dockerfile
CHANGED
@@ -5,11 +5,24 @@ WORKDIR /app
|
|
5 |
RUN apt-get update && apt-get install -y \
|
6 |
build-essential \
|
7 |
curl \
|
|
|
8 |
git \
|
9 |
&& rm -rf /var/lib/apt/lists/*
|
10 |
|
11 |
COPY requirements.txt ./
|
12 |
COPY src/ ./src/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
RUN pip3 install -r requirements.txt
|
15 |
|
|
|
5 |
RUN apt-get update && apt-get install -y \
|
6 |
build-essential \
|
7 |
curl \
|
8 |
+
software-properties-common \
|
9 |
git \
|
10 |
&& rm -rf /var/lib/apt/lists/*
|
11 |
|
12 |
COPY requirements.txt ./
|
13 |
COPY src/ ./src/
|
14 |
+
COPY .streamlit/ ./.streamlit/
|
15 |
+
|
16 |
+
|
17 |
+
|
18 |
+
ENV MONGO_URI="mongodb+srv://multichem:[email protected]/?retryWrites=true&w=majority&appName=TestCluster"
|
19 |
+
RUN useradd -m -u 1000 user
|
20 |
+
USER user
|
21 |
+
ENV HOME=/home/user\
|
22 |
+
PATH=/home/user/.local/bin:$PATH
|
23 |
+
WORKDIR $HOME/app
|
24 |
+
RUN pip install --no-cache-dir --upgrade pip
|
25 |
+
COPY --chown=user . $HOME/app
|
26 |
|
27 |
RUN pip3 install -r requirements.txt
|
28 |
|
requirements.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
openpyxl
|
3 |
+
matplotlib
|
4 |
+
pulp
|
5 |
+
docker
|
6 |
+
plotly
|
7 |
+
scipy
|
8 |
+
pymongo
|
src/streamlit_app.py
CHANGED
@@ -1,40 +1,821 @@
|
|
1 |
-
import
|
2 |
import numpy as np
|
|
|
3 |
import pandas as pd
|
4 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
indices = np.linspace(0, 1, num_points)
|
20 |
-
theta = 2 * np.pi * num_turns * indices
|
21 |
-
radius = indices
|
22 |
-
|
23 |
-
x = radius * np.cos(theta)
|
24 |
-
y = radius * np.sin(theta)
|
25 |
-
|
26 |
-
df = pd.DataFrame({
|
27 |
-
"x": x,
|
28 |
-
"y": y,
|
29 |
-
"idx": indices,
|
30 |
-
"rand": np.random.randn(num_points),
|
31 |
-
})
|
32 |
-
|
33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
34 |
-
.mark_point(filled=True)
|
35 |
-
.encode(
|
36 |
-
x=alt.X("x", axis=None),
|
37 |
-
y=alt.Y("y", axis=None),
|
38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
40 |
-
))
|
|
|
1 |
+
import streamlit as st
|
2 |
import numpy as np
|
3 |
+
from numpy import where as np_where
|
4 |
import pandas as pd
|
5 |
+
import gspread
|
6 |
+
import plotly.express as px
|
7 |
+
import scipy.stats as stats
|
8 |
+
from pymongo import MongoClient
|
9 |
+
st.set_page_config(layout="wide")
|
10 |
+
|
11 |
+
@st.cache_resource
|
12 |
+
def init_conn():
|
13 |
+
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
|
14 |
+
|
15 |
+
credentials = {
|
16 |
+
"type": "service_account",
|
17 |
+
"project_id": "model-sheets-connect",
|
18 |
+
"private_key_id": st.secrets['model_sheets_connect_pk'],
|
19 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDiu1v/e6KBKOcK\ncx0KQ23nZK3ZVvADYy8u/RUn/EDI82QKxTd/DizRLIV81JiNQxDJXSzgkbwKYEDm\n48E8zGvupU8+Nk76xNPakrQKy2Y8+VJlq5psBtGchJTuUSHcXU5Mg2JhQsB376PJ\nsCw552K6Pw8fpeMDJDZuxpKSkaJR6k9G5Dhf5q8HDXnC5Rh/PRFuKJ2GGRpX7n+2\nhT/sCax0J8jfdTy/MDGiDfJqfQrOPrMKELtsGHR9Iv6F4vKiDqXpKfqH+02E9ptz\nBk+MNcbZ3m90M8ShfRu28ebebsASfarNMzc3dk7tb3utHOGXKCf4tF8yYKo7x8BZ\noO9X4gSfAgMBAAECggEAU8ByyMpSKlTCF32TJhXnVJi/kS+IhC/Qn5JUDMuk4LXr\naAEWsWO6kV/ZRVXArjmuSzuUVrXumISapM9Ps5Ytbl95CJmGDiLDwRL815nvv6k3\nUyAS8EGKjz74RpoIoH6E7EWCAzxlnUgTn+5oP9Flije97epYk3H+e2f1f5e1Nn1d\nYNe8U+1HqJgILcxA1TAUsARBfoD7+K3z/8DVPHI8IpzAh6kTHqhqC23Rram4XoQ6\nzj/ZdVBjvnKuazETfsD+Vl3jGLQA8cKQVV70xdz3xwLcNeHsbPbpGBpZUoF73c65\nkAXOrjYl0JD5yAk+hmYhXr6H9c6z5AieuZGDrhmlFQKBgQDzV6LRXmjn4854DP/J\nI82oX2GcI4eioDZPRukhiQLzYerMQBmyqZIRC+/LTCAhYQSjNgMa+ZKyvLqv48M0\n/x398op/+n3xTs+8L49SPI48/iV+mnH7k0WI/ycd4OOKh8rrmhl/0EWb9iitwJYe\nMjTV/QxNEpPBEXfR1/mvrN/lVQKBgQDuhomOxUhWVRVH6x03slmyRBn0Oiw4MW+r\nrt1hlNgtVmTc5Mu+4G0USMZwYuOB7F8xG4Foc7rIlwS7Ic83jMJxemtqAelwOLdV\nXRLrLWJfX8+O1z/UE15l2q3SUEnQ4esPHbQnZowHLm0mdL14qSVMl1mu1XfsoZ3z\nJZTQb48CIwKBgEWbzQRtKD8lKDupJEYqSrseRbK/ax43DDITS77/DWwHl33D3FYC\nMblUm8ygwxQpR4VUfwDpYXBlklWcJovzamXpSnsfcYVkkQH47NuOXPXPkXQsw+w+\nDYcJzeu7F/vZqk9I7oBkWHUrrik9zPNoUzrfPvSRGtkAoTDSwibhoc5dAoGBAMHE\nK0T/ANeZQLNuzQps6S7G4eqjwz5W8qeeYxsdZkvWThOgDd/ewt3ijMnJm5X05hOn\ni4XF1euTuvUl7wbqYx76Wv3/1ZojiNNgy7ie4rYlyB/6vlBS97F4ZxJdxMlabbCW\n6b3EMWa4EVVXKoA1sCY7IVDE+yoQ1JYsZmq45YzPAoGBANWWHuVueFGZRDZlkNlK\nh5OmySmA0NdNug3G1upaTthyaTZ+CxGliwBqMHAwpkIRPwxUJpUwBTSEGztGTAxs\nWsUOVWlD2/1JaKSmHE8JbNg6sxLilcG6WEDzxjC5dLL1OrGOXj9WhC9KX3sq6qb6\nF/j9eUXfXjAlb042MphoF3ZC\n-----END PRIVATE KEY-----\n",
|
20 |
+
"client_email": "[email protected]",
|
21 |
+
"client_id": "100369174533302798535",
|
22 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
23 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
24 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
25 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40model-sheets-connect.iam.gserviceaccount.com"
|
26 |
+
}
|
27 |
+
|
28 |
+
credentials2 = {
|
29 |
+
"type": "service_account",
|
30 |
+
"project_id": "sheets-api-connect-378620",
|
31 |
+
"private_key_id": st.secrets['sheets_api_connect_pk'],
|
32 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtKa01beXwc88R\nnPZVQTNPVQuBnbwoOfc66gW3547ja/UEyIGAF112dt/VqHprRafkKGmlg55jqJNt\na4zceLKV+wTm7vBu7lDISTJfGzCf2TrxQYNqwMKE2LOjI69dBM8u4Dcb4k0wcp9v\ntW1ZzLVVuwTvmrg7JBHjiSaB+x5wxm/r3FOiJDXdlAgFlytzqgcyeZMJVKKBQHyJ\njEGg/1720A0numuOCt71w/2G0bDmijuj1e6tH32MwRWcvRNZ19K9ssyDz2S9p68s\nYDhIxX69OWxwScTIHLY6J2t8txf/XMivL/636fPlDADvBEVTdlT606n8CcKUVQeq\npUVdG+lfAgMBAAECggEAP38SUA7B69eTfRpo658ycOs3Amr0JW4H/bb1rNeAul0K\nZhwd/HnU4E07y81xQmey5kN5ZeNrD5EvqkZvSyMJHV0EEahZStwhjCfnDB/cxyix\nZ+kFhv4y9eK+kFpUAhBy5nX6T0O+2T6WvzAwbmbVsZ+X8kJyPuF9m8ldcPlD0sce\ntj8NwVq1ys52eosqs7zi2vjt+eMcaY393l4ls+vNq8Yf27cfyFw45W45CH/97/Nu\n5AmuzlCOAfFF+z4OC5g4rei4E/Qgpxa7/uom+BVfv9G0DIGW/tU6Sne0+37uoGKt\nW6DzhgtebUtoYkG7ZJ05BTXGp2lwgVcNRoPwnKJDxQKBgQDT5wYPUBDW+FHbvZSp\nd1m1UQuXyerqOTA9smFaM8sr/UraeH85DJPEIEk8qsntMBVMhvD3Pw8uIUeFNMYj\naLmZFObsL+WctepXrVo5NB6RtLB/jZYxiKMatMLUJIYtcKIp+2z/YtKiWcLnwotB\nWdCjVnPTxpkurmF2fWP/eewZ+wKBgQDRMtJg7etjvKyjYNQ5fARnCc+XsI3gkBe1\nX9oeXfhyfZFeBXWnZzN1ITgFHplDznmBdxAyYGiQdbbkdKQSghviUQ0igBvoDMYy\n1rWcy+a17Mj98uyNEfmb3X2cC6WpvOZaGHwg9+GY67BThwI3FqHIbyk6Ko09WlTX\nQpRQjMzU7QKBgAfi1iflu+q0LR+3a3vvFCiaToskmZiD7latd9AKk2ocsBd3Woy9\n+hXXecJHPOKV4oUJlJgvAZqe5HGBqEoTEK0wyPNLSQlO/9ypd+0fEnArwFHO7CMF\nycQprAKHJXM1eOOFFuZeQCaInqdPZy1UcV5Szla4UmUZWkk1m24blHzXAoGBAMcA\nyH4qdbxX9AYrC1dvsSRvgcnzytMvX05LU0uF6tzGtG0zVlub4ahvpEHCfNuy44UT\nxRWW/oFFaWjjyFxO5sWggpUqNuHEnRopg3QXx22SRRTGbN45li/+QAocTkgsiRh1\nqEcYZsO4mPCsQqAy6E2p6RcK+Xa+omxvSnVhq0x1AoGAKr8GdkCl4CF6rieLMAQ7\nLNBuuoYGaHoh8l5E2uOQpzwxVy/nMBcAv+2+KqHEzHryUv1owOi6pMLv7A9mTFoS\n18B0QRLuz5fSOsVnmldfC9fpUc6H8cH1SINZpzajqQA74bPwELJjnzrCnH79TnHG\nJuElxA33rFEjbgbzdyrE768=\n-----END PRIVATE KEY-----\n",
|
33 |
+
"client_email": "gspread-connection@sheets-api-connect-378620.iam.gserviceaccount.com",
|
34 |
+
"client_id": "106625872877651920064",
|
35 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
36 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
37 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
38 |
+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/gspread-connection%40sheets-api-connect-378620.iam.gserviceaccount.com"
|
39 |
+
}
|
40 |
+
|
41 |
+
NFL_Data = st.secrets['NFL_Data']
|
42 |
+
|
43 |
+
uri = st.secrets['mongo_uri']
|
44 |
+
client = MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=100000)
|
45 |
+
dfs_db = client["NFL_Database"]
|
46 |
+
props_db = client["Props_DB"]
|
47 |
+
|
48 |
+
gc = gspread.service_account_from_dict(credentials)
|
49 |
+
gc2 = gspread.service_account_from_dict(credentials2)
|
50 |
+
|
51 |
+
return gc, gc2, NFL_Data, props_db, dfs_db
|
52 |
+
|
53 |
+
gcservice_account, gcservice_account2, NFL_Data, props_db, dfs_db = init_conn()
|
54 |
+
|
55 |
+
game_format = {'Win%': '{:.2%}', 'Vegas': '{:.2%}', 'Win% Diff': '{:.2%}'}
|
56 |
+
american_format = {'First Inning Lead Percentage': '{:.2%}', 'Fifth Inning Lead Percentage': '{:.2%}'}
|
57 |
+
|
58 |
+
def calculate_poisson(row):
|
59 |
+
mean_val = row['Mean_Outcome']
|
60 |
+
threshold = row['Prop']
|
61 |
+
cdf_value = stats.poisson.cdf(threshold, mean_val)
|
62 |
+
probability = 1 - cdf_value
|
63 |
+
return probability
|
64 |
+
|
65 |
+
@st.cache_resource(ttl=600)
|
66 |
+
def init_baselines():
|
67 |
+
collection = dfs_db["Game_Betting_Model"]
|
68 |
+
cursor = collection.find()
|
69 |
+
raw_display = pd.DataFrame(list(cursor))
|
70 |
+
game_model = raw_display[['Team', 'Opp', 'Win%', 'Vegas', 'Win% Diff', 'Win Line', 'Vegas Line', 'Line Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
|
71 |
+
|
72 |
+
collection = dfs_db["Player_Stats"]
|
73 |
+
cursor = collection.find()
|
74 |
+
raw_display = pd.DataFrame(list(cursor))
|
75 |
+
overall_stats = raw_display[['Player', 'Position', 'Team', 'Opp', 'rush_att', 'rec', 'dropbacks', 'rush_yards', 'rush_tds', 'rec_yards', 'rec_tds', 'pass_att', 'pass_yards', 'pass_tds', 'PPR', 'Half_PPR']]
|
76 |
+
|
77 |
+
collection = dfs_db["Prop_Trends"]
|
78 |
+
cursor = collection.find()
|
79 |
+
raw_display = pd.DataFrame(list(cursor))
|
80 |
+
prop_trends = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L3 Success', 'L6_Success', 'L10_success', 'L6 Avg', 'Projection',
|
81 |
+
'Proj Diff', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge']]
|
82 |
+
|
83 |
+
collection = dfs_db["DK_NFL_ROO"]
|
84 |
+
cursor = collection.find()
|
85 |
+
|
86 |
+
raw_display = pd.DataFrame(list(cursor))
|
87 |
+
raw_display = raw_display[['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%',
|
88 |
+
'Own', 'Small_Field_Own', 'Large_Field_Own', 'Cash_Field_Own', 'CPT_Own', 'LevX', 'version', 'slate', 'timestamp', 'player_ID', 'site']]
|
89 |
+
load_display = raw_display[raw_display['Position'] != 'K']
|
90 |
+
timestamp = load_display['timestamp'][0]
|
91 |
+
|
92 |
+
collection = dfs_db["Prop_Trends"]
|
93 |
+
cursor = collection.find()
|
94 |
+
raw_display = pd.DataFrame(list(cursor))
|
95 |
+
prop_frame = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L3 Success', 'L6_Success', 'L10_success', 'L6 Avg', 'Projection',
|
96 |
+
'Proj Diff', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge']]
|
97 |
+
|
98 |
+
collection = dfs_db['Pick6_Trends']
|
99 |
+
cursor = collection.find()
|
100 |
+
raw_display = pd.DataFrame(list(cursor))
|
101 |
+
pick_frame = raw_display[['Player', 'over_prop', 'over_line', 'under_prop', 'under_line', 'book', 'prop_type', 'No Vig', 'Team', 'L3 Success', 'L6_Success', 'L10_success', 'L6 Avg', 'Projection',
|
102 |
+
'Proj Diff', 'Implied Over', 'Trending Over', 'Over Edge', 'Implied Under', 'Trending Under', 'Under Edge', 'last_name', 'P6_name', 'Full_name']]
|
103 |
+
|
104 |
+
collection = props_db["NFL_Props"]
|
105 |
+
cursor = collection.find()
|
106 |
+
|
107 |
+
raw_display = pd.DataFrame(list(cursor))
|
108 |
+
market_props = raw_display[['Name', 'Position', 'Projection', 'PropType', 'OddsType', 'over_pay', 'under_pay']]
|
109 |
+
market_props['over_prop'] = market_props['Projection']
|
110 |
+
market_props['over_line'] = market_props['over_pay'].apply(lambda x: (x - 1) * 100 if x >= 2.0 else -100 / (x - 1))
|
111 |
+
market_props['under_prop'] = market_props['Projection']
|
112 |
+
market_props['under_line'] = market_props['under_pay'].apply(lambda x: (x - 1) * 100 if x >= 2.0 else -100 / (x - 1))
|
113 |
+
|
114 |
+
return game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props
|
115 |
+
|
116 |
+
def calculate_no_vig(row):
|
117 |
+
def implied_probability(american_odds):
|
118 |
+
if american_odds < 0:
|
119 |
+
return (-american_odds) / ((-american_odds) + 100)
|
120 |
+
else:
|
121 |
+
return 100 / (american_odds + 100)
|
122 |
+
|
123 |
+
over_line = row['over_line']
|
124 |
+
under_line = row['under_line']
|
125 |
+
over_prop = row['over_prop']
|
126 |
+
|
127 |
+
over_prob = implied_probability(over_line)
|
128 |
+
under_prob = implied_probability(under_line)
|
129 |
+
|
130 |
+
total_prob = over_prob + under_prob
|
131 |
+
no_vig_prob = (over_prob / total_prob + 0.5) * over_prop
|
132 |
+
|
133 |
+
return no_vig_prob
|
134 |
+
|
135 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
136 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
137 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
138 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
139 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
140 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
141 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
142 |
+
|
143 |
+
prop_table_options = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_PASSING_COMPLETIONS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
144 |
+
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
145 |
+
prop_format = {'L3 Success': '{:.2%}', 'L6_Success': '{:.2%}', 'L10_success': '{:.2%}', 'Trending Over': '{:.2%}', 'Trending Under': '{:.2%}',
|
146 |
+
'Implied Over': '{:.2%}', 'Implied Under': '{:.2%}', 'Over Edge': '{:.2%}', 'Under Edge': '{:.2%}'}
|
147 |
+
all_sim_vars = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_PASSING_COMPLETIONS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
148 |
+
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
149 |
+
pick6_sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Completions', 'Rushing Yards', 'Receptions', 'Receiving Yards']
|
150 |
+
sim_all_hold = pd.DataFrame(columns=['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge'])
|
151 |
+
|
152 |
+
tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["Game Betting Model", 'Prop Market', "QB Projections", "RB/WR/TE Projections", "Player Prop Trends", "Player Prop Simulations", "Stat Specific Simulations"])
|
153 |
+
|
154 |
+
def convert_df_to_csv(df):
|
155 |
+
return df.to_csv().encode('utf-8')
|
156 |
+
|
157 |
+
with tab1:
|
158 |
+
st.info(t_stamp)
|
159 |
+
if st.button("Reset Data", key='reset1'):
|
160 |
+
st.cache_data.clear()
|
161 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
162 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
163 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
164 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
165 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
166 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
167 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
168 |
+
line_var1 = st.radio('How would you like to display odds?', options = ['Percentage', 'American'], key='line_var1')
|
169 |
+
team_frame = game_model
|
170 |
+
if line_var1 == 'Percentage':
|
171 |
+
team_frame = team_frame[['Team', 'Opp', 'Win%', 'Vegas', 'Win% Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
|
172 |
+
team_frame = team_frame.set_index('Team')
|
173 |
+
try:
|
174 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(game_format, precision=2), use_container_width = True)
|
175 |
+
except:
|
176 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
177 |
+
if line_var1 == 'American':
|
178 |
+
team_frame = team_frame[['Team', 'Opp', 'Win Line', 'Vegas Line', 'Line Diff', 'PD Spread', 'Vegas Spread', 'Spread Diff']]
|
179 |
+
team_frame = team_frame.set_index('Team')
|
180 |
+
st.dataframe(team_frame.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height = 1000, use_container_width = True)
|
181 |
+
|
182 |
+
st.download_button(
|
183 |
+
label="Export Team Model",
|
184 |
+
data=convert_df_to_csv(team_frame),
|
185 |
+
file_name='NFL_team_betting_export.csv',
|
186 |
+
mime='text/csv',
|
187 |
+
key='team_export',
|
188 |
+
)
|
189 |
+
|
190 |
+
with tab2:
|
191 |
+
st.info(t_stamp)
|
192 |
+
if st.button("Reset Data", key='reset4'):
|
193 |
+
st.cache_data.clear()
|
194 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
195 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
196 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
197 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
198 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
199 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
200 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
201 |
+
market_type = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options, key = 'market_type_key')
|
202 |
+
disp_market = market_props.copy()
|
203 |
+
disp_market = disp_market[disp_market['PropType'] == market_type]
|
204 |
+
disp_market['No_Vig_Prop'] = disp_market.apply(calculate_no_vig, axis=1)
|
205 |
+
fanduel_frame = disp_market[disp_market['OddsType'] == 'FANDUEL']
|
206 |
+
fanduel_dict = dict(zip(fanduel_frame['Name'], fanduel_frame['No_Vig_Prop']))
|
207 |
+
draftkings_frame = disp_market[disp_market['OddsType'] == 'DRAFTKINGS']
|
208 |
+
draftkings_dict = dict(zip(draftkings_frame['Name'], draftkings_frame['No_Vig_Prop']))
|
209 |
+
mgm_frame = disp_market[disp_market['OddsType'] == 'MGM']
|
210 |
+
mgm_dict = dict(zip(mgm_frame['Name'], mgm_frame['No_Vig_Prop']))
|
211 |
+
bet365_frame = disp_market[disp_market['OddsType'] == 'BET_365']
|
212 |
+
bet365_dict = dict(zip(bet365_frame['Name'], bet365_frame['No_Vig_Prop']))
|
213 |
+
|
214 |
+
disp_market['FANDUEL'] = disp_market['Name'].map(fanduel_dict)
|
215 |
+
disp_market['DRAFTKINGS'] = disp_market['Name'].map(draftkings_dict)
|
216 |
+
disp_market['MGM'] = disp_market['Name'].map(mgm_dict)
|
217 |
+
disp_market['BET365'] = disp_market['Name'].map(bet365_dict)
|
218 |
+
|
219 |
+
disp_market = disp_market[['Name', 'Position','FANDUEL', 'DRAFTKINGS', 'MGM', 'BET365']]
|
220 |
+
disp_market = disp_market.drop_duplicates(subset=['Name'], keep='first', ignore_index=True)
|
221 |
+
|
222 |
+
st.dataframe(disp_market.style.background_gradient(axis=1, subset=['FANDUEL', 'DRAFTKINGS', 'MGM', 'BET365'], cmap='RdYlGn').format(prop_format, precision=2), height = 1000, use_container_width = True)
|
223 |
+
st.download_button(
|
224 |
+
label="Export Market Props",
|
225 |
+
data=convert_df_to_csv(disp_market),
|
226 |
+
file_name='NFL_market_props_export.csv',
|
227 |
+
mime='text/csv',
|
228 |
+
)
|
229 |
+
|
230 |
+
with tab3:
|
231 |
+
st.info(t_stamp)
|
232 |
+
if st.button("Reset Data", key='reset2'):
|
233 |
+
st.cache_data.clear()
|
234 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
235 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
236 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
237 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
238 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
239 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
240 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
241 |
+
split_var1 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var1')
|
242 |
+
if split_var1 == 'Specific Teams':
|
243 |
+
team_var1 = st.multiselect('Which teams would you like to include in the tables?', options = qb_stats['Team'].unique(), key='team_var1')
|
244 |
+
elif split_var1 == 'All':
|
245 |
+
team_var1 = qb_stats.Team.values.tolist()
|
246 |
+
qb_stats = qb_stats[qb_stats['Team'].isin(team_var1)]
|
247 |
+
qb_stats_disp = qb_stats.set_index('Player')
|
248 |
+
qb_stats_disp = qb_stats_disp.sort_values(by='PPR', ascending=False)
|
249 |
+
st.dataframe(qb_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height = 1000, use_container_width = True)
|
250 |
+
st.download_button(
|
251 |
+
label="Export Prop Model",
|
252 |
+
data=convert_df_to_csv(qb_stats_disp),
|
253 |
+
file_name='NFL_qb_stats_export.csv',
|
254 |
+
mime='text/csv',
|
255 |
+
key='NFL_qb_stats_export',
|
256 |
+
)
|
257 |
+
|
258 |
+
with tab4:
|
259 |
+
st.info(t_stamp)
|
260 |
+
if st.button("Reset Data", key='reset3'):
|
261 |
+
st.cache_data.clear()
|
262 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
263 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
264 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
265 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
266 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
267 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
268 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
269 |
+
split_var2 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var2')
|
270 |
+
if split_var2 == 'Specific Teams':
|
271 |
+
team_var2 = st.multiselect('Which teams would you like to include in the tables?', options = non_qb_stats['Team'].unique(), key='team_var2')
|
272 |
+
elif split_var2 == 'All':
|
273 |
+
team_var2 = non_qb_stats.Team.values.tolist()
|
274 |
+
non_qb_stats = non_qb_stats[non_qb_stats['Team'].isin(team_var2)]
|
275 |
+
non_qb_stats_disp = non_qb_stats.set_index('Player')
|
276 |
+
non_qb_stats_disp = non_qb_stats_disp.sort_values(by='PPR', ascending=False)
|
277 |
+
st.dataframe(non_qb_stats_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), height = 1000, use_container_width = True)
|
278 |
+
st.download_button(
|
279 |
+
label="Export Prop Model",
|
280 |
+
data=convert_df_to_csv(non_qb_stats_disp),
|
281 |
+
file_name='NFL_nonqb_stats_export.csv',
|
282 |
+
mime='text/csv',
|
283 |
+
key='NFL_nonqb_stats_export',
|
284 |
+
)
|
285 |
+
|
286 |
+
with tab5:
|
287 |
+
st.info(t_stamp)
|
288 |
+
if st.button("Reset Data", key='reset5'):
|
289 |
+
st.cache_data.clear()
|
290 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
291 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
292 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
293 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
294 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
295 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
296 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
297 |
+
split_var5 = st.radio("Would you like to view all teams or specific ones?", ('All', 'Specific Teams'), key='split_var5')
|
298 |
+
if split_var5 == 'Specific Teams':
|
299 |
+
team_var5 = st.multiselect('Which teams would you like to include in the tables?', options = prop_trends['Team'].unique(), key='team_var5')
|
300 |
+
elif split_var5 == 'All':
|
301 |
+
team_var5 = prop_trends.Team.values.tolist()
|
302 |
+
prop_type_var2 = st.selectbox('Select type of prop are you wanting to view', options = prop_table_options)
|
303 |
+
book_var2 = st.selectbox('Select type of book do you want to view?', options = ['FANDUEL', 'BET365', 'DRAFTKINGS', 'CONSENSUS'])
|
304 |
+
prop_frame_disp = prop_trends[prop_trends['Team'].isin(team_var5)]
|
305 |
+
prop_frame_disp = prop_frame_disp[prop_frame_disp['book'] == book_var2]
|
306 |
+
prop_frame_disp = prop_frame_disp[prop_frame_disp['prop_type'] == prop_type_var2]
|
307 |
+
#prop_frame_disp = prop_frame_disp.set_index('Player')
|
308 |
+
prop_frame_disp = prop_frame_disp.sort_values(by='Trending Over', ascending=False)
|
309 |
+
st.dataframe(prop_frame_disp.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(prop_format, precision=2), height = 1000, use_container_width = True)
|
310 |
+
st.download_button(
|
311 |
+
label="Export Prop Trends Model",
|
312 |
+
data=convert_df_to_csv(prop_frame_disp),
|
313 |
+
file_name='NFL_prop_trends_export.csv',
|
314 |
+
mime='text/csv',
|
315 |
+
)
|
316 |
+
|
317 |
+
with tab6:
|
318 |
+
st.info(t_stamp)
|
319 |
+
if st.button("Reset Data", key='reset6'):
|
320 |
+
st.cache_data.clear()
|
321 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
322 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
323 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
324 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
325 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
326 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
327 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
328 |
+
col1, col2 = st.columns([1, 5])
|
329 |
+
|
330 |
+
with col2:
|
331 |
+
df_hold_container = st.empty()
|
332 |
+
info_hold_container = st.empty()
|
333 |
+
plot_hold_container = st.empty()
|
334 |
+
|
335 |
+
with col1:
|
336 |
+
player_check = st.selectbox('Select player to simulate props', options = overall_stats['Player'].unique())
|
337 |
+
prop_type_var = st.selectbox('Select type of prop to simulate', options = ['Pass Yards', 'Pass TDs', 'Rush Yards', 'Rush TDs', 'Receptions', 'Rec Yards', 'Rec TDs', 'Fantasy', 'FD Fantasy', 'PrizePicks'])
|
338 |
+
|
339 |
+
ou_var = st.selectbox('Select wether it is an over or under', options = ['Over', 'Under'])
|
340 |
+
if prop_type_var == 'Pass Yards':
|
341 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 100.0, max_value = 400.5, value = 250.5, step = .5)
|
342 |
+
elif prop_type_var == 'Pass TDs':
|
343 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
344 |
+
elif prop_type_var == 'Rush Yards':
|
345 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 155.5, value = 25.5, step = .5)
|
346 |
+
elif prop_type_var == 'Rush TDs':
|
347 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
348 |
+
elif prop_type_var == 'Receptions':
|
349 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 15.5, value = 5.5, step = .5)
|
350 |
+
elif prop_type_var == 'Rec Yards':
|
351 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 155.5, value = 25.5, step = .5)
|
352 |
+
elif prop_type_var == 'Rec TDs':
|
353 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 5.5, value = 1.5, step = .5)
|
354 |
+
elif prop_type_var == 'Fantasy':
|
355 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 10.5, step = .5)
|
356 |
+
elif prop_type_var == 'FD Fantasy':
|
357 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 10.5, step = .5)
|
358 |
+
elif prop_type_var == 'PrizePicks':
|
359 |
+
prop_var = st.number_input('Type in the prop offered (i.e 5.5)', min_value = 0.0, max_value = 50.5, value = 10.5, step = .5)
|
360 |
+
line_var = st.number_input('Type in the line on the prop (i.e. -120)', min_value = -1000, max_value = 1000, value = -150, step = 1)
|
361 |
+
line_var = line_var + 1
|
362 |
+
|
363 |
+
if st.button('Simulate Prop'):
|
364 |
+
with col2:
|
365 |
+
|
366 |
+
with df_hold_container.container():
|
367 |
+
|
368 |
+
df = overall_stats
|
369 |
+
|
370 |
+
total_sims = 5000
|
371 |
+
|
372 |
+
df.replace("", 0, inplace=True)
|
373 |
+
|
374 |
+
player_var = df[df['Player'] == player_check]
|
375 |
+
player_var = player_var.reset_index()
|
376 |
+
|
377 |
+
if prop_type_var == 'Pass Yards':
|
378 |
+
df['Median'] = df['pass_yards']
|
379 |
+
elif prop_type_var == 'Pass TDs':
|
380 |
+
df['Median'] = df['pass_tds']
|
381 |
+
elif prop_type_var == 'Rush Yards':
|
382 |
+
df['Median'] = df['rush_yards']
|
383 |
+
elif prop_type_var == 'Rush TDs':
|
384 |
+
df['Median'] = df['rush_tds']
|
385 |
+
elif prop_type_var == 'Receptions':
|
386 |
+
df['Median'] = df['rec']
|
387 |
+
elif prop_type_var == 'Rec Yards':
|
388 |
+
df['Median'] = df['rec_yards']
|
389 |
+
elif prop_type_var == 'Rec TDs':
|
390 |
+
df['Median'] = df['rec_tds']
|
391 |
+
elif prop_type_var == 'Fantasy':
|
392 |
+
df['Median'] = df['PPR']
|
393 |
+
elif prop_type_var == 'FD Fantasy':
|
394 |
+
df['Median'] = df['Half_PPF']
|
395 |
+
elif prop_type_var == 'PrizePicks':
|
396 |
+
df['Median'] = df['Half_PPF']
|
397 |
+
|
398 |
+
flex_file = df
|
399 |
+
flex_file['Floor'] = flex_file['Median'] * .25
|
400 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
401 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
402 |
+
flex_file = flex_file[['Player', 'Floor', 'Median', 'Ceiling', 'STD']]
|
403 |
+
|
404 |
+
hold_file = flex_file
|
405 |
+
overall_file = flex_file
|
406 |
+
salary_file = flex_file
|
407 |
+
|
408 |
+
overall_players = overall_file[['Player']]
|
409 |
+
|
410 |
+
for x in range(0,total_sims):
|
411 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
412 |
+
|
413 |
+
overall_file=overall_file.drop(['Player', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
414 |
+
overall_file.astype('int').dtypes
|
415 |
+
|
416 |
+
players_only = hold_file[['Player']]
|
417 |
+
|
418 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
419 |
+
|
420 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
421 |
+
players_only['Prop'] = prop_var
|
422 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
423 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
424 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
425 |
+
if ou_var == 'Over':
|
426 |
+
players_only['beat_prop'] = np.where(players_only['Prop'] <= 3, players_only['poisson_var'], overall_file[overall_file > prop_var].count(axis=1)/float(total_sims))
|
427 |
+
elif ou_var == 'Under':
|
428 |
+
players_only['beat_prop'] = np.where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], (overall_file[overall_file < prop_var].count(axis=1)/float(total_sims)))
|
429 |
+
|
430 |
+
players_only['implied_odds'] = np.where(line_var <= 0, (-(line_var)/((-(line_var))+100)), 100/(line_var+100))
|
431 |
+
|
432 |
+
players_only['Player'] = hold_file[['Player']]
|
433 |
+
|
434 |
+
final_outcomes = players_only[['Player', '10%', 'Mean_Outcome', '90%', 'implied_odds', 'beat_prop']]
|
435 |
+
final_outcomes['Bet?'] = np.where(final_outcomes['beat_prop'] - final_outcomes['implied_odds'] >= .10, "Bet", "No Bet")
|
436 |
+
final_outcomes = final_outcomes[final_outcomes['Player'] == player_check]
|
437 |
+
player_outcomes = player_outcomes[player_outcomes['Player'] == player_check]
|
438 |
+
player_outcomes = player_outcomes.drop(columns=['Player']).transpose()
|
439 |
+
player_outcomes = player_outcomes.reset_index()
|
440 |
+
player_outcomes.columns = ['Instance', 'Outcome']
|
441 |
+
|
442 |
+
x1 = player_outcomes.Outcome.to_numpy()
|
443 |
+
|
444 |
+
print(x1)
|
445 |
+
|
446 |
+
hist_data = [x1]
|
447 |
+
|
448 |
+
group_labels = ['player outcomes']
|
449 |
+
|
450 |
+
fig = px.histogram(
|
451 |
+
player_outcomes, x='Outcome')
|
452 |
+
fig.add_vline(x=prop_var, line_dash="dash", line_color="green")
|
453 |
+
|
454 |
+
with df_hold_container:
|
455 |
+
df_hold_container = st.empty()
|
456 |
+
format_dict = {'10%': '{:.2f}', 'Mean_Outcome': '{:.2f}','90%': '{:.2f}', 'beat_prop': '{:.2%}','implied_odds': '{:.2%}'}
|
457 |
+
st.dataframe(final_outcomes.style.format(format_dict), use_container_width = True)
|
458 |
+
|
459 |
+
with info_hold_container:
|
460 |
+
st.info('The Y-axis is the percent of times in simulations that the player reaches certain thresholds, while the X-axis is the threshold to be met. The Green dotted line is the prop you entered. You can hover over any spot and see the percent to reach that mark.')
|
461 |
+
|
462 |
+
with plot_hold_container:
|
463 |
+
st.dataframe(player_outcomes, use_container_width = True)
|
464 |
+
plot_hold_container = st.empty()
|
465 |
+
st.plotly_chart(fig, use_container_width=True)
|
466 |
+
|
467 |
+
with tab7:
|
468 |
+
st.info(t_stamp)
|
469 |
+
st.info('The Over and Under percentages are a compositve percentage based on simulations, historical performance, and implied probabilities, and may be different than you would expect based purely on the median projection. Likewise, the Edge of a bet is not the only indicator of if you should make the bet or not as the suggestion is using a base acceptable threshold to determine how much edge you should have for each stat category.')
|
470 |
+
if st.button("Reset Data/Load Data", key='reset7'):
|
471 |
+
st.cache_data.clear()
|
472 |
+
game_model, overall_stats, timestamp, prop_frame, prop_trends, pick_frame, market_props = init_baselines()
|
473 |
+
qb_stats = overall_stats[overall_stats['Position'] == 'QB']
|
474 |
+
qb_stats = qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
475 |
+
non_qb_stats = overall_stats[overall_stats['Position'] != 'QB']
|
476 |
+
non_qb_stats = non_qb_stats.drop_duplicates(subset=['Player', 'Position'])
|
477 |
+
team_dict = dict(zip(prop_frame['Player'], prop_frame['Team']))
|
478 |
+
t_stamp = f"Last Update: " + str(timestamp) + f" CST"
|
479 |
+
|
480 |
+
settings_container = st.empty()
|
481 |
+
df_hold_container = st.empty()
|
482 |
+
export_container = st.empty()
|
483 |
+
|
484 |
+
with settings_container.container():
|
485 |
+
col1, col2, col3, col4 = st.columns([3, 3, 3, 3])
|
486 |
+
with col1:
|
487 |
+
game_select_var = st.selectbox('Select prop source', options = ['Aggregate', 'Pick6'])
|
488 |
+
with col2:
|
489 |
+
book_select_var = st.selectbox('Select book', options = ['ALL', 'BET_365', 'DRAFTKINGS', 'FANDUEL', 'MGM', 'UNIBET', 'WILLIAM_HILL'])
|
490 |
+
if book_select_var == 'ALL':
|
491 |
+
book_selections = ['BET_365', 'DRAFTKINGS', 'FANDUEL', 'MGM', 'UNIBET', 'WILLIAM_HILL']
|
492 |
+
else:
|
493 |
+
book_selections = [book_select_var]
|
494 |
+
if game_select_var == 'Aggregate':
|
495 |
+
prop_df = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
496 |
+
elif game_select_var == 'Pick6':
|
497 |
+
prop_df = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
498 |
+
book_selections = ['Pick6']
|
499 |
+
with col3:
|
500 |
+
if game_select_var == 'Aggregate':
|
501 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
502 |
+
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS'])
|
503 |
+
elif game_select_var == 'Pick6':
|
504 |
+
prop_type_var = st.selectbox('Select prop category', options = ['All Props', 'Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Rushing Attempts', 'Rushing Yards', 'Receptions', 'Receiving Yards', 'Receiving TDs'])
|
505 |
+
with col4:
|
506 |
+
st.download_button(
|
507 |
+
label="Download Prop Source",
|
508 |
+
data=convert_df_to_csv(prop_df),
|
509 |
+
file_name='NFL_prop_source.csv',
|
510 |
+
mime='text/csv',
|
511 |
+
key='prop_source',
|
512 |
+
)
|
513 |
+
|
514 |
+
if st.button('Simulate Prop Category'):
|
515 |
+
|
516 |
+
with df_hold_container.container():
|
517 |
+
if prop_type_var == 'All Props':
|
518 |
+
if game_select_var == 'Aggregate':
|
519 |
+
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
520 |
+
sim_vars = ['NFL_GAME_PLAYER_PASSING_YARDS', 'NFL_GAME_PLAYER_RUSHING_YARDS', 'NFL_GAME_PLAYER_PASSING_ATTEMPTS', 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS', 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS',
|
521 |
+
'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS', 'NFL_GAME_PLAYER_RECEIVING_YARDS', 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
522 |
+
elif game_select_var == 'Pick6':
|
523 |
+
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
524 |
+
sim_vars = ['Rush + Rec Yards', 'Rush + Rec TDs', 'Passing Yards', 'Passing Attempts', 'Passing TDs', 'Rushing Attempts', 'Rushing Yards', 'Receptions', 'Receiving Yards', 'Receiving TDs']
|
525 |
+
|
526 |
+
player_df = overall_stats.copy()
|
527 |
+
|
528 |
+
for prop in sim_vars:
|
529 |
+
|
530 |
+
for books in book_selections:
|
531 |
+
prop_df = prop_df_raw[prop_df_raw['book'] == books]
|
532 |
+
prop_df = prop_df[prop_df['prop_type'] == prop]
|
533 |
+
prop_df = prop_df[~((prop_df['over_prop'] < 15) & (prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_YARDS'))]
|
534 |
+
prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
535 |
+
prop_df.rename(columns={"over_prop": "Prop"}, inplace = True)
|
536 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
537 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
538 |
+
|
539 |
+
prop_dict = dict(zip(prop_df.Player, prop_df.Prop))
|
540 |
+
prop_type_dict = dict(zip(prop_df.Player, prop_df.prop_type))
|
541 |
+
book_dict = dict(zip(prop_df.Player, prop_df.book))
|
542 |
+
over_dict = dict(zip(prop_df.Player, prop_df.Over))
|
543 |
+
under_dict = dict(zip(prop_df.Player, prop_df.Under))
|
544 |
+
trending_over_dict = dict(zip(prop_df.Player, prop_df['Trending Over']))
|
545 |
+
trending_under_dict = dict(zip(prop_df.Player, prop_df['Trending Under']))
|
546 |
+
|
547 |
+
player_df['book'] = player_df['Player'].map(book_dict)
|
548 |
+
player_df['Prop'] = player_df['Player'].map(prop_dict)
|
549 |
+
player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
|
550 |
+
player_df['Trending Over'] = player_df['Player'].map(trending_over_dict)
|
551 |
+
player_df['Trending Under'] = player_df['Player'].map(trending_under_dict)
|
552 |
+
|
553 |
+
df = player_df.reset_index(drop=True)
|
554 |
+
|
555 |
+
team_dict = dict(zip(df.Player, df.Team))
|
556 |
+
|
557 |
+
total_sims = 1000
|
558 |
+
|
559 |
+
df.replace("", 0, inplace=True)
|
560 |
+
|
561 |
+
if prop == "NFL_GAME_PLAYER_PASSING_YARDS" or prop == "Passing Yards":
|
562 |
+
df['Median'] = df['pass_yards']
|
563 |
+
elif prop == "NFL_GAME_PLAYER_RUSHING_YARDS" or prop == "Rushing Yards":
|
564 |
+
df['Median'] = df['rush_yards']
|
565 |
+
elif prop == "NFL_GAME_PLAYER_PASSING_ATTEMPTS" or prop == "Passing Attempts":
|
566 |
+
df['Median'] = df['pass_att']
|
567 |
+
elif prop == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS" or prop == "Passing TDs":
|
568 |
+
df['Median'] = df['pass_tds']
|
569 |
+
elif prop == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS" or prop == "Rushing Attempts":
|
570 |
+
df['Median'] = df['rush_att']
|
571 |
+
elif prop == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS" or prop == "Receptions":
|
572 |
+
df['Median'] = df['rec']
|
573 |
+
elif prop == "NFL_GAME_PLAYER_RECEIVING_YARDS" or prop == "Receiving Yards":
|
574 |
+
df['Median'] = df['rec_yards']
|
575 |
+
elif prop == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS" or prop == "Receiving TDs":
|
576 |
+
df['Median'] = df['rec_tds']
|
577 |
+
elif prop == "Rush + Rec Yards":
|
578 |
+
df['Median'] = df['rush_yards'] + df['rec_yards']
|
579 |
+
elif prop == "Rush + Rec TDs":
|
580 |
+
df['Median'] = df['rush_tds'] + df['rec_tds']
|
581 |
+
|
582 |
+
flex_file = df.copy()
|
583 |
+
flex_file['Floor'] = flex_file['Median'] * .25
|
584 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
585 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
586 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
587 |
+
flex_file = flex_file[['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
588 |
+
|
589 |
+
hold_file = flex_file.copy()
|
590 |
+
overall_file = flex_file.copy()
|
591 |
+
prop_file = flex_file.copy()
|
592 |
+
|
593 |
+
overall_players = overall_file[['Player']]
|
594 |
+
|
595 |
+
for x in range(0,total_sims):
|
596 |
+
prop_file[x] = prop_file['Prop']
|
597 |
+
|
598 |
+
prop_file = prop_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
599 |
+
|
600 |
+
for x in range(0,total_sims):
|
601 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
602 |
+
|
603 |
+
overall_file=overall_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
604 |
+
|
605 |
+
players_only = hold_file[['Player']]
|
606 |
+
|
607 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
608 |
+
|
609 |
+
prop_check = (overall_file - prop_file)
|
610 |
+
|
611 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
612 |
+
players_only['Book'] = players_only['Player'].map(book_dict)
|
613 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
614 |
+
players_only['Trending Over'] = players_only['Player'].map(trending_over_dict)
|
615 |
+
players_only['Trending Under'] = players_only['Player'].map(trending_under_dict)
|
616 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
617 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
618 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
619 |
+
players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
620 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
621 |
+
players_only['Over%'] = players_only[["Over", "Imp Over", "Trending Over"]].mean(axis=1)
|
622 |
+
players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
623 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
624 |
+
players_only['Under%'] = players_only[["Under", "Imp Under", "Trending Under"]].mean(axis=1)
|
625 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
626 |
+
players_only['prop_threshold'] = .10
|
627 |
+
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
628 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
629 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
630 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
631 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
632 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
633 |
+
players_only['Edge'] = players_only['Bet_check']
|
634 |
+
players_only['Prop Type'] = prop
|
635 |
+
|
636 |
+
players_only['Player'] = hold_file[['Player']]
|
637 |
+
players_only['Team'] = players_only['Player'].map(team_dict)
|
638 |
+
|
639 |
+
leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge']]
|
640 |
+
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
641 |
+
|
642 |
+
final_outcomes = sim_all_hold
|
643 |
+
st.write(f'finished {prop} for {books}')
|
644 |
+
|
645 |
+
elif prop_type_var != 'All Props':
|
646 |
+
|
647 |
+
player_df = overall_stats.copy()
|
648 |
+
|
649 |
+
if game_select_var == 'Aggregate':
|
650 |
+
prop_df_raw = prop_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
651 |
+
elif game_select_var == 'Pick6':
|
652 |
+
prop_df_raw = pick_frame[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
653 |
+
|
654 |
+
for books in book_selections:
|
655 |
+
prop_df = prop_df_raw[prop_df_raw['book'] == books]
|
656 |
+
|
657 |
+
if prop_type_var == "NFL_GAME_PLAYER_PASSING_YARDS":
|
658 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_YARDS']
|
659 |
+
elif prop_type_var == "Passing Yards":
|
660 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Passing Yards']
|
661 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_YARDS":
|
662 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_YARDS']
|
663 |
+
elif prop_type_var == "Rushing Yards":
|
664 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rushing Yards']
|
665 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_ATTEMPTS":
|
666 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_ATTEMPTS']
|
667 |
+
elif prop_type_var == "Passing Attempts":
|
668 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Passing Attempts']
|
669 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS":
|
670 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_PASSING_TOUCHDOWNS']
|
671 |
+
elif prop_type_var == "Passing TDs":
|
672 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Passing TDs']
|
673 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS":
|
674 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RUSHING_ATTEMPTS']
|
675 |
+
elif prop_type_var == "Rushing Attempts":
|
676 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rushing Attempts']
|
677 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS":
|
678 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_RECEPTIONS']
|
679 |
+
elif prop_type_var == "Receptions":
|
680 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Receptions']
|
681 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_YARDS":
|
682 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_YARDS']
|
683 |
+
elif prop_type_var == "Receiving Yards":
|
684 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Receiving Yards']
|
685 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS":
|
686 |
+
prop_df = prop_df[prop_df['prop_type'] == 'NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS']
|
687 |
+
elif prop_type_var == "Receiving TDs":
|
688 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Receiving TDs']
|
689 |
+
elif prop_type_var == "Rush + Rec Yards":
|
690 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rush + Rec Yards']
|
691 |
+
elif prop_type_var == "Rush + Rec TDs":
|
692 |
+
prop_df = prop_df[prop_df['prop_type'] == 'Rush + Rec TDs']
|
693 |
+
|
694 |
+
prop_df = prop_df[['Player', 'book', 'over_prop', 'over_line', 'under_line', 'prop_type', 'Trending Over', 'Trending Under']]
|
695 |
+
prop_df = prop_df.rename(columns={"over_prop": "Prop"})
|
696 |
+
prop_df['Over'] = 1 / prop_df['over_line']
|
697 |
+
prop_df['Under'] = 1 / prop_df['under_line']
|
698 |
+
|
699 |
+
prop_dict = dict(zip(prop_df.Player, prop_df.Prop))
|
700 |
+
prop_type_dict = dict(zip(prop_df.Player, prop_df.prop_type))
|
701 |
+
book_dict = dict(zip(prop_df.Player, prop_df.book))
|
702 |
+
over_dict = dict(zip(prop_df.Player, prop_df.Over))
|
703 |
+
under_dict = dict(zip(prop_df.Player, prop_df.Under))
|
704 |
+
trending_over_dict = dict(zip(prop_df.Player, prop_df['Trending Over']))
|
705 |
+
trending_under_dict = dict(zip(prop_df.Player, prop_df['Trending Under']))
|
706 |
+
|
707 |
+
player_df['book'] = player_df['Player'].map(book_dict)
|
708 |
+
player_df['Prop'] = player_df['Player'].map(prop_dict)
|
709 |
+
player_df['prop_type'] = player_df['Player'].map(prop_type_dict)
|
710 |
+
player_df['Trending Over'] = player_df['Player'].map(trending_over_dict)
|
711 |
+
player_df['Trending Under'] = player_df['Player'].map(trending_under_dict)
|
712 |
+
|
713 |
+
df = player_df.reset_index(drop=True)
|
714 |
+
|
715 |
+
team_dict = dict(zip(df.Player, df.Team))
|
716 |
+
|
717 |
+
total_sims = 1000
|
718 |
+
|
719 |
+
df.replace("", 0, inplace=True)
|
720 |
+
|
721 |
+
if prop_type_var == "NFL_GAME_PLAYER_PASSING_YARDS" or prop_type_var == "Passing Yards":
|
722 |
+
df['Median'] = df['pass_yards']
|
723 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_YARDS" or prop_type_var == "Rushing Yards":
|
724 |
+
df['Median'] = df['rush_yards']
|
725 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_ATTEMPTS" or prop_type_var == "Passing Attempts":
|
726 |
+
df['Median'] = df['pass_att']
|
727 |
+
elif prop_type_var == "NFL_GAME_PLAYER_PASSING_TOUCHDOWNS" or prop_type_var == "Passing TDs":
|
728 |
+
df['Median'] = df['pass_tds']
|
729 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RUSHING_ATTEMPTS" or prop_type_var == "Rushing Attempts":
|
730 |
+
df['Median'] = df['rush_att']
|
731 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_RECEPTIONS" or prop_type_var == "Receptions":
|
732 |
+
df['Median'] = df['rec']
|
733 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_YARDS" or prop_type_var == "Receiving Yards":
|
734 |
+
df['Median'] = df['rec_yards']
|
735 |
+
elif prop_type_var == "NFL_GAME_PLAYER_RECEIVING_TOUCHDOWNS" or prop_type_var == "Receiving TDs":
|
736 |
+
df['Median'] = df['rec_tds']
|
737 |
+
elif prop_type_var == "Rush + Rec Yards":
|
738 |
+
df['Median'] = df['rush_yards'] + df['rec_yards']
|
739 |
+
elif prop_type_var == "Rush + Rec TDs":
|
740 |
+
df['Median'] = df['rush_tds'] + df['rec_tds']
|
741 |
+
|
742 |
+
flex_file = df.copy()
|
743 |
+
flex_file['Floor'] = flex_file['Median'] * .25
|
744 |
+
flex_file['Ceiling'] = flex_file['Median'] + (flex_file['Median'] * 1.75)
|
745 |
+
flex_file['STD'] = flex_file['Median'] / 4
|
746 |
+
flex_file['Prop'] = flex_file['Player'].map(prop_dict)
|
747 |
+
flex_file = flex_file[['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD']]
|
748 |
+
|
749 |
+
hold_file = flex_file.copy()
|
750 |
+
overall_file = flex_file.copy()
|
751 |
+
prop_file = flex_file.copy()
|
752 |
+
|
753 |
+
overall_players = overall_file[['Player']]
|
754 |
+
|
755 |
+
for x in range(0,total_sims):
|
756 |
+
prop_file[x] = prop_file['Prop']
|
757 |
+
|
758 |
+
prop_file = prop_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
759 |
+
|
760 |
+
for x in range(0,total_sims):
|
761 |
+
overall_file[x] = np.random.normal(overall_file['Median'],overall_file['STD'])
|
762 |
+
|
763 |
+
overall_file=overall_file.drop(['Player', 'book', 'Prop', 'Floor', 'Median', 'Ceiling', 'STD'], axis=1)
|
764 |
+
|
765 |
+
players_only = hold_file[['Player']]
|
766 |
+
|
767 |
+
player_outcomes = pd.merge(players_only, overall_file, left_index=True, right_index=True)
|
768 |
+
|
769 |
+
prop_check = (overall_file - prop_file)
|
770 |
+
|
771 |
+
players_only['Mean_Outcome'] = overall_file.mean(axis=1)
|
772 |
+
players_only['Book'] = players_only['Player'].map(book_dict)
|
773 |
+
players_only['Prop'] = players_only['Player'].map(prop_dict)
|
774 |
+
players_only['Trending Over'] = players_only['Player'].map(trending_over_dict)
|
775 |
+
players_only['Trending Under'] = players_only['Player'].map(trending_under_dict)
|
776 |
+
players_only['poisson_var'] = players_only.apply(calculate_poisson, axis=1)
|
777 |
+
players_only['10%'] = overall_file.quantile(0.1, axis=1)
|
778 |
+
players_only['90%'] = overall_file.quantile(0.9, axis=1)
|
779 |
+
players_only['Over'] = np_where(players_only['Prop'] <= 3, players_only['poisson_var'], prop_check[prop_check > 0].count(axis=1)/float(total_sims))
|
780 |
+
players_only['Imp Over'] = players_only['Player'].map(over_dict)
|
781 |
+
players_only['Over%'] = players_only[["Over", "Imp Over", "Trending Over"]].mean(axis=1)
|
782 |
+
players_only['Under'] = np_where(players_only['Prop'] <= 3, 1 - players_only['poisson_var'], prop_check[prop_check < 0].count(axis=1)/float(total_sims))
|
783 |
+
players_only['Imp Under'] = players_only['Player'].map(under_dict)
|
784 |
+
players_only['Under%'] = players_only[["Under", "Imp Under", "Trending Under"]].mean(axis=1)
|
785 |
+
players_only['Prop_avg'] = players_only['Prop'].mean() / 100
|
786 |
+
players_only['prop_threshold'] = .10
|
787 |
+
players_only = players_only[players_only['Mean_Outcome'] > 0]
|
788 |
+
players_only['Over_diff'] = players_only['Over%'] - players_only['Imp Over']
|
789 |
+
players_only['Under_diff'] = players_only['Under%'] - players_only['Imp Under']
|
790 |
+
players_only['Bet_check'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], players_only['Over_diff'] , players_only['Under_diff'])
|
791 |
+
players_only['Bet_suggest'] = np.where(players_only['Over_diff'] > players_only['Under_diff'], "Over" , "Under")
|
792 |
+
players_only['Bet?'] = np.where(players_only['Bet_check'] >= players_only['prop_threshold'], players_only['Bet_suggest'], "No Bet")
|
793 |
+
players_only['Edge'] = players_only['Bet_check']
|
794 |
+
players_only['Prop Type'] = prop_type_var
|
795 |
+
|
796 |
+
players_only['Player'] = hold_file[['Player']]
|
797 |
+
players_only['Team'] = players_only['Player'].map(team_dict)
|
798 |
+
|
799 |
+
leg_outcomes = players_only[['Player', 'Team', 'Book', 'Prop Type', 'Prop', 'Mean_Outcome', 'Imp Over', 'Trending Over', 'Over%', 'Imp Under', 'Trending Under', 'Under%', 'Bet?', 'Edge']]
|
800 |
+
sim_all_hold = pd.concat([sim_all_hold, leg_outcomes], ignore_index=True)
|
801 |
+
|
802 |
+
final_outcomes = sim_all_hold
|
803 |
+
st.write(f'finished {prop_type_var} for {books}')
|
804 |
+
|
805 |
+
final_outcomes = final_outcomes.dropna()
|
806 |
+
if game_select_var == 'Pick6':
|
807 |
+
final_outcomes = final_outcomes.drop_duplicates(subset=['Player', 'Prop Type'])
|
808 |
+
final_outcomes = final_outcomes.sort_values(by='Edge', ascending=False)
|
809 |
|
810 |
+
with df_hold_container:
|
811 |
+
df_hold_container = st.empty()
|
812 |
+
st.dataframe(final_outcomes.style.background_gradient(axis=0).background_gradient(cmap='RdYlGn').format(precision=2), use_container_width = True)
|
813 |
+
with export_container:
|
814 |
+
export_container = st.empty()
|
815 |
+
st.download_button(
|
816 |
+
label="Export Projections",
|
817 |
+
data=convert_df_to_csv(final_outcomes),
|
818 |
+
file_name='NFL_prop_proj.csv',
|
819 |
+
mime='text/csv',
|
820 |
+
key='prop_proj',
|
821 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|