BraydenMoore commited on
Commit
c1442da
1 Parent(s): 1690aaa

Auto-populate lines

Browse files
Files changed (2) hide show
  1. Templates/index.html +40 -13
  2. main.py +22 -0
Templates/index.html CHANGED
@@ -243,6 +243,25 @@
243
  transition: 0.3s ease;
244
  }
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
 
247
  @media screen and (max-width: 768px) {
248
  .winner-wrapper, .over-under-wrapper{
@@ -337,8 +356,10 @@
337
  const pulled_games = await response.json();
338
  const table = document.getElementById('gameTable');
339
  const columns = ['Date','Away Team', 'Home Team'];
 
 
340
 
341
- pulled_games.forEach((game) => {
342
  const row = table.insertRow(-1);
343
 
344
  columns.forEach((column) => {
@@ -353,12 +374,13 @@
353
  cell.textContent = game[column];
354
  }
355
  });
356
-
357
  for (let i = 0; i < 3; i++) {
358
  const cell = row.insertCell(-1);
359
  if (i<1) {
360
  const input = document.createElement('input');
361
  input.type = 'text';
 
362
  cell.appendChild(input);
363
  }
364
  }
@@ -370,14 +392,23 @@
370
 
371
  function submitData() {
372
  const predictButton = document.getElementById('submitButton');
 
373
  const table = document.getElementById('gameTable');
374
  const rows = table.querySelectorAll('tr');
375
  const games = [];
376
 
377
- predictButton.textContent = 'Predicting...';
378
-
379
  rows.forEach((row, index) => {
380
  if (index === 0) return;
 
 
 
 
 
 
 
 
 
 
381
  const cells = row.querySelectorAll('td');
382
  const game = {};
383
 
@@ -389,6 +420,7 @@
389
  games.push(game);
390
  });
391
 
 
392
  fetch('/submit_games', {
393
  method: 'POST',
394
  headers: {
@@ -404,10 +436,11 @@
404
 
405
  data.moneylines.forEach((moneyline, index) => {
406
  const row = rows[parseInt(moneyline.rowIndex) + 1];
407
-
408
  const winnerCell = row.cells[row.cells.length - 2];
 
409
  winnerCell.innerHTML = '';
410
-
411
  const wrapperDiv = document.createElement('div');
412
  wrapperDiv.className = 'winner-wrapper';
413
 
@@ -435,13 +468,10 @@
435
  winnerImg.classList.remove('hidden');
436
  }, 10);
437
 
438
- const winnerOverlayDiv = document.createElement('div');
439
- winnerOverlayDiv.className = 'overlay';
440
- winnerOverlayDiv.textContent = `${(moneyline.Probabilities[0] * 100).toFixed(2)}%`;
441
- //wrapperDiv.appendChild(winnerOverlayDiv);
442
  winnerCell.appendChild(wrapperDiv);
443
 
444
  const overUnderCell = row.cells[row.cells.length - 1];
 
445
  overUnderCell.innerHTML = '';
446
 
447
  const overUnderDiv = document.createElement('div');
@@ -480,15 +510,12 @@
480
  const overUnderOverlayDiv = document.createElement('div');
481
  overUnderOverlayDiv.className = 'overlay';
482
  overUnderOverlayDiv.textContent = `${(data.over_unders[index]['Probability'][0] * 100).toFixed(2)}%`;
483
- //overUnderDiv.appendChild(overUnderOverlayDiv);
484
-
485
  overUnderCell.appendChild(overUnderDiv);
486
 
487
  });
488
  }
489
  });
490
 
491
- predictButton.textContent = 'Predict';
492
  }
493
 
494
  document.getElementById('submitButton').addEventListener('click', submitData);
 
243
  transition: 0.3s ease;
244
  }
245
 
246
+ .spinner {
247
+ margin: auto;
248
+ display: block;
249
+ border: 2px solid transparent;
250
+ border-radius: 50%;
251
+ border-top: 2px solid #6a6a6a;
252
+ width: 16px;
253
+ height: 16px;
254
+ animation: spin 1s linear infinite;
255
+ }
256
+
257
+ @keyframes spin {
258
+ 0% {
259
+ transform: rotate(0deg);
260
+ }
261
+ 100% {
262
+ transform: rotate(360deg);
263
+ }
264
+ }
265
 
266
  @media screen and (max-width: 768px) {
267
  .winner-wrapper, .over-under-wrapper{
 
356
  const pulled_games = await response.json();
357
  const table = document.getElementById('gameTable');
358
  const columns = ['Date','Away Team', 'Home Team'];
359
+ const lines_response = await fetch('/get_lines');
360
+ const lines = await lines_response.json()
361
 
362
+ pulled_games.forEach((game, index) => {
363
  const row = table.insertRow(-1);
364
 
365
  columns.forEach((column) => {
 
374
  cell.textContent = game[column];
375
  }
376
  });
377
+
378
  for (let i = 0; i < 3; i++) {
379
  const cell = row.insertCell(-1);
380
  if (i<1) {
381
  const input = document.createElement('input');
382
  input.type = 'text';
383
+ input.value = lines[index];
384
  cell.appendChild(input);
385
  }
386
  }
 
392
 
393
  function submitData() {
394
  const predictButton = document.getElementById('submitButton');
395
+
396
  const table = document.getElementById('gameTable');
397
  const rows = table.querySelectorAll('tr');
398
  const games = [];
399
 
 
 
400
  rows.forEach((row, index) => {
401
  if (index === 0) return;
402
+
403
+ const winnerCell = row.cells[row.cells.length - 2];
404
+ const overUnderCell = row.cells[row.cells.length - 1];
405
+ const spinnerDiv = document.createElement('div');
406
+ spinnerDiv.className = 'spinner';
407
+ winnerCell.innerHTML = '';
408
+ overUnderCell.innerHTML = '';
409
+ winnerCell.appendChild(spinnerDiv);
410
+ overUnderCell.appendChild(spinnerDiv.cloneNode(true));
411
+
412
  const cells = row.querySelectorAll('td');
413
  const game = {};
414
 
 
420
  games.push(game);
421
  });
422
 
423
+
424
  fetch('/submit_games', {
425
  method: 'POST',
426
  headers: {
 
436
 
437
  data.moneylines.forEach((moneyline, index) => {
438
  const row = rows[parseInt(moneyline.rowIndex) + 1];
439
+
440
  const winnerCell = row.cells[row.cells.length - 2];
441
+ winnerCell.removeChild(winnerCell.querySelector('.spinner'));
442
  winnerCell.innerHTML = '';
443
+
444
  const wrapperDiv = document.createElement('div');
445
  wrapperDiv.className = 'winner-wrapper';
446
 
 
468
  winnerImg.classList.remove('hidden');
469
  }, 10);
470
 
 
 
 
 
471
  winnerCell.appendChild(wrapperDiv);
472
 
473
  const overUnderCell = row.cells[row.cells.length - 1];
474
+ overUnderCell.removeChild(overUnderCell.querySelector('.spinner'));
475
  overUnderCell.innerHTML = '';
476
 
477
  const overUnderDiv = document.createElement('div');
 
510
  const overUnderOverlayDiv = document.createElement('div');
511
  overUnderOverlayDiv.className = 'overlay';
512
  overUnderOverlayDiv.textContent = `${(data.over_unders[index]['Probability'][0] * 100).toFixed(2)}%`;
 
 
513
  overUnderCell.appendChild(overUnderDiv);
514
 
515
  });
516
  }
517
  });
518
 
 
519
  }
520
 
521
  document.getElementById('submitButton').addEventListener('click', submitData);
main.py CHANGED
@@ -10,6 +10,24 @@ pd.set_option('display.expand_frame_repr', False)
10
  import os
11
  import json
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  # get week, season
14
  week, season = predict.get_week()
15
 
@@ -22,6 +40,10 @@ games = predict.get_games(week)[['Date','Away Team','Home Team']]
22
  def index():
23
  return render_template('index.html')
24
 
 
 
 
 
25
  @app.route('/get_games')
26
  def get_games():
27
  return jsonify(games.to_dict(orient='records'))
 
10
  import os
11
  import json
12
 
13
+ # input the over/under lines here for quicker predictions!
14
+ lines = [49,
15
+ 40.5,
16
+ 47,
17
+ 46,
18
+ 47,
19
+ 39.5,
20
+ 51.5,
21
+ 41,
22
+ 45.5,
23
+ 40,
24
+ 44.5,
25
+ 38,
26
+ 39,
27
+ 46,
28
+ 39.5,
29
+ 38]
30
+
31
  # get week, season
32
  week, season = predict.get_week()
33
 
 
40
  def index():
41
  return render_template('index.html')
42
 
43
+ @app.route('/get_lines')
44
+ def get_lines():
45
+ return jsonify(lines)
46
+
47
  @app.route('/get_games')
48
  def get_games():
49
  return jsonify(games.to_dict(orient='records'))