-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoddcode.js
More file actions
160 lines (143 loc) · 6.75 KB
/
oddcode.js
File metadata and controls
160 lines (143 loc) · 6.75 KB
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
document.addEventListener("DOMContentLoaded", function() {
let rightBox = document.getElementById("right");
let leftBox = document.getElementById("left");
let dropdownBtn = document.querySelector(".dropdown-btn");
let dropdownContent = document.querySelector(".dropdown-content");
const pickContainer = document.querySelector(".pick");
const oddsResult = document.getElementById("odds-result");
function closeAllDropdowns() {
dropdownContent.classList.remove("show");
}
dropdownBtn.addEventListener("click", function(event) {
event.stopPropagation();
dropdownContent.classList.toggle("show");
});
dropdownContent.addEventListener("click", function(event) {
event.preventDefault();
if (event.target.tagName === 'A') {
const selectedLeague = event.target.getAttribute('data-league');
dropdownBtn.textContent = event.target.textContent;
closeAllDropdowns();
displayTeams(selectedLeague);
}
});
// Lists of teams
function displayTeams(league) {
const leagueTeams = {
"premier-league": [
"Aston Villa F.C.", "Tottenham Hotspur F.C.", "Manchester United F.C.",
"West Ham United F.C.", "Newcastle United F.C.", "Brighton & Hove Albion F.C.",
"Wolverhampton Wanderers F.C.", "AFC Bournemouth", "Crystal Palace F.C.",
"Nottingham Forest F.C.", "Luton Town F.C.", "Sheffield United F.C.",
"Liverpool", "Manchester City", "Arsenal", "Chelsea", "Fulham",
"Brentford", "Everton", "Burnley"
],
"la-liga": [
"FC Barcelona", "RC Celta de Vigo", "Rayo Vallecano", "Real Valladolid",
"Villarreal CF", "Sevilla FC", "UD Las Palmas", "Atletico Madrid",
"CA Osasuna", "RCD Mallorca", "Getafe CF", "Girona FC", "Athletic Bilbao",
"Real Betis Seville", "CD Leganés", "Real Madrid", "Deportivo Alavés", "Valencia CF"
],
"bundesliga": [
"FC Bayern Munich", "VfL Bochum", "Borussia Dortmund", "Borussia Mönchengladbach",
"SV Werder Bremen", "VfL Wolfsburg", "VfB Stuttgart", "1. FSV Mainz 05",
"Bayer 04 Leverkusen", "SC Freiburg", "Eintracht Frankfurt", "TSG 1899 Hoffenheim",
"1. FC Union Berlin", "FC Augsburg", "1. FC Heidenheim", "RB Leipzig"
],
"eredivisie": [
"Ajax Amsterdam", "Almere City FC", "AZ Alkmaar", "FC Groningen",
"FC Twente Enschede", "FC Utrecht", "Feyenoord Rotterdam", "Fortuna Sittard",
"Go Ahead Eagles", "Heracles Almelo", "N.E.C. Nijmegen", "NAC Breda",
"PEC Zwolle", "PSV Eindhoven", "RKC Waalwijk", "SC Heerenveen",
"Sparta Rotterdam", "Willem II Tilburg"
],
"nba": [
"Atlanta Hawks", "Boston Celtics", "Brooklyn Nets", "Charlotte Hornets",
"Chicago Bulls", "Cleveland Cavaliers", "Dallas Mavericks", "Denver Nuggets",
"Detroit Pistons", "Golden State Warriors", "Houston Rockets", "Indiana Pacers",
"LA Clippers", "Los Angeles Lakers", "Memphis Grizzlies", "Miami Heat",
"Milwaukee Bucks", "Minnesota Timberwolves", "New Orleans Pelicans",
"New York Knicks", "Oklahoma City Thunder", "Orlando Magic", "Philadelphia 76ers",
"Phoenix Suns", "Portland Trail Blazers", "Sacramento Kings", "San Antonio Spurs",
"Toronto Raptors", "Utah Jazz", "Washington Wizards"
]
};
const teams = leagueTeams[league];
if (!teams) {
console.error("No teams found for league:", league);
return;
}
pickContainer.innerHTML = "";
teams.forEach((team, index) => {
const teamDiv = document.createElement("div");
teamDiv.className = "team";
teamDiv.id = `team${index + 1}`;
teamDiv.draggable = true;
teamDiv.textContent = team;
pickContainer.appendChild(teamDiv);
});
initializeDragAndDrop();
}
function initializeDragAndDrop() {
let teams = document.getElementsByClassName("team");
for (let team of teams) {
team.addEventListener("dragstart", function(e) {
e.dataTransfer.setData("text/plain", e.target.id);
});
}
[rightBox, leftBox].forEach(box => {
box.addEventListener("dragover", function(e) {
e.preventDefault();
});
box.addEventListener("drop", function(e) {
e.preventDefault();
const data = e.dataTransfer.getData("text");
const draggedElement = document.getElementById(data);
if (draggedElement) {
this.innerHTML = '';
this.appendChild(draggedElement);
checkBoxesAndDisplayMessage();
}
});
});
// Removes team when double clicked on
pickContainer.addEventListener("dblclick", function(e) {
if (e.target.classList.contains("team")) {
pickContainer.appendChild(e.target);
checkBoxesAndDisplayMessage();
}
});
}
function checkBoxesAndDisplayMessage() {
if (leftBox.textContent && rightBox.textContent) {
const team1 = leftBox.textContent;
const team2 = rightBox.textContent;
fetch('http://localhost:5000/predict', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({team1, team2}),
})
.then(response => response.json())
.then(data => {
oddsResult.innerHTML = `
<p>${team1} win: ${(data.team1_win * 100).toFixed(2)}%</p>
<p>Draw: ${(data.draw * 100).toFixed(2)}%</p>
<p>${team2} win: ${(data.team2_win * 100).toFixed(2)}%</p>
`;
})
.catch((error) => {
console.error('Error:', error);
oddsResult.textContent = "Error calculating odds";
});
} else {
oddsResult.textContent = "";
}
}
window.addEventListener("click", function(event) {
if (!event.target.matches('.dropdown-btn')) {
closeAllDropdowns();
}
});
});