-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
377 lines (333 loc) · 13.4 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HackQuarantine</title>
<!--Link de css para agregar mapas-->
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<!--Link de javascript para agregar mapas-->
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<!--Aquí están los estilos (colores, bordes, etc)-->
<style>
html, body{
margin: 0px;
padding: 0px;
height: 100vh;
display: flex;
flex-direction: column;
}
hr{
width: 100%;
}
/*Encabezado*/
#header{
padding: 18px;
box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
font-size: 2em;
z-index: 2;
position: relative;
display: flex;
justify-content: space-between;
align-items: center;
}
#header>span{
display: flex;
align-items: center;
}
#header img{
height: 40px;
margin: 8px;
}
#header a{
font-size: 0.8em;
padding: 8px 16px;
background: rgb(230,240,244);
text-decoration: none;
}
/*Mapa*/
#mapid {
flex: 1;
z-index: 1;
}
/*Botón dentro de mapa*/
#mapid button{
margin: 16px;
padding: 8px;
position: absolute;
z-index: 999;
font-size: 2em;
bottom: 16px;
}
/*Datos de probabilidad*/
#window{
position: absolute;
bottom: 16px;
right: 16px;
z-index: 999;
font-size: 1em;
bottom: 16px;
background: white;
padding: 16px;
font-family: Arial, Helvetica, sans-serif;
display: flex;
flex-direction: column;
width: 400px;
}
#window button{
padding: 8px;
font-size: 1em;
}
#window h1{
margin: 0px;
margin-top: 1em;
font-size: 1.6em;
margin-bottom: 0.4em;
color: rgb(160,160,160);
}
/*Pacientes*/
.patient{
width: 5px;
height: 5px;
position: absolute;
display: inline-block;
background: black;
}
.data_row{
display: flex;
}
.data_row>.data_cell{
flex: 1;
}
.data_row .data_number{
margin: 0px;
font-weight: 600;
font-size: 2.5em;
}
.data_row .data_description{
font-weight: 600;
color: rgb(100,100,100);
}
</style>
</head>
<body>
<!--Header-->
<div id="header">
<span>
<img src="https://ctrl-alt-tec.hackclub.com/img/logo-block.png" alt="" srcset="">
CovidApp.
</span>
<a href="formulario.html">Diagnóstico</a>
</div>
<!--mapa leafts-->
<div id="mapid">
</div>
<!--datos de probabilidad de contagio-->
<div id= "window">
<button>Actualizar ubicación</button>
<br>
<fieldset>
<legend name="prob_legend">Probabilidad de enfermedad</legend>
<input type="range" min="0" max="1" step="0.1" style="width: 100%;" name="prob">
</fieldset>
<br>
<div id="data" class="data_row">
<div class="data_cell">
<h2 class="data_number" id="simulation_cases"></h2>
<span class="data_description">Casos</h2>
</div>
<div class="data_cell">
<h2 class="data_number" id="simulation_population"></h2>
<span class="data_description">Población</span>
</div>
</div>
<hr>
<h1>Probabilidades de contagio</h1>
<div id="data" class="data_row">
<div class="data_cell">
<h2 class="data_number">33.33%</h2>
<span class="data_description">Al aire libre</h2>
</div>
<div class="data_cell">
<h2 class="data_number">55.55%</h2>
<span class="data_description">En lugares cerrados</span>
</div>
</div>
<h1>El día de hoy</h1>
<div id="data" class="data_row">
<div class="data_cell">
<h2 class="data_number" id="data_cases" style="color: rgb(255,149,0)">N.D.</h2>
<span class="data_description">Casos</h2>
</div>
<div class="data_cell">
<h2 class="data_number" id="data_recoveries" style="color: rgb(52, 19, 89)">N.D.</h2>
<span class="data_description">Recuperad@s</span>
</div>
<div class="data_cell">
<h2 class="data_number" id="data_deaths" style="color: rgb(255, 5, 48)">N.D.</h2>
<span class="data_description">Muertes</span>
</div>
</div>
<p id="credits" style="text-align: center;">
<br>
<br>
Matías Sandoval, Fer Nava, Ricardo Uraga, Eduardo Villalpando <br>
Made with 💙 by <a href="https://ctrl-alt-tec.hackclub.com">Ctrl Alt Tec</a>
</p>
</div>
<!--Acá está el código con la lógica del programa-->
<script>
// Límites de la ciudad de mexico
const mexicoCityBoundaries = {
minLat: 19.00,
maxLat: 19.40,
minLong: -98.8,
maxLong: -99.4,
}
const radius = 1000;
// ESTO ES UN ARRAY CON LOS DATOS DE CADA PACIENTE: su id, lat, long, y probabilidad de estar infectadx
let patients = [
{id: 0, coords: [19.432708, -99.133309], infection: 1/3, recents: []},
{id: 1, coords: [19.434703, -99.123209], infection: 0, recents: []},
{id: 2, coords: [19.432703, -99.143202], infection: 0, recents: []},
{id: 3, coords: [19.442703, -99.146202], infection: 0, recents: []},
{id: 4, coords: [19.442303, -99.142202], infection: 0, recents: []},
{id: 5, coords: [19.482303, -99.142202], infection: 0, recents: []},
{id: 6, coords: [19.422303, -99.142202], infection: 0, recents: []},
{id: 7, coords: [19.432728, -99.132539], infection: 0, recents: []},
{id: 8, coords: [19.434723, -99.122539], infection: 0, recents: []},
{id: 9, coords: [19.432723, -99.142532], infection: 0.3, recents: []},
{id: 10, coords: [19.442723, -99.125312], infection: 0, recents: []},
{id: 11, coords: [19.442323, -99.125312], infection: 0, recents: []},
{id: 12, coords: [19.482323, -99.125312], infection: 0, recents: []},
{id: 13, coords: [19.422323, -99.125312], infection: 0, recents: []},
]
//esta línea de código incializa el mapa en londres
var map = L.map('mapid').setView([19.432608, -99.133209], 13)
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
maxZoom: 18,
id: 'mapbox/streets-v11',
tileSize: 512,
zoomOffset: -1
}).addTo(map);
let iconSick = L.icon({
iconUrl: 'virus.png',
iconSize: [40,40],
})
let iconHappy = L.icon({
iconUrl: 'happy.png',
iconSize: [40,40],
})
let iconCompromised = L.icon({
iconUrl: 'compromised.png',
iconSize: [40,40],
})
//Para cada elemento de patients, genera un marcador en el mapa
let markers = patients.map(l=>(
L.marker(l.coords) // Crea marcador con coordenadas
.addTo(map) // Lo añade al mapa
.bindPopup(JSON.stringify(l)) // Le asigna un popup
.setIcon((()=>{
if(l.infection>0){ return iconSick }
else { return iconHappy }
})())
));
document.querySelector("#simulation_population").innerHTML = patients.length
document.querySelector("#simulation_cases").innerHTML = patients.filter(l=>l.infection>0).length
//Ejecutar código cada que se presione el botón
document.querySelector('button').addEventListener('click', ()=>{
//Decide cuántas personas cambiarán de ubivación
let randomCounter = Math.floor(Math.random()*(5 + 1)+1);
//Ejecuta elcódigo para cada persona
for (let i = 0; i < randomCounter; i++) {
// Escoge un índice al azar
let randomIndex = Math.floor(Math.random()*(patients.length-1)+1);
//Ejecuta la funcón change location
changeLocation(randomIndex)
}
})
function changeLocation(id){
console.log(id)
// Genera coordenadas aleatorias
let newCoords = [
Math.random()*(mexicoCityBoundaries.maxLat - mexicoCityBoundaries.minLat) + mexicoCityBoundaries.minLat,
Math.random()*(mexicoCityBoundaries.maxLong - mexicoCityBoundaries.minLong) + mexicoCityBoundaries.minLong
]
// Mueve el marcador en el mapa
markers[id].setLatLng(newCoords);
//Actualiza las coordenadas en los datos
patients[id].coords = newCoords;
//Crea una copia temporal de patients
let nearestPoint = [...patients].sort((a, b) => map.distance(newCoords, a.coords) - map.distance(newCoords, b.coords) ) // Los ordena de acuerdo a su distancia
if( map.distance(newCoords, nearestPoint[1].coords) < radius){
console.log("%c Infection", "font-size: 2em")
let infected_id = nearestPoint[1].id;
diagnoseSick(id, (1/3)*patients[infected_id].infection)
diagnoseSick(infected_id, (1/3)*patients[id].infection)
patients[id].recents.push(infected_id)
patients[infected_id].recents.push(id)
updatePatientInfo(id)
updatePatientInfo(infected_id)
console.log(patients[id], patients[infected_id])
document.querySelector("#simulation_cases").innerHTML = patients.filter(l=>l.infection>0).length
} else {
console.log("%c Clean", "font-size: 2em; color: green")
}
}
function diagnoseSick(id, percentage, propagate=false){
patients[id].infection+=percentage;
if(patients[id].infection > 0.5 && propagate){
[...new Set(patients[id].recents)].forEach(l=>{
diagnoseSick(l, (1/3)*patients[id].infection, false)
//updatePatientInfo(l)
})
}
}
function updatePatientInfo(id){
if(patients[id].infection > 0 && patients[id].infection < 0.5){
markers[id].setIcon(iconCompromised)
}
else if(patients[id].infection > 0.5){
markers[id].setIcon(iconSick)
}
markers[id].setPopupContent(JSON.stringify(patients[id]))
}
function getDataMX(){
fetch('https://pomber.github.io/covid19/timeseries.json', {
}).then(data=>data.json()).then(data=>{
//console.log(data.timelineitems[0])
//let allDates = Object.keys(data['Mexico'].timelineitems[0]).filter(l=>l!="stat").sort((a,b)=>new Date(a)-new Date(b))
//let today = [...allDates].pop()
/*let todayData = data['Mexico'].timelineitems[0][today]
console.log(todayData)
*/
let todayData = data['Mexico'][data['Mexico'].length-1]
document.querySelector('#data_cases').innerHTML = todayData.confirmed;
document.querySelector('#data_recoveries').innerHTML = todayData.recovered;
document.querySelector('#data_deaths').innerHTML = todayData.deaths;
console.log(data['Mexico'][data['Mexico'].length-1])
})
}
function getLiveLocation(){
if (navigator.geolocation) { //check if geolocation is available
navigator.geolocation.getCurrentPosition(function(position){
let newCoords = [position.coords.latitude, position.coords.longitude]
patients[0].coords = newCoords
markers[0].setLatLng(newCoords)
});
}
}
getLiveLocation()
getDataMX()
document.querySelector('[name="prob"]').addEventListener('change', (e)=>{
document.querySelector('[name="prob_legend"]').innerHTML = `Probabilidad de enfermedad (${e.target.value})`;
diagnoseSick(0, e.target.value, true)
})
</script>
</body>
</html>