-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
344 lines (300 loc) · 11.1 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upcoming Movies Prediction</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
color: #333;
}
header {
background-color: #007BFF;
color: white;
text-align: center;
padding: 20px 10px;
position: sticky;
top: 0;
z-index: 1000;
display: flex;
justify-content: space-between;
align-items: center;
}
.repo-link img {
width: 40px;
height: 40px;
}
.description {
text-align: center;
margin: 20px;
font-size: 16px;
color: #555;
}
.controls {
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
margin: 20px;
}
.search-bar input, .sort-dropdown {
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 8px;
}
.theme-toggle {
padding: 10px;
background-color: #007BFF;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
}
.gallery {
display: flex;
flex-wrap: wrap;
gap: 20px;
padding: 20px;
justify-content: center;
}
.card {
border: 1px solid #ddd;
border-radius: 8px;
background: white;
padding: 10px;
width: 200px;
text-align: center;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease, box-shadow 0.3s ease;
overflow: hidden;
position: relative;
}
.card:hover {
transform: scale(1.05);
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.card img {
width: 100%;
border-radius: 8px;
object-fit: cover;
cursor: pointer;
}
.card h3 {
font-size: 16px;
margin: 10px 0;
}
.rating {
font-size: 14px;
margin: 10px 0;
}
.stars {
color: #FFD700;
}
.card .genres {
display: flex;
flex-wrap: wrap;
gap: 5px;
justify-content: center;
}
.card .genres span {
padding: 5px 10px;
background-color: #f0f0f0;
border-radius: 5px;
font-size: 12px;
cursor: pointer;
transition: background-color 0.3s;
}
.card .genres span:hover {
background-color: #007BFF;
color: white;
}
.favorites {
margin: 20px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: white;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.favorites h2 {
text-align: center;
margin-bottom: 10px;
}
.favorites-list {
display: flex;
flex-wrap: wrap;
gap: 20px;
justify-content: center;
}
.spinner {
text-align: center;
margin-top: 50px;
}
.dark-mode {
background-color: #1e1e1e;
color: #ccc;
}
.dark-mode .card {
background-color: #333;
border-color: #555;
}
.dark-mode .theme-toggle {
background-color: #555;
color: #ddd;
}
.dark-mode .sort-dropdown {
background-color: #333;
color: #ccc;
border-color: #555;
}
</style>
</head>
<body>
<header>
<h1>Upcoming Movies Prediction</h1>
<button class="theme-toggle" id="theme-toggle">Toggle Dark Mode</button>
<a href="https://github.com/MartinEBravo/movie-rating-predictor-service" class="repo-link" target="_blank">
<img src="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png" alt="GitHub Repo">
</a>
</header>
<div class="description">
Welcome to the Upcoming Movies Prediction! Here you can explore a variety of movies, check their predicted ratings, and add your favorites to a personalized list.
</div>
<div class="controls">
<input type="text" id="search" placeholder="Search for movies...">
<select id="sort" class="sort-dropdown">
<option value="title">Sort by Title</option>
<option value="rating">Sort by Predicted Rating</option>
<option value="year">Sort by Release Year</option>
</select>
</div>
<div class="favorites" id="favorites">
<h2>Your Favorites</h2>
<div id="favorites-list" class="favorites-list">No favorites yet.</div>
</div>
<div class="spinner" id="spinner">Loading...</div>
<div class="gallery" id="gallery"></div>
<script>
const csvUrl = "https://raw.githubusercontent.com/MartinEBravo/movie-rating-predictor-service/main/movies.csv";
const favorites = [];
async function fetchCSV(url) {
const response = await fetch(url);
const csvText = await response.text();
const rows = csvText.split("\n").map(row => row.split(";"));
const headers = rows[0];
const data = rows.slice(1).map(row => {
const obj = {};
row.forEach((value, index) => {
obj[headers[index].trim()] = value.trim();
});
return obj;
});
return data;
}
function createMovieCard(movie) {
const title = movie["title"] || "Unknown Title";
const rating = parseFloat(movie["predicted_rating"] || 0).toFixed(1);
const stars = "⭐".repeat(Math.round(rating));
const year = movie["release_year"] || "Unknown Year";
const genres = (movie["genres"] || "").split(",").map(genre => genre.trim());
const poster = movie["poster_path"]
? `https://image.tmdb.org/t/p/w200${movie["poster_path"]}`
: "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/No_image_available.svg/1024px-No_image_available.svg.png";
const imdbLink = movie["imdb_id"] ? `https://www.imdb.com/title/${movie["imdb_id"]}` : "#";
return `
<div class="card">
<a href="${imdbLink}" target="_blank">
<img src="${poster}" alt="${title}">
</a>
<h3>${title}</h3>
<p class="rating">Predicted Rating: ${rating} <span class="stars">${stars}</span></p>
<p>Year: ${year}</p>
<div class="genres">
${genres.map(genre => `<span>${genre}</span>`).join("")}
</div>
<button onclick="addToFavorites('${title}', ${rating}, '${poster}', '${genres.join(", ")}')">Add to Favorites</button>
</div>
`;
}
function addToFavorites(title, rating, poster, genres) {
if (!favorites.some(fav => fav.title === title)) {
favorites.push({ title, rating, poster, genres });
updateFavorites();
}
}
function updateFavorites() {
const favoritesList = document.getElementById("favorites-list");
if (favorites.length === 0) {
favoritesList.innerHTML = "No favorites yet.";
} else {
favoritesList.innerHTML = favorites.map(fav => `
<div class="card">
<img src="${fav.poster}" alt="${fav.title}">
<h3>${fav.title}</h3>
<p class="rating">Predicted Rating: ${fav.rating} <span class="stars">${"⭐".repeat(Math.round(fav.rating))}</span></p>
<p>Genres: ${fav.genres}</p>
</div>
`).join("");
}
}
function sortMovies(movies, criteria) {
return movies.sort((a, b) => {
if (criteria === "rating") {
return parseFloat(b["predicted_rating"] || 0) - parseFloat(a["predicted_rating"] || 0);
} else if (criteria === "year") {
return parseInt(b["release_year"] || 0) - parseInt(a["release_year"] || 0);
} else {
return (a["title"] || "").localeCompare(b["title"] || "");
}
});
}
async function displayMovies() {
const spinner = document.getElementById("spinner");
const gallery = document.getElementById("gallery");
const searchInput = document.getElementById("search");
const sortDropdown = document.getElementById("sort");
try {
let movies = await fetchCSV(csvUrl);
spinner.style.display = "none";
function renderGallery(filteredMovies) {
gallery.innerHTML = filteredMovies.map(createMovieCard).join("");
}
renderGallery(movies);
searchInput.addEventListener("input", event => {
const searchTerm = event.target.value.toLowerCase();
const filteredMovies = movies.filter(movie =>
(movie["title"] || "").toLowerCase().includes(searchTerm)
);
renderGallery(filteredMovies);
});
sortDropdown.addEventListener("change", event => {
const sortedMovies = sortMovies(movies, event.target.value);
renderGallery(sortedMovies);
});
gallery.addEventListener("click", event => {
if (event.target.tagName === "SPAN") {
const genre = event.target.textContent.toLowerCase();
const filteredMovies = movies.filter(movie =>
(movie["genres"] || "").toLowerCase().includes(genre)
);
renderGallery(filteredMovies);
}
});
} catch (error) {
console.error("Error fetching or parsing CSV:", error);
spinner.textContent = "Failed to load movies.";
}
}
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
}
document.getElementById("theme-toggle").addEventListener("click", toggleDarkMode);
document.addEventListener("DOMContentLoaded", displayMovies);
</script>
</body>
</html>