-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
256 lines (223 loc) · 9.24 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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IMSS - Turno Unifila</title>
<!-- Meta tags para cambiar el color de la barra del navegador -->
<meta name="theme-color" content="#006847">
<meta name="apple-mobile-web-app-status-bar-style" content="#006847">
<style>
/* Definición de variables CSS para colores principales */
:root {
--primary-color: #006847;
--secondary-color: #00a86b;
--text-color: #333;
--background-color: #f0f0f0;
}
/* Estilos generales del body */
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: var(--background-color);
color: var(--text-color);
line-height: 1.6;
margin: 0;
padding: 0;
}
/* Contenedor principal */
.container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
}
/* Estilos del encabezado */
header {
background-color: var(--primary-color);
color: white;
text-align: center;
padding: 1rem;
}
/* Estilos de los títulos */
h1, h2 {
margin-bottom: 1rem;
}
/* Estilos de las tarjetas */
.card {
background-color: white;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 20px;
margin-bottom: 20px;
}
/* Estilos de los campos de entrada y botones */
input[type="text"], button {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
button {
background-color: var(--secondary-color);
color: white;
border: none;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: var(--primary-color);
}
/* Estilos para los resultados y el último turno */
#resultado, #ultimoTurno {
font-weight: bold;
margin-top: 10px;
}
/* Estilos del indicador de carga */
.loader {
border: 5px solid #f3f3f3;
border-top: 5px solid var(--primary-color);
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 20px auto;
display: none;
}
/* Animación para el indicador de carga */
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<header>
<h1>IMSS - Turno Unifila</h1>
</header>
<div class="container">
<div class="card">
<h2>Turno actual atendido</h2>
<p id="ultimoTurno">Cargando...</p>
</div>
<div class="card">
<h2>Buscar mi turno</h2>
<input type="text" id="nombreInput" placeholder="Ingresa tu nombre" aria-label="Ingresa tu nombre">
<button onclick="buscarTurnoPorNombre()">Buscar turno</button>
<div class="loader" id="loader"></div>
<p id="resultado"></p>
</div>
</div>
<script>
// URL de la hoja de cálculo de Google publicada como CSV
const urlCSV = 'https://docs.google.com/spreadsheets/d/e/2PACX-1vREcyV03371MlmUfeTdaChjrsTV06nOSuN64LBNXQ55muGb3T7Q5MSfqrWaRIdCpfp8NmZzgRaipQML/pub?output=csv';
// Array para almacenar los datos de la hoja de cálculo
let datos = [];
// Función para cargar los datos desde la hoja de cálculo
async function cargarDatos() {
const response = await fetch(urlCSV);
const data = await response.text();
const filas = data.split('\n').map(row => row.split(','));
return filas.filter(fila => fila.length >= 3);
}
// Función para mostrar el último turno atendido
async function mostrarUltimoTurno() {
try {
datos = await cargarDatos();
let turnoAtendido = datos.reduce((ultimo, fila) => {
return (fila[2].trim().toLowerCase() === 'true') ? parseInt(fila[0]) : ultimo;
}, null);
document.getElementById('ultimoTurno').innerText = turnoAtendido !== null
? `El último turno atendido es: ${turnoAtendido}`
: 'No se ha atendido ningún turno aún.';
} catch (error) {
console.error('Error al cargar datos:', error);
document.getElementById('ultimoTurno').innerText = 'Error al cargar datos. Por favor, intente más tarde.';
}
}
// Función principal para buscar el turno por nombre
async function buscarTurnoPorNombre() {
document.getElementById('loader').style.display = 'block';
document.getElementById('resultado').innerText = '';
try {
if (datos.length === 0) {
datos = await cargarDatos();
}
const nombreBuscado = document.getElementById('nombreInput').value.trim().toLowerCase();
let mejorCoincidencia = { nombre: '', turno: null, porcentaje: 0 };
datos.forEach(fila => {
const nombreOriginal = fila[1].trim();
const nombreComparar = nombreOriginal.toLowerCase();
const coincidencia = calcularCoincidencia(nombreBuscado, nombreComparar);
if (coincidencia > mejorCoincidencia.porcentaje && coincidencia >= 0.8) {
mejorCoincidencia = {
nombre: nombreOriginal,
turno: fila[0],
porcentaje: coincidencia
};
}
});
let mensajeResultado = '';
if (mejorCoincidencia.turno !== null) {
const ultimoTurnoAtendido = await obtenerUltimoTurnoAtendido();
if (ultimoTurnoAtendido !== null) {
const lugaresRestantes = parseInt(mejorCoincidencia.turno) - ultimoTurnoAtendido;
mensajeResultado = `Hola ${mejorCoincidencia.nombre}, tu turno es: ${mejorCoincidencia.turno}.
El último turno atendido es: ${ultimoTurnoAtendido}.
${lugaresRestantes > 0
? `Faltan aproximadamente ${lugaresRestantes} personas para tu turno.`
: 'Tu turno ya ha sido llamado.'}`;
}
} else {
mensajeResultado = 'No se encontró un turno para ese nombre.';
}
document.getElementById('resultado').innerText = mensajeResultado;
} catch (error) {
console.error('Error en la búsqueda:', error);
document.getElementById('resultado').innerText = 'Error al buscar el turno. Por favor, intente nuevamente.';
} finally {
document.getElementById('loader').style.display = 'none';
}
}
// Función para calcular la coincidencia entre dos cadenas
function calcularCoincidencia(nombreBuscado, nombre) {
const distancia = levenshteinDistance(nombreBuscado, nombre);
return 1 - (distancia / Math.max(nombreBuscado.length, nombre.length));
}
// Función para calcular la distancia de Levenshtein entre dos cadenas
function levenshteinDistance(a, b) {
const matrix = [];
for (let i = 0; i <= b.length; i++) {
matrix[i] = [i];
}
for (let j = 0; j <= a.length; j++) {
matrix[0][j] = j;
}
for (let i = 1; i <= b.length; i++) {
for (let j = 1; j <= a.length; j++) {
if (b.charAt(i - 1) === a.charAt(j - 1)) {
matrix[i][j] = matrix[i - 1][j - 1];
} else {
matrix[i][j] = Math.min(
matrix[i - 1][j - 1] + 1,
matrix[i][j - 1] + 1,
matrix[i - 1][j] + 1
);
}
}
}
return matrix[b.length][a.length];
}
// Función para obtener el último turno atendido
async function obtenerUltimoTurnoAtendido() {
return datos.reduce((ultimo, fila) => {
return (fila[2].trim().toLowerCase() === 'true') ? Math.max(ultimo, parseInt(fila[0])) : ultimo;
}, 0);
}
// Cargar el último turno atendido al cargar la página
window.onload = mostrarUltimoTurno;
// Actualizar el último turno atendido cada minuto
setInterval(mostrarUltimoTurno, 60000);
</script>
</body>
</html>