File size: 4,456 Bytes
2e74090
 
 
 
10e8968
2e74090
 
 
 
 
09a3d56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
---
title: Paydirt Model Updates
emoji: πŸ’
colorFrom: red
colorTo: yellow
sdk: docker
app_port: 8501
pinned: false
---

# πŸ’ Paydirt NHL Model Updates

A Streamlit application for generating NHL DFS lineup projections and updating model data in real-time.

## Features

- **NHL Lineup Generation**: Automated lineup optimization for DraftKings and FanDuel
- **Real-time Updates**: Integrates with Google Sheets for live data updates
- **Multiple Platforms**: Supports both DK and FD contests
- **Ownership Projections**: ML-powered ownership predictions using XGBoost, LightGBM, and KNN models
- **Discord Notifications**: Automatic notifications when updates complete
- **MongoDB Integration**: Stores historical data and projections

## Architecture

- **Python/Streamlit**: Web interface and data processing
- **Go**: High-performance lineup generation
- **MongoDB**: Data storage and retrieval
- **Google Sheets API**: Live data integration
- **Docker**: Containerized deployment

## Setup

### Local Development

1. **Install Dependencies**
```bash
pip install -r requirements.txt
```

2. **Configure Secrets**

Create `.streamlit/secrets.toml`:
```toml
MONGODB_URI = "your-mongodb-uri"
GOOGLE_PROJECT_ID_1 = "your-project-id"
# ... (see .streamlit/secrets.toml.example for full template)
```

3. **Build Go Programs** (if developing locally on Windows)
```bash
cd func/dk_nhl_go
go build -o NHL_seed_frames.exe NHL_seed_frames.go

cd ../fd_nhl_go
go build -o NHL_seed_frames.exe NHL_seed_frames.go
```

4. **Run the App**
```bash
streamlit run src/streamlit_app.py
```

### Hugging Face Deployment

This app is configured for deployment on Hugging Face Spaces using Docker.

1. **Create a Space** on Hugging Face with Docker SDK
2. **Add Secrets** in Space settings (Settings β†’ Repository secrets)
   - Add all variables from `.streamlit/secrets.toml.example`
3. **Push Code** to your Space repository
4. The Docker build will automatically:
   - Build Go programs for Linux
   - Install Python dependencies
   - Configure the environment

## Project Structure

```
Paydirt_model_updates/
β”œβ”€β”€ src/
β”‚   └── streamlit_app.py      # Main Streamlit application
β”œβ”€β”€ func/
β”‚   β”œβ”€β”€ NHL_own_regress.py    # Ownership prediction models
β”‚   β”œβ”€β”€ dk_nhl_go/            # DraftKings lineup generator (Go)
β”‚   └── fd_nhl_go/            # FanDuel lineup generator (Go)
β”œβ”€β”€ Dockerfile                # Docker configuration
β”œβ”€β”€ requirements.txt          # Python dependencies
β”œβ”€β”€ go.mod                    # Go module definition
└── README.md                 # This file
```

## Technologies Used

### Python Stack
- **Streamlit**: Web interface
- **pandas**: Data manipulation
- **numpy**: Numerical operations
- **xgboost/lightgbm/scikit-learn**: Machine learning models
- **pymongo**: MongoDB client
- **gspread**: Google Sheets API
- **ortools**: Linear optimization

### Go Stack
- **MongoDB Driver**: Database connectivity
- High-performance lineup generation algorithms

## Environment Variables

Required environment variables (can be set in `.streamlit/secrets.toml` or as environment variables):

| Variable | Description |
|----------|-------------|
| `MONGODB_URI` | MongoDB connection string |
| `GOOGLE_PROJECT_ID_1` | Google Cloud project ID (primary) |
| `GOOGLE_PRIVATE_KEY_1` | Service account private key (primary) |
| `GOOGLE_CLIENT_EMAIL_1` | Service account email (primary) |
| `GOOGLE_PROJECT_ID_2` | Google Cloud project ID (backup) |
| `GOOGLE_PRIVATE_KEY_2` | Service account private key (backup) |
| `GOOGLE_CLIENT_EMAIL_2` | Service account email (backup) |
| `DISCORD_WEBHOOK_URL` | Discord webhook for notifications |
| `MASTER_SHEET_URL` | Google Sheets URL for master data |

## Usage

1. Open the app in your browser
2. Check connection status in the sidebar
3. Click "πŸš€ Generate NHL Lineups" to start the process
4. Monitor progress as the app:
   - Builds prop betting tables
   - Generates player-level outcomes
   - Creates stack matrices
   - Runs lineup optimization
   - Updates MongoDB with results
   - Sends Discord notifications

## Security Notes

- Never commit `.streamlit/secrets.toml` to version control
- Use Hugging Face Secrets for production deployment
- Rotate service account keys regularly
- Keep MongoDB credentials secure

## License

Proprietary - Paydirt Sports

## Support

For issues or questions, contact the development team.