File size: 21,878 Bytes
3231b63
 
f74deb3
3231b63
 
6e0b380
3231b63
 
 
e8fe7a9
 
3231b63
03fec6a
3231b63
 
 
ea95b78
3231b63
 
 
 
 
 
29c9c90
3231b63
4e138ed
3231b63
 
 
 
 
 
 
 
 
db2eccf
3231b63
1a89c67
3231b63
0327077
3231b63
 
 
7600ef9
 
 
 
3231b63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16fb9b3
390b694
3231b63
 
072016f
 
3231b63
fb1925e
68bea89
 
 
072016f
3231b63
 
 
072016f
3231b63
 
 
 
 
b4b6b3c
3231b63
 
 
 
 
520b9b9
3231b63
 
1a89c67
3231b63
 
 
fc2b782
 
 
1a89c67
3231b63
 
 
fc2b782
26537a8
 
c8cf1db
3231b63
1a89c67
3231b63
 
 
 
 
 
1a89c67
3231b63
 
 
fc2b782
 
 
3231b63
 
0301780
3231b63
 
0301780
3231b63
 
fc2b782
3231b63
db2eccf
e3ac90c
45adebd
 
2aafbd7
e3ac90c
db2eccf
995112e
db2eccf
3231b63
 
 
db2eccf
3231b63
 
 
 
db2eccf
3231b63
 
 
 
 
 
 
 
db2eccf
3231b63
 
 
db2eccf
3231b63
 
 
 
 
 
db2eccf
3231b63
 
 
 
 
 
b4b6b3c
3231b63
db2eccf
3231b63
 
 
db2eccf
3231b63
 
 
db2eccf
4697c91
 
 
db2eccf
29c9c90
 
 
 
 
 
 
 
 
 
 
 
da2f1da
29c9c90
db2eccf
29c9c90
 
 
 
 
 
 
db2eccf
29c9c90
1579776
29c9c90
 
db2eccf
974b3b2
 
9c42f46
26537a8
4731ae2
db2eccf
c1442da
 
 
 
 
 
 
 
 
 
788d0f3
 
 
 
 
 
 
 
 
 
31a4695
788d0f3
db2eccf
f4f1524
b4b6b3c
7b7505e
84f21e6
7b7505e
c8cf1db
1a89c67
 
 
 
 
 
 
 
6e8090a
 
 
5f81d51
c1442da
 
 
 
 
 
 
 
db2eccf
f23a31d
e067f2c
 
 
 
69d6c33
8a28aaf
69d6c33
 
 
 
 
 
 
b4b6b3c
 
 
 
 
 
 
 
 
1d760ce
 
 
 
71b1efe
5804fd1
1d760ce
995112e
db2eccf
3231b63
29c9c90
 
 
 
 
 
 
3231b63
 
 
6a5cae4
788d0f3
b3b97dc
788d0f3
c06d9af
1422343
 
f23a31d
1a89c67
 
 
 
f23a31d
 
 
 
24c0fdf
 
5fcb670
0d8c46c
24c0fdf
f23a31d
 
 
3231b63
 
 
 
 
 
f4f1524
84f21e6
3231b63
 
 
27a162f
3231b63
246fd4b
3231b63
 
 
 
 
 
 
 
 
 
 
 
4ea0b49
 
3231b63
 
 
 
 
 
 
 
 
 
 
 
f4f1524
84f21e6
f4f1524
 
 
952abd1
f4f1524
 
 
952abd1
 
f4f1524
 
 
952abd1
f4f1524
 
 
952abd1
f4f1524
 
 
 
4697c91
9704cc0
 
 
3231b63
 
1a89c67
 
fc2b782
 
1a89c67
 
 
 
5f81d51
5fcb670
c1442da
 
db2eccf
c1442da
fc2b782
 
 
 
5fcb670
fc2b782
 
 
 
 
 
 
3d72e51
fc2b782
 
c1442da
fc2b782
 
 
 
 
c1442da
fc2b782
 
3231b63
fc2b782
3231b63
db2eccf
 
3231b63
a6e2f58
db2eccf
a6e2f58
 
 
db2eccf
a6e2f58
 
c1442da
 
 
 
 
 
 
 
 
db2eccf
a6e2f58
 
db2eccf
a6e2f58
 
 
 
 
 
 
db2eccf
 
a6e2f58
 
 
 
 
 
 
 
 
 
 
 
db2eccf
a6e2f58
 
db2eccf
a6e2f58
c1442da
a6e2f58
db2eccf
a6e2f58
 
bacfa3b
69d6c33
e980d8f
623a8f8
 
 
db2eccf
a6e2f58
 
 
 
 
 
db2eccf
a6e2f58
 
c8cf1db
1a89c67
623a8f8
a6e2f58
738a4c4
 
 
 
 
a6e2f58
 
623a8f8
1a89c67
a6e2f58
 
db2eccf
a6e2f58
 
 
db2eccf
a6e2f58
db2eccf
a6e2f58
c1442da
a6e2f58
db2eccf
a6e2f58
 
bacfa3b
69d6c33
e980d8f
623a8f8
 
 
db2eccf
a6e2f58
 
 
 
 
 
 
 
 
 
db2eccf
a6e2f58
db2eccf
a6e2f58
 
c8cf1db
de3c36c
623a8f8
de3c36c
a6e2f58
738a4c4
 
 
 
 
a6e2f58
 
623a8f8
1a89c67
a6e2f58
 
db2eccf
a6e2f58
 
 
c8cf1db
db2eccf
2634ee3
1a89c67
 
 
a6e2f58
 
3231b63
c8cf1db
1a89c67
c8cf1db
2634ee3
 
 
 
9177931
c8cf1db
4298351
9177931
 
 
 
 
4298351
4b7c989
4298351
 
 
 
 
2634ee3
 
4b7c989
 
 
 
9177931
4b7c989
 
4298351
2634ee3
 
 
4298351
2634ee3
4298351
2634ee3
3231b63
5f81d51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34dc9be
55b8464
5f81d51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3231b63
5f81d51
 
 
 
 
 
 
1a89c67
 
 
 
 
c8cf1db
 
3231b63
 
 
db2eccf
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
    <link rel="shortcut icon" type="image/x-icon" href="https://images.squarespace-cdn.com/content/v1/64790f5777b5d772678cce83/6d71eaee-f825-4324-be9b-2def32469eac/favicon.ico?format=100w">
    <title>MARCI - NFL Betting</title>
</head>
<style>
    body {
        max-width: 90vw;
        margin: auto;
        background-color: black;
        font-family: 'Helvetica';
        justify-content: center;
        text-align: center;
        padding-top: 2%;
        padding-bottom: 5%;
    }
    p {
        color: #f2f2f2;
    }
    h1 {
        color: #f2f2f2;
        margin-top: 40px;
        margin-bottom: 10px;
        font-size: xxx-large;
    }
    h2 {
        margin-top: 0px;
        color: #f2f2f2;
    }
    h3 {
        color: #f2f2f2;
        margin: 0px;
    }

    table {
        transition: 0.3s ease;
        margin-top: 20px;
        width: 80%;
        border-collapse: collapse;
        text-align: center;
    }
    .table-div {
        display: flex;
        justify-content: center;
    }
    th, td {
        color: #f2f2f2;
        border: 1px solid black;
        text-align: center;
        padding: 8px;
    }
    th {
        background-color: black;
    }
    tr {
        background-color: black;
    }
    tr:nth-child(even) {
        background-color: rgb(10, 10, 5);
    }
    td img {
        display: block;
        margin: auto;
    }
    input[type="text"] {
        font-size: 12pt;
        width: 45px;
        height: 30px;
        text-align: center;
        background-color: transparent;
        border-radius: 5px;
        transition: 0.3s ease;
        color: #f2f2f2;
        border: none;
    }    
    
    input[type="text"]:hover {
        background-color:rgb(30, 30, 30);    
    }
    button {
        font-size: 12pt;
        background-color: rgb(30, 30, 30);
        color: #ffffff; 
        padding: 10px 20px; 
        border: none;
        border-radius: 5px; 
        margin-top: 40px;
        width: 80%;
        transition: all 0.3s ease;  
    }
    button:hover {
        color: rgb(0, 0, 0);
        background-color: rgb(255, 255, 255);
        cursor: pointer;
    }
    .winner-wrapper {
        cursor: default;
        position: relative;
        width: 100%;  
        text-align: center; 
        display: flex;
        justify-content: center;
        align-items: center;
        transition: 0.3s ease;
    }
    .winner-image {
        height: auto;
        margin: 0;
        transition: 0.3s ease;
    }

    .over-under-wrapper {
        cursor: default;
        position: relative;
        width: 100%;
        height: 50px; 
        display: flex;
        align-items: center;  
        justify-content: center; 
        transition: 0.3s ease;
    }
    .over-under-text {
        display: inline-block;
        margin: 0;
        margin-right: 2px;
        font-weight: bold;
    }
    .over {
        color: rgb(255, 255, 255);
    }
    .under {
        color: rgb(255, 255, 255);
    }
    .na {
        color: white;
    }

    .highlight {
        background: rgb(30, 30, 30) !important;
        border: 2px solid rgb(30, 30, 30)  !important;
        border-radius: 10px  !important;
    }

    .force-repaint { transform: translateZ(0); }

    .hidden {
        opacity: 0;
    }

    .section-container {
        display: flex;
        justify-content: space-between;
    }

    .section {
        padding: 30px;
        text-align: left;
        border-style: solid;
        border-width: 1px;
        border-color: rgb(61, 61, 61);
        width: 48%; 
    }

    .content {
        width: 100%;
    }

    .content img {
        width: 100%;
        height: auto;
        margin-top: 20px;
        margin-bottom: 20px;
    }

    .divider {
        border: 0;
        height: 1px;
        background: rgb(61, 61, 61);
        margin-top: 50px;
        margin-bottom: 50px;
        width: 80%;
    }

    .label {
        color: rgb(114, 114, 114);
    }

    .info {
        color: white;
    }

    a {
      color: white;
    }

    .scroll-banner {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        z-index: 999;
        width: 100%;
        display: flex;
        align-items: center;
        height: 30px;
        background-color: green;
        overflow: hidden;
        visibility: hidden;
    }

    .scroll-text {
        font-family: 'Helvetica';
        color: white;
        display: inline-block;
        animation: scrolling 10s linear infinite;
        white-space: nowrap;
    }

    @keyframes scrolling {
        0% { transform: translateX(100vw); }
        100% { transform: translateX(-100%); }
    }

    .emoji {
        margin-left: 5px;
        color: rgb(255, 255, 255);
        transition: 0.3s ease;
    }

    .spinner {
        margin: auto;
        display: block;
        border: 2px solid transparent;
        border-radius: 50%;
        border-top: 2px solid #6a6a6a;
        width: 16px;
        height: 16px;
        animation: spin 1s linear infinite;
    }
    
    #gradient {
        background: red;
        background: -webkit-linear-gradient(left, orange , yellow, green, cyan, blue, violet);
        background: -o-linear-gradient(right, orange, yellow, green, cyan, blue, violet);
        background: -moz-linear-gradient(right, orange, yellow, green, cyan, blue, violet);
        background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet);
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        font-weight: bold;
    }

    .modelDetails {
        width: 80%;
        display: inline-block;
        margin-bottom: 40px;
    }

    #weekSelector {
        transition: 0.3s ease;
        border-radius: 10px;
        padding: 5px;
        color: white;
        background: rgb(30, 30, 30) !important;
        font-family: Arial, Helvetica, sans-serif;
    }
    #weekSelector:hover {
        opacity: 0.5;
    }

    @keyframes spin {
        0% {
            transform: rotate(0deg);
        }
        100% {
            transform: rotate(360deg);
        }
    }

    @media screen and (max-width: 768px) {
        .table-div {
            display: block;
            justify-content: center;
        }
        .winner-image {
            margin: 0;
        }
        .emoji {
            margin: 0;
        }
        .table-div{
            overflow-x: scroll;
        }
        .divider {
            width: 90%;
        }
        #modelDetails {
            width: 90%;
        }
        .button {
            width: 90%;
        }
        .section-container {
            display: inline;
        }
        .section {
            padding: 15px;
            width: auto;
        }
    }

</style>

<div class="scroll-banner">
    <div class="scroll-text">
      Predictions will begin at the conclusion of Week 1. Bet at your own risk. Know your limits. And most importantly, have fun!
    </div>
</div>

<body>
    <h1>M A R C I</h1>
    <div class="info">
        <span class="label"><i>Moore's Algorithm for Risky Capital Investments</i></span><br><br>

        <span id="gradient">"Just win baby!" -Al Davis</span><br><br>

        <span class="label"><b>Record through {{ latest_game }}</b></span><br>
        <span class="label">Winners:</span> {{ winners_correct }}-{{winners_incorrect}}{{winners_tie}}<span class="label"> ({{ winners_return }})</span><br>
        <span class="label">Over/Unders:</span> {{over_unders_correct}}-{{over_unders_incorrect}}{{over_unders_push}}<span class="label"> ({{over_unders_return}})</span><br><br>
    </div>

    <select id="weekSelector">
    </select>

    <div class="table-div">
        <table id="gameTable">
            <tr>
                <th>Date</th>
                <th>Away</th>
                <th>Home</th>
                <th>O/U</th>
                <th>Predicted Winner</th>
                <th>Predicted O/U</th>
            </tr>
        </table>
    </div>
    <button id="submitButton">
        Predict
    </button>

    <hr class="divider"> 

    <div class="modelDetails">
        <h2>Model Train/Test Details</h2>
        <div class="section-container">
            <div class="section">
                <h3>Moneyline</h3>
                <div class="info"></h3><span class="label">Test Accuracy:</span> 71.4%<br></div>
                <div class="content">
                    <img src="/Static/xgboost_ML_no_odds_71.4%25_dark.png" alt="Moneyline Model">
                    <div class="info">
                        <span class="label">Model:</span> XGBoost<br>
                        <span class="label">Train/Test Split:</span> 1782/199<br>
                        <span class="label">Max Depth:</span> 2<br>
                        <span class="label">Learning Rate:</span> 0.01<br>
                        <span class="label">Epochs:</span> 500
                    </div>
                </div>
            </div>
            <div class="section">
                <h3>Over/Under</h3>
                <div class="content">
                    <div class="info"></h3><span class="label">Test Accuracy:</span> 59.8%<br></div>
                    <img src="/Static/xgboost_OU_no_odds_59.8%25_dark.png" alt="Over/Under Model">
                    <div class="info">
                        <span class="label">Model:</span> XGBoost<br>
                        <span class="label">Train/Test Split:</span> 1782/199<br>
                        <span class="label">Max Depth:</span> 6<br>
                        <span class="label">Learning Rate:</span> 0.05<br>
                        <span class="label">Epochs:</span> 300
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modelDetails">
        <h2>Predictive Accuracy This Year</h2>
        <div class="section-container">
            <div class="section">
                <h3>Moneyline</h3>
                <div class="info">{{ winners_return }}.</div>
                <div class="content">
                    <img src="/Static/Winner_Predictions_dark.png" alt="Moneyline Accuracy">
                </div>
                <div class="info"><span class="label">{{ winners_binom }}</span><br></div>

            </div>
            <div class="section">
                <h3>Over/Under</h3>
                <div class="info">{{ over_unders_return }}.</div>
                <div class="content">
                    <img src="/Static/Over_Under_Predictions_dark.png" alt="Over/Under Model">
                </div>
                <div class="info"><span class="label">{{ over_unders_binom }}</span><br></div>
            </div>
        </div>
    </div>

    <p>πŸ€—<a href="https://huggingface.co/spaces/BraydenMoore/MARCI-NFL-Betting/tree/main">See the Code</a></p>


    

    <script>
    async function fetchGames(selectedWeek) {
        const response = await fetch(`/get_games?week=${selectedWeek}`);
        const pulled_games = await response.json();
        const table = document.getElementById('gameTable');
        
        for(let i = table.rows.length - 1; i > 0; i--) {
            table.deleteRow(i);
        }

        const columns = ['Date','Away Team', 'Home Team']; 
        const lines_response = await fetch('/get_lines');
        const lines = await lines_response.json()

        pulled_games.forEach((game, index) => {
            const row = table.insertRow(-1);
            
            columns.forEach((column) => {
                const cell = row.insertCell(-1);
                if (column === 'Away Team' || column === 'Home Team') {
                    const img = document.createElement('img');
                    img.src = `/Static/${game[column]}.webp`;
                    img.alt = game[column];
                    img.width = 50; 
                    cell.appendChild(img);
                } else {
                    cell.textContent = game[column];
                    cell.style.color = "rgb(114, 114, 114)";
                }
            });
            
            for (let i = 0; i < 3; i++) {
                const cell = row.insertCell(-1);
                if (i<1) {
                    const input = document.createElement('input');
                    input.type = 'text';
                    input.value = lines[index];
                    cell.appendChild(input);
                }
            }
            });
    }


    function submitData() {
        const predictButton = document.getElementById('submitButton');

        const table = document.getElementById('gameTable');
        const rows = table.querySelectorAll('tr');
        const games = [];

        rows.forEach((row, index) => {
            if (index === 0) return;
            
            const winnerCell = row.cells[row.cells.length - 2];
            const overUnderCell = row.cells[row.cells.length - 1];
            const spinnerDiv = document.createElement('div');
            spinnerDiv.className = 'spinner';
            winnerCell.innerHTML = ''; 
            overUnderCell.innerHTML = ''; 
            winnerCell.appendChild(spinnerDiv);
            overUnderCell.appendChild(spinnerDiv.cloneNode(true));

            const cells = row.querySelectorAll('td');
            const game = {};

            game.Date = cells[0].textContent;
            game.AwayTeam = cells[1].querySelector('img').alt;
            game.HomeTeam = cells[2].querySelector('img').alt;
            game.OverUnderLine = cells[3].querySelector('input').value;
            game.rowIndex = index - 1;  
            games.push(game);
        });


        fetch('/submit_games', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(games),
        })
        .then(response => response.json())
        .then(data => {
            if (data.moneylines && data.over_unders) {
                const table = document.getElementById('gameTable');
                const rows = table.querySelectorAll('tr');

                data.moneylines.forEach((moneyline, index) => {
                    const row = rows[parseInt(moneyline.rowIndex) + 1];

                    const winnerCell = row.cells[row.cells.length - 2];
                    winnerCell.removeChild(winnerCell.querySelector('.spinner'));
                    winnerCell.innerHTML = ''; 

                    const wrapperDiv = document.createElement('div');
                    wrapperDiv.className = 'winner-wrapper';
                    if (moneyline.Probabilities[0] > 0.6){
                        wrapperDiv.classList.add("highlight");
                    }
                    else {
                        wrapperDiv.style.opacity = "0.5";
                    }

                    const winnerImg = document.createElement('img');
                    winnerImg.src = `/Static/${moneyline.Winner}.webp`;
                    winnerImg.alt = moneyline.Winner;
                    winnerImg.width = 50;  
                    winnerImg.className = 'winner-image hidden';
                    wrapperDiv.appendChild(winnerImg);

                    const winnerEmojiDiv = document.createElement('div');
                    winnerEmojiDiv.className = 'emoji';

                    wrapperDiv.dataset.proba = (moneyline.Probabilities[0] * 100).toFixed(0);
                    if (moneyline.Winner[0] === moneyline.Result) {
                        winnerEmojiDiv.textContent = 'βœ…';
                    } 
                    else if (moneyline.Result === 'Tie') {
                        winnerEmojiDiv.textContent = '(TIE)';
                    }
                    else {
                        winnerEmojiDiv.textContent = '❌';
                    }
                    if (moneyline.Result === 'N/A') {
                        winnerEmojiDiv.textContent = `(${wrapperDiv.dataset.proba}%)`;
                    }
                    wrapperDiv.appendChild(winnerEmojiDiv);

                    setTimeout(() => {
                        winnerImg.classList.remove('hidden');
                    }, 10);

                    winnerCell.appendChild(wrapperDiv);

                    const overUnderCell = row.cells[row.cells.length - 1];
                    overUnderCell.removeChild(overUnderCell.querySelector('.spinner'));
                    overUnderCell.innerHTML = ''; 

                    const overUnderDiv = document.createElement('div');
                    overUnderDiv.className = 'over-under-wrapper hidden';
                    if (data.over_unders[index]['Probability'][0] > 0.6){
                        overUnderDiv.classList.add("highlight");
                    }
                    else {
                        overUnderDiv.style.opacity = "0.5";
                    }

                    const textDiv = document.createElement('div');
                    textDiv.className = 'over-under-text';
                    textDiv.textContent = data.over_unders[index]['Over/Under'];
                    if (textDiv.textContent === 'Over') {
                        overUnderDiv.className += ' over';
                    } else if (textDiv.textContent === 'Under') {
                        overUnderDiv.className += ' under';
                    } else {
                        overUnderDiv.className += ' na';
                    }

                    overUnderDiv.appendChild(textDiv);

                    const overEmojiDiv = document.createElement('div');
                    overEmojiDiv.className = 'emoji';

                    overUnderDiv.dataset.proba = Math.floor(data.over_unders[index]['Probability'][0] * 100).toFixed(0);
                    if (data.over_unders[index]['Over/Under'][0] === data.over_unders[index]['Result']) {
                        console.log(data.over_unders[index]['Result']);
                        overEmojiDiv.textContent = 'βœ…';
                    } 
                    else if (data.over_unders[index]['Over/Under'][0] === 'Push') {
                        overEmojiDiv.textContent = '(PUSH)';
                    }
                    else {
                        overEmojiDiv.textContent = '❌';
                    }
                    if (data.over_unders[index]['Result'] === 'N/A') {
                        overEmojiDiv.textContent = `(${overUnderDiv.dataset.proba}%)`;
                    }
                    overUnderDiv.appendChild(overEmojiDiv);

                    setTimeout(() => {
                        overUnderDiv.classList.remove('hidden');
                    }, 10);

                    overUnderCell.appendChild(overUnderDiv);

                    showProbabilityOnHover(wrapperDiv);
                    showProbabilityOnHover(overUnderDiv);
                    
                });
            }
            });

    }

    //Hover listener
    function showProbabilityOnHover(div) {
        let previousValue;
        let divText = div.children[1];
        let eventProcessed = false;

        function handleEnter() {
            if (eventProcessed) return;  // Skip if an event has already been processed

            eventProcessed = true;

            if (divText.textContent !== `(${div.dataset.proba}%)`) {
                divText.style.opacity = 0;

                setTimeout(() => {
                    previousValue = divText.textContent;
                    divText.textContent = `(${div.dataset.proba}%)`;
                    divText.style.opacity = 1;
                }, 300);

                setTimeout(() => {
                    divText.style.opacity = 0;
                    setTimeout(() => {
                        divText.textContent = previousValue;
                        divText.style.opacity = 1;
                        eventProcessed = false;  // Reset the flag
                    }, 300);
                }, 1000);
            }
        }

        // For desktop
        div.addEventListener('mouseenter', handleEnter);
        // For mobile
        div.addEventListener('touchstart', handleEnter);
    }

    // Populate dropdown
    let selectedWeek;
    async function populateDropdown() {
        const weekSelector = document.getElementById('weekSelector');
        weekSelector.innerHTML = "";

        const response = await fetch('/get_weeks');
        const data = await response.json();
        
        data.forEach((week, index) => {
            const option = document.createElement('option');
            option.value = week;
            option.text = `Week ${week}`;
            weekSelector.appendChild(option);

            if (index === 0) {
                selectedWeek = week;
            }
        });
    }
    
    
    // Get new games when new week selected
    document.getElementById('weekSelector').addEventListener('change', function(event) {
        selectedWeek = event.target.value;
        getNew();
    });


    // Initial load
    function loadThings() { 
        populateDropdown()
        .then(() => fetchGames(selectedWeek))
        .then(() => submitData())
        .catch(error => console.error(error));
    }

    // Get new
    async function getNew() {
        const table = document.getElementById('gameTable');
        table.style.opacity = "0.5";

        try {
            await fetchGames(selectedWeek);
            await submitData();
            table.style.opacity = "1";
        } catch (error) {
            console.error(error);
        }
    }


    // Submit on click, enter, and pageload
    loadThings();

    document.getElementById('submitButton').addEventListener('click', submitData);

    document.addEventListener('keydown', function(event) {
        if (event.keyCode === 13) {  
            submitData();
        }
    });


</script>

</body>
</html>