Skip to content
Snippets Groups Projects
Commit 7542666b authored by josborg's avatar josborg
Browse files

Funcionalidades de rankings y envio unico de solucion

parent b11dfa04
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,12 @@
<div class="col-auto">
<button class="btn btn-primary mb-2 btn-block" (click)="navPoll()"><h3>Ir a encusta</h3></button>
</div>
<div class="col-auto">
<button class="btn btn-primary mb-2 btn-block" (click)="navProf()"><h3>Perfil profesor</h3></button>
</div>
<div class="col-auto">
<button class="btn btn-primary mb-2 btn-block" (click)="navUsr()"><h3>Perfil usuario</h3></button>
</div>
<div class="col">
<h1>{{this.user.username}}#{{this.user.discriminator}}</h1>
<h1>{{this.user.id}}</h1>
......
......@@ -110,6 +110,12 @@ export class AuthComponent implements OnInit {
navPoll(){
this.router.navigate(["/client/encuestas/"+this.id+"/preguntas"])
}
navProf(){
this.router.navigate(["/client/encuestas/profesores/"+this.user.id])
}
navUsr(){
this.router.navigate(["/client/encuestas/usuarios/"+this.user.id])
}
getGuilds() {
this.clienteApiRest.getGuilds(this.access_token).subscribe();
......
<div>
<button class="btn btn-primary ml-3" (click)="navSol()">navSol()</button>
</div>
<div class="container">
<div class="row">
<div class="col-lg-7 mx-auto">
......
......@@ -102,4 +102,8 @@ export class EncuestasListarComponent implements OnInit {
);
}
navSol(){
this.router.navigate(['client/encuestas/'+this.operacion+'/'+this.id+'/soluciones'])
}
}
<div class="container">
<div class="row mt-5">
<div class="col-sm">
<h1>Diagarmas de respuestas</h1>
<h1>Diagramas de respuestas</h1>
<figure class="highcharts-figure">
<div *ngFor="let pregunta of preguntas; let i = index">
<div id='container{{pregunta.id}}' class="shadow-lg p-3 mb-5 bg-white rounded"></div>
......@@ -10,11 +10,20 @@
</div>
<div class="col-sm">
<h1>Ranking</h1>
<div *ngIf="encuesta.status.toString() == 'FINALIZADA'; else elseBlock">
<div *ngFor="let solucion of aciertosPorEncuesta; let i = index">
<div class="shadow-lg p-3 mb-1 bg-white rounded">
<p>{{solucion.name}} - {{solucion.diff / 1000}} segundos</p>
</div>
</div>
</div>
<ng-template #elseBlock>
<div *ngFor="let solucion of soluciones; let i = index">
<div class="shadow-lg p-3 mb-1 bg-white rounded">
<p>{{solucion.name}} - {{solucion.diff / 1000}} segundos</p>
</div>
</div>
</ng-template>
</div>
</div>
</div>
......@@ -28,6 +28,8 @@ export class EstadisticasComponent implements OnInit {
preguntas: Pregunta[] = [];
encuesta: Encuesta = <Encuesta>{};
aciertosPorEncuesta: Array<any> = [];
ranking: any;
map = new Map();
......@@ -62,16 +64,39 @@ export class EstadisticasComponent implements OnInit {
});
});
}
generateRanking(){
if(this.encuesta.status.toString() == "FINALIZADA"){ //OJOOOO
this.soluciones.forEach(solucion => {
var corrects = solucion.respuestas.filter(r => r.correct)
this.aciertosPorEncuesta.push({name:solucion.name, userId: solucion.userId, idEncuesta: this.encuesta.id,
nAciertos: corrects.length, nPreguntas: this.encuesta.preguntas.length, diff: solucion.diff, valid: solucion.valid, ranking: 0})
});
this.aciertosPorEncuesta.sort((a ,b) => this.compare(a,b))
for (let i = 0; i < this.aciertosPorEncuesta.length; i++) {
this.aciertosPorEncuesta[i].ranking = i+1;
}
}
this.soluciones.sort((a, b) => <number>a.diff - <number>b.diff);
this.soluciones.forEach(element => {
console.log("kkkk"+element.id +" - "+ element.diff);
});
}
compare(a:any, b:any){
if(a.valid != b.valid){
return(+b.valid - +a.valid);
}else if(a.nAciertos != b.nAciertos){
return(+b.nAciertos - +a.nAciertos);
}else{
return (a.diff - b.diff);
}
}
loadDiagrams(){
//Highcharts.chart('container2', this.options);
this.optionsArray.forEach(element => {
......
......@@ -94,6 +94,25 @@
</table>
-->
<table class="table table-borderless">
<thead>
<tr>
<th scope="col">user.name</th>
<th scope="col">user.userId</th>
<th scope="col">user.nTop1</th>
<th scope="col">user.bestRank</th>
</tr>
</thead>
<tbody *ngFor="let user of users; let i = index">
<tr>
<td>{{user.name}}</td>
<td>{{user.userId}}</td>
<td>{{user.nTop1}}</td>
<td>{{user.bestRank}}</td>
</tr>
</tbody>
</table>
<table class="table table-borderless">
<thead>
<tr>
......@@ -101,6 +120,9 @@
<th scope="col">user.idEncuesta</th>
<th scope="col">user.nAciertos</th>
<th scope="col">user.nPreguntas</th>
<th scope="col">user.diff</th>
<th scope="col">user.valid</th>
<th scope="col">user.ranking</th>
</tr>
</thead>
<tbody *ngFor="let user of aciertosPorEncuesta; let i = index">
......@@ -109,6 +131,9 @@
<td>{{user.idEncuesta}}</td>
<td>{{user.nAciertos}}</td>
<td>{{user.nPreguntas}}</td>
<td>{{user.diff}}</td>
<td>{{user.valid}}</td>
<td>{{user.ranking}}</td>
</tr>
</tbody>
</table>
\ No newline at end of file
......@@ -16,6 +16,7 @@ export class PerfilComponent implements OnInit {
userId = "";
soluciones: Array<Solucion> = [];
encuestas: Array<Encuesta> = [];
users: Array<any> = [];
id: string = "";
operacion: string = "";
......@@ -134,7 +135,7 @@ export class PerfilComponent implements OnInit {
});
}
}
var aux: Array<any> = [];
var ranking = this.aciertosPorEncuesta.filter(a => a.idEncuesta == encuesta.id);
ranking.sort((a ,b) => this.compare(a,b))
for (let i = 0; i < ranking.length; i++) {
......@@ -144,25 +145,35 @@ export class PerfilComponent implements OnInit {
});
console.log(this.aciertosPorEncuesta);
var users: Array<any> = [this.id];
var userId = localStorage.getItem('userId');
var name = localStorage.getItem('userName');
var users: Array<any> = [];
if(userId != null && name != null){
users = [{userId: userId, name: name}];
}
if(this.operacion == "profesores"){
users = []
this.aciertosPorEncuesta.forEach(element => {
if(!users.includes(element.userId)){
users.push(element.userId);
if(users.filter(u => u.userId == element.userId && u.name == element.name).length == 0){
users.push({userId: element.userId, name: element.name});
}
});
}
users.forEach(element => {
var user = this.aciertosPorEncuesta.filter(a => a.userId == element);
var user = this.aciertosPorEncuesta.filter(a => a.userId == element.userId);
var nTop1 = user.filter(u => u.ranking == 1).length;
var bestRank = 1;
if(nTop1 == 0 && user.length > 0){
bestRank = user.sort((a, b) => a.ranking - b.ranking)[0].ranking;
}
console.log("nTop1: "+ nTop1);
console.log("bestRank: "+ bestRank);
this.users.push({userId: element.userId, name: element.name, nTop1: nTop1, bestRank: bestRank})
});
/*
if(this.operacion == "usuarios"){
this.aciertosPorEncuesta = this.aciertosPorEncuesta.filter(u => u.userId == userId && u.name == name);
}*/
console.log(this.users);
}
compare(a:any, b:any){
if(a.valid != b.valid){
......@@ -174,6 +185,9 @@ export class PerfilComponent implements OnInit {
}
}
navSol(){
this.router.navigate(['client/encuestas/'+this.operacion+'/'+this.id+'/soluciones'])
}
// Al pulsar en el boton List Encuesta
clickEncuestas() {
this.datos.cambiarMostrarMensaje(false);
......
......@@ -339,6 +339,7 @@ public class EncuestaController {
@PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, value = "/{id}")
public String newSolucion(@RequestBody Solucion newSolucion, @PathVariable Integer id) {
try {
if(!solucionRepository.existsByUserIdAndNameAndIdEncuesta(newSolucion.getUserId(), newSolucion.getName(), newSolucion.getIdEncuesta())){
ZoneOffset utc = ZoneOffset.ofHours(2);
String date = formatDate(LocalDateTime.now(utc));
Encuesta encuesta = encuestaRepository.findById(id).get();
......@@ -348,10 +349,8 @@ public class EncuestaController {
if(date.compareTo(encuesta.getInicio()) < 0 || date.compareTo(encuesta.getFin()) > 0 ){ // no abierta
System.out.println("La encuesta no esta abierta");
return "La encuesta no esta abierta";
}else if (encuesta.getStatus().equals(Estado.ABIERTA)){
System.out.println("La encuesta esta abierta");
//Comprobacion del deadline
newSolucion.setValid(true);
if(encuesta.getMaxTiempo() >= 0){
......@@ -381,7 +380,10 @@ public class EncuestaController {
}
solucionRepository.saveAndFlush(newSolucion);
return "Nuevo registro creado";
return "Solucion guardada";
}
}else{
return "Solucion ya se habia enviado";
}
} catch (Exception e) {
......
......@@ -11,5 +11,9 @@ public interface SolucionRepository extends JpaRepository<Solucion, Integer> {
List<Solucion> findByIdEncuesta(Integer idEncuesta);
List<Solucion> findByName(String name);
List<Solucion> findByUserId(Long userId);
boolean existsByUserId(Long userId);
boolean existsByName(String name);
boolean existsByIdEncuesta(Integer idEncuesta);
boolean existsByUserIdAndNameAndIdEncuesta(Long userId, String name, Integer idEncuesta);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment