Last active
February 16, 2021 16:50
-
-
Save donal56/6cccb369c2c5078a4a203a28154b0b7c to your computer and use it in GitHub Desktop.
Evaluacion docente ITVH automática en base a dos preguntas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var avg = prompt('¿Que calificación le pondría al profesor (0-100)?'); | |
var repre = prompt('¿Considera que el maestro toma represalias contra los alumnos?\n1= No 2 3= No estoy seguro 4 5= Sí'); | |
var mySet = new Set(); | |
var aux = []; | |
var cont= 0; | |
var desfase= 5; | |
var cont_ciclos= 0; | |
var fDispersion= 1; /*(0-20), cambiara a los elementos asi de cercanos o lejanos*/ | |
avg = Number(avg); | |
repre = Number(repre) - 1; | |
if(Number.isNaN(avg) || Number.isNaN(repre)) | |
{ | |
alert('Error\nIngrese un número entero.'); | |
} | |
else | |
{ | |
for (var i = 0; i < 48; i++) | |
{ | |
aux[i] = randomInt(); | |
} | |
forzarPromedio(); | |
console.log(aux); | |
$('input[type="radio"]').each(function(index) | |
{ | |
if((index + 1) % 5 == 0) | |
{ | |
mySet.add(this.name); | |
} | |
}); | |
for (var nm of mySet) | |
{ | |
if (aux[cont] > 80) | |
document['fPreguntas'][nm].item(0).checked = true; | |
else if (aux[cont] > 60) | |
document['fPreguntas'][nm].item(1).checked = true; | |
else if (aux[cont] > 40) | |
document['fPreguntas'][nm].item(2).checked = true; | |
else if (aux[cont] > 20) | |
document['fPreguntas'][nm].item(3).checked = true; | |
else | |
document['fPreguntas'][nm].item(4).checked = true; | |
cont++; | |
} | |
document['fPreguntas'][Array.from(mySet)[25]].item(repre).checked = true; | |
} | |
function forzarPromedio() | |
{ | |
cont_ciclos++; | |
if(promedio() > (avg + desfase)) | |
aux.forEach(function(item, index) | |
{ | |
(item + fDispersion * desfase) > avg ? aux[index]= randomInt( avg, item) : void(0) | |
}); | |
else if(promedio() < (avg - desfase)) | |
aux.forEach(function(item, index) | |
{ | |
(item - fDispersion * desfase) < avg ? aux[index]= randomInt( item, avg) : void(0) | |
}); | |
if (promedio() > (avg + desfase) || promedio() < (avg - desfase)) | |
forzarPromedio(); | |
console.log('Vuelta ' + cont_ciclos + '\nPromedio: ' + promedio()); | |
} | |
function randomInt(min= 0, max= 100) | |
{ | |
return Math.round(Math.random() * (max-min)) + min; | |
} | |
function promedio() | |
{ | |
return aux.reduce(function(acumulator, num, arr) { return acumulator + num; } ) / aux.length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment