-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsih.html
More file actions
470 lines (425 loc) · 19.8 KB
/
Copy pathsih.html
File metadata and controls
470 lines (425 loc) · 19.8 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Talent Discovery App</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
font-family: 'Inter', sans-serif;
background-color: #0d1117;
color: #c9d1d9;
}
.container {
max-width: 420px;
margin: auto;
min-height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
padding: 1rem;
}
.card {
background-color: #161b22;
border: 1px solid #30363d;
border-radius: 12px;
padding: 2rem;
width: 100%;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
}
.input-field {
background-color: #0d1117;
border: 1px solid #30363d;
color: #c9d1d9;
padding: 0.75rem;
border-radius: 8px;
width: 100%;
outline: none;
transition: border-color 0.2s ease-in-out;
}
.input-field:focus {
border-color: #58a6ff;
}
.btn {
background-color: #238636;
color: #ffffff;
font-weight: 600;
padding: 0.75rem 1.5rem;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.2s ease-in-out;
width: 100%;
}
.btn:hover {
background-color: #2ea043;
}
.btn-secondary {
background-color: #21262d;
border: 1px solid #30363d;
color: #58a6ff;
}
.btn-secondary:hover {
background-color: #30363d;
}
.screen {
display: none;
}
.screen.active {
display: flex;
flex-direction: column;
}
.leaderboard-item {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem;
border-bottom: 1px solid #30363d;
}
.leaderboard-item:last-child {
border-bottom: none;
}
.progress-bar {
height: 8px;
background-color: #21262d;
border-radius: 4px;
overflow: hidden;
}
.progress-fill {
height: 100%;
background-color: #238636;
transition: width 0.5s ease-in-out;
}
.lottie-container {
width: 100%;
height: 200px;
background-color: #21262d;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 1.5rem;
font-size: 1.5rem;
color: #6a737d;
}
</style>
</head>
<body class="bg-gray-900 text-gray-100">
<div class="container">
<!-- Login/Signup Screen -->
<div id="loginScreen" class="screen active">
<div class="card">
<h1 class="text-2xl font-bold mb-6 text-center">Talent Discovery</h1>
<p class="text-sm text-gray-400 text-center mb-4">Discover, track, and empower talent.</p>
<div class="space-y-4">
<input type="text" id="username" placeholder="Username" class="input-field">
<input type="password" id="password" placeholder="Password" class="input-field">
<button id="loginBtn" class="btn">Login / Register</button>
</div>
<p class="text-center text-xs text-gray-400 mt-4">This is a simulated login. Your profile will be stored in the cloud.</p>
</div>
</div>
<!-- Dashboard / Test Selection Screen -->
<div id="dashboardScreen" class="screen">
<div class="card">
<div class="flex items-center justify-between mb-6">
<div>
<h2 class="text-xl font-semibold">Welcome back, <span id="welcomeUsername"></span>!</h2>
<p class="text-sm text-gray-400">Your User ID: <span id="userIdDisplay" class="font-mono text-xs"></span></p>
</div>
<button id="logoutBtn" class="bg-red-600 hover:bg-red-700 text-white font-medium py-1 px-3 rounded-full text-xs transition">Logout</button>
</div>
<div class="space-y-4">
<h3 class="text-lg font-semibold border-b border-gray-700 pb-2 mb-4">Choose a Fitness Test</h3>
<button class="btn btn-secondary test-btn" data-test="Sit-ups">Sit-ups</button>
<button class="btn btn-secondary test-btn" data-test="Jumps">Jumps</button>
<button class="btn btn-secondary test-btn" data-test="Shuttle Run">Shuttle Run</button>
<button class="btn btn-secondary test-btn" data-test="Push-ups">Push-ups</button>
</div>
<div class="mt-8">
<h3 class="text-lg font-semibold border-b border-gray-700 pb-2 mb-4">Leaderboard</h3>
<div id="leaderboard" class="space-y-2">
<!-- Leaderboard items will be inserted here by JS -->
<div class="leaderboard-item">
<span>S. Kumar</span>
<span class="text-green-400">85 Sit-ups</span>
</div>
<div class="leaderboard-item">
<span>P. Verma</span>
<span class="text-green-400">78 Sit-ups</span>
</div>
</div>
</div>
</div>
</div>
<!-- Instruction Screen -->
<div id="instructionScreen" class="screen">
<div class="card">
<h2 class="text-2xl font-bold mb-4 text-center">Instructions for <span id="testName"></span></h2>
<div class="lottie-container">
<p>Lottie Animation Placeholder</p>
</div>
<p id="instructionText" class="text-gray-400 mb-6 text-center">
<!-- Instructions will be inserted here -->
</p>
<button id="startRecordingBtn" class="btn">Start Recording</button>
<button id="backToTestsBtn" class="btn btn-secondary mt-2">Back to Tests</button>
</div>
</div>
<!-- Recording Screen -->
<div id="recordingScreen" class="screen">
<div class="card text-center">
<h2 class="text-2xl font-bold mb-4">Recording...</h2>
<div class="relative w-full aspect-video bg-black rounded-lg overflow-hidden mb-4">
<video id="cameraFeed" class="w-full h-full object-cover"></video>
<div id="recordingIndicator" class="absolute top-2 left-2 w-3 h-3 bg-red-500 rounded-full animate-pulse hidden"></div>
</div>
<div id="recordingProgress" class="progress-bar mb-4">
<div id="progressFill" class="progress-fill" style="width: 0%;"></div>
</div>
<p id="timer" class="text-xl font-bold mb-4">00:00</p>
<button id="stopRecordingBtn" class="btn bg-red-600 hover:bg-red-700">Stop Recording</button>
</div>
</div>
</div>
<!-- Firebase SDKs -->
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-app.js";
import { getAuth, signInAnonymously, signInWithCustomToken, onAuthStateChanged } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-auth.js";
import { getFirestore, doc, setDoc, collection, addDoc, getDoc, onSnapshot, query, where, getDocs } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-firestore.js";
import { setLogLevel } from "https://www.gstatic.com/firebasejs/11.6.1/firebase-firestore.js";
setLogLevel('debug'); // Enable debug logging for Firestore
// Firebase global variables
const appId = typeof __app_id !== 'undefined' ? __app_id : 'default-app-id';
const firebaseConfig = JSON.parse(typeof __firebase_config !== 'undefined' ? __firebase_config : '{}');
const initialAuthToken = typeof __initial_auth_token !== 'undefined' ? __initial_auth_token : null;
let db, auth, app, userId;
let isAuthReady = false;
let currentPage = 'loginScreen';
let cameraStream = null;
let recordingTimerInterval = null;
let recordingDuration = 0;
let selectedTest = null;
// UI Elements
const screens = {
loginScreen: document.getElementById('loginScreen'),
dashboardScreen: document.getElementById('dashboardScreen'),
instructionScreen: document.getElementById('instructionScreen'),
recordingScreen: document.getElementById('recordingScreen')
};
const usernameInput = document.getElementById('username');
const loginBtn = document.getElementById('loginBtn');
const logoutBtn = document.getElementById('logoutBtn');
const welcomeUsername = document.getElementById('welcomeUsername');
const userIdDisplay = document.getElementById('userIdDisplay');
const testButtons = document.querySelectorAll('.test-btn');
const testNameDisplay = document.getElementById('testName');
const instructionText = document.getElementById('instructionText');
const startRecordingBtn = document.getElementById('startRecordingBtn');
const backToTestsBtn = document.getElementById('backToTestsBtn');
const cameraFeed = document.getElementById('cameraFeed');
const recordingIndicator = document.getElementById('recordingIndicator');
const stopRecordingBtn = document.getElementById('stopRecordingBtn');
const timerDisplay = document.getElementById('timer');
const progressFill = document.getElementById('progressFill');
const leaderboardContainer = document.getElementById('leaderboard');
const instructions = {
"Sit-ups": "Perform as many sit-ups as you can in 60 seconds. Keep your back straight and your feet on the ground. The AI will count your reps.",
"Jumps": "Perform 30 seconds of vertical jumps. The AI will analyze your form and height.",
"Shuttle Run": "Run between the two cones as fast as possible. The AI will track your speed and agility.",
"Push-ups": "Perform as many push-ups as you can with proper form. The AI will count your reps and detect any incorrect moves."
};
// --- State Management and UI Functions ---
function showScreen(screenId) {
Object.keys(screens).forEach(id => {
screens[id].classList.remove('active');
});
screens[screenId].classList.add('active');
currentPage = screenId;
}
async function initFirebase() {
try {
app = initializeApp(firebaseConfig);
auth = getAuth(app);
db = getFirestore(app);
onAuthStateChanged(auth, async (user) => {
if (user) {
userId = user.uid;
isAuthReady = true;
userIdDisplay.textContent = userId;
console.log('User signed in with UID:', userId);
await loadUserProfile();
listenToLeaderboard();
} else {
console.log('User is signed out.');
isAuthReady = false;
showScreen('loginScreen');
}
});
if (initialAuthToken) {
await signInWithCustomToken(auth, initialAuthToken);
} else {
await signInAnonymously(auth);
}
} catch (e) {
console.error("Error initializing Firebase:", e);
// Fallback or error UI
}
}
async function loginOrRegister() {
const username = usernameInput.value.trim();
if (!username) {
console.log("Username cannot be empty.");
return;
}
if (auth.currentUser) {
try {
const userProfileRef = doc(db, `/artifacts/${appId}/users/${userId}/profile`, 'info');
const profileDoc = await getDoc(userProfileRef);
if (!profileDoc.exists()) {
await setDoc(userProfileRef, { username: username, createdAt: new Date() });
console.log("New user profile created.");
} else {
console.log("User profile already exists.");
}
showScreen('dashboardScreen');
} catch (e) {
console.error("Error setting user profile:", e);
}
}
}
async function loadUserProfile() {
if (!isAuthReady) return;
try {
const userProfileRef = doc(db, `/artifacts/${appId}/users/${userId}/profile`, 'info');
const profileDoc = await getDoc(userProfileRef);
if (profileDoc.exists()) {
const data = profileDoc.data();
welcomeUsername.textContent = data.username;
}
} catch (e) {
console.error("Error loading user profile:", e);
}
}
function listenToLeaderboard() {
if (!isAuthReady) return;
const q = collection(db, `/artifacts/${appId}/public/data/leaderboard`);
onSnapshot(q, (querySnapshot) => {
leaderboardContainer.innerHTML = '';
querySnapshot.forEach((doc) => {
const data = doc.data();
const item = document.createElement('div');
item.className = 'leaderboard-item';
item.innerHTML = `<span>${data.username}</span><span class="text-green-400">${data.score} ${data.test}</span>`;
leaderboardContainer.appendChild(item);
});
}, (error) => {
console.error("Error listening to leaderboard:", error);
});
}
// --- Camera and Recording Functions ---
async function startCamera() {
if (cameraStream) return;
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: { facingMode: 'user' } });
cameraFeed.srcObject = stream;
cameraStream = stream;
} catch (err) {
console.error("Error accessing camera:", err);
alert('Could not access camera. Please check permissions.');
}
}
function stopCamera() {
if (cameraStream) {
cameraStream.getTracks().forEach(track => track.stop());
cameraStream = null;
}
}
function startRecordingSimulation() {
recordingDuration = 0;
const maxDuration = 10; // 10 seconds for the simulation
recordingIndicator.classList.remove('hidden');
progressFill.style.width = '0%';
timerDisplay.textContent = '00:00';
recordingTimerInterval = setInterval(() => {
recordingDuration++;
const minutes = Math.floor(recordingDuration / 60).toString().padStart(2, '0');
const seconds = (recordingDuration % 60).toString().padStart(2, '0');
timerDisplay.textContent = `${minutes}:${seconds}`;
const progress = (recordingDuration / maxDuration) * 100;
progressFill.style.width = `${progress}%`;
if (recordingDuration >= maxDuration) {
stopRecordingSimulation();
console.log("Recording simulation finished.");
}
}, 1000);
}
async function stopRecordingSimulation() {
clearInterval(recordingTimerInterval);
recordingIndicator.classList.add('hidden');
stopCamera();
// Save mock data to Firestore
if (isAuthReady) {
const testsCollectionRef = collection(db, `/artifacts/${appId}/users/${userId}/tests`);
try {
const mockScore = Math.floor(Math.random() * 50) + 10; // A random score
await addDoc(testsCollectionRef, {
test: selectedTest,
duration: recordingDuration,
score: mockScore,
timestamp: new Date()
});
const leaderboardRef = collection(db, `/artifacts/${appId}/public/data/leaderboard`);
const username = welcomeUsername.textContent;
await addDoc(leaderboardRef, {
username: username,
test: selectedTest,
score: mockScore
});
console.log("Mock test result saved to Firestore.");
} catch (e) {
console.error("Error saving mock test data:", e);
}
}
showScreen('dashboardScreen');
}
// --- Event Listeners ---
loginBtn.addEventListener('click', loginOrRegister);
logoutBtn.addEventListener('click', async () => {
if (auth.currentUser) {
try {
await auth.signOut();
console.log("User signed out.");
showScreen('loginScreen');
usernameInput.value = '';
} catch (e) {
console.error("Error signing out:", e);
}
}
});
testButtons.forEach(button => {
button.addEventListener('click', (e) => {
selectedTest = e.target.dataset.test;
testNameDisplay.textContent = selectedTest;
instructionText.textContent = instructions[selectedTest];
showScreen('instructionScreen');
});
});
startRecordingBtn.addEventListener('click', () => {
startCamera();
showScreen('recordingScreen');
setTimeout(startRecordingSimulation, 1000); // Give camera time to load
});
stopRecordingBtn.addEventListener('click', stopRecordingSimulation);
backToTestsBtn.addEventListener('click', () => {
showScreen('dashboardScreen');
});
// Initialize the app on window load
window.onload = initFirebase;
</script>
</body>
</html>