Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development #8

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
460914a
muchas cosas
sant11h Feb 23, 2020
b85032d
Agregado lo del tiempo límite
GastonGzMr Feb 23, 2020
d75dad3
v0.9
GastonGzMr Oct 24, 2020
e179aa0
v0.9.1
GastonGzMr Oct 24, 2020
82f3a7c
v0.9.1
GastonGzMr Oct 24, 2020
003b9be
vPushsdedfef
GastonGzMr Nov 22, 2020
1cfe4b4
Remake.0.1
GastonGzMr Nov 22, 2020
d6d3edb
JSON Mapper
sant11h Nov 22, 2020
acef626
Remake.0.2
GastonGzMr Nov 22, 2020
025a3e1
Merge branch 'development' of https://github.com/shock-team/shockquiz…
GastonGzMr Nov 22, 2020
de8ece5
Remake.0.3
GastonGzMr Nov 22, 2020
1d22cde
Remake.0.4
GastonGzMr Nov 22, 2020
19fa2a4
Update RepositorioPregunta.cs
sant11h Nov 22, 2020
cc0142c
a
sant11h Nov 22, 2020
9a907b8
Merge branch 'development' of https://github.com/shock-team/shockquiz…
sant11h Nov 22, 2020
6c9ad46
Update .gitignore
sant11h Nov 22, 2020
0574af2
a
sant11h Nov 22, 2020
ff82870
Update ConfigurarSesionForm.cs
sant11h Nov 22, 2020
675ef68
Remake.0.5
GastonGzMr Nov 23, 2020
6624d4e
Remake.0.6
GastonGzMr Nov 23, 2020
98ae920
Remake.0.7
GastonGzMr Nov 23, 2020
4878430
Nuevo Timer (agane)
sant11h Nov 23, 2020
d1e09b3
Merge branch 'development' of https://github.com/shock-team/shockquiz…
sant11h Nov 23, 2020
c804b36
Timer Final
sant11h Nov 24, 2020
a4d4c0a
Details
sant11h Nov 24, 2020
73e61ba
Update README.md
sant11h Nov 24, 2020
8f732c0
Update FachadaSesion.cs
sant11h Nov 24, 2020
891cd41
Details
sant11h Nov 24, 2020
d8439c5
Remake.1
GastonGzMr Nov 24, 2020
5ec12bc
Update Program.cs
sant11h Nov 24, 2020
7493428
Merge branch 'master' into development
sant11h Nov 25, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ obj/
Debug/
test/
packages/
Migrations/
.vs
*.ide-shm
*.cache
Expand Down
10 changes: 10 additions & 0 deletions ShockQuiz/DAL/EntityFramework/Mapping/PreguntaMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ public PreguntaMap()
this.HasRequired<Conjunto>(x => x.Conjunto)
.WithMany(x => x.Preguntas)
.HasForeignKey<int>(x => x.ConjuntoId);

/*this.HasRequired<Sesion>(x => x.SesionActual)
.WithMany(x => x.Preguntas)
.HasForeignKey<int>(x => x.SesionActualId);*/

this.Property(x => x.SesionActualId)
.IsRequired()
.HasColumnName("idSesionActual");

this.Ignore(x => x.ConjuntoNombre);
}
}
}
9 changes: 4 additions & 5 deletions ShockQuiz/DAL/EntityFramework/Mapping/SesionMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public SesionMap()
.HasDatabaseGeneratedOption(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.Identity)
.HasColumnName("id");

this.Property(x => x.CantidadPreguntas)
this.Property(x => x.PreguntasRestantes)
.HasColumnName("cantidadPreguntas")
.IsRequired();

Expand All @@ -31,8 +31,7 @@ public SesionMap()
.IsRequired();

this.Property(x => x.FechaFin)
.HasColumnName("fechaInicio")
.IsRequired();
.HasColumnName("fechaInicio");

this.Property(x => x.FechaFin)
.HasColumnName("fechaFin")
Expand All @@ -46,8 +45,8 @@ public SesionMap()
.WithMany(x => x.Sesiones)
.HasForeignKey<int>(x => x.ConjuntoId);

this.Ignore(x => x.Preguntas);
this.Ignore(x => x.RespuestasCorrectas);
this.Property(x => x.RespuestasCorrectas);
this.Property(x => x.CantidadTotalPreguntas);
}
}
}
42 changes: 36 additions & 6 deletions ShockQuiz/DAL/EntityFramework/RepositorioPregunta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ public IEnumerable<Pregunta> ObtenerTodas()
/// <param name="pConjunto">Conjunto</param>
/// <param name="pCantidad">Cantidad de Preguntas</param>
/// <returns></returns>
public IEnumerable<Pregunta> ObtenerPreguntas(Categoria pCategoria, Dificultad pDificultad, Conjunto pConjunto, int pCantidad = 10)
public IEnumerable<Pregunta> ObtenerPreguntas(int pCategoria, int pDificultad, int pConjunto, int pCantidad = 10)
{

var list = from t in iDbContext.Preguntas
.Include(x => x.Respuestas)
.Include(x => x.Categoria)
.Include(x => x.Dificultad)
.Include(x => x.Conjunto)
where t.Categoria.Nombre == pCategoria.Nombre
&& t.Dificultad.Nombre == pDificultad.Nombre
&& t.Conjunto.Nombre == pConjunto.Nombre
where t.Categoria.Id == pCategoria
&& t.Dificultad.Id == pDificultad
&& t.Conjunto.ConjuntoId == pConjunto
select t;
if (list.Count() >= pCantidad)
{
return list.ToList().OrderBy(x => rnd.Next()).Take(pCantidad);
return list;
}
else
{
Expand All @@ -70,7 +70,8 @@ public string GetOrCreate(string pNombre, string pConjunto)
{
var manager = ((IObjectContextAdapter)iDbContext).ObjectContext;

var dbPregunta = iDbContext.Preguntas.ToList().Where(x => x.Nombre == pNombre && x.Conjunto.Nombre == pConjunto).Any();
var dbPregunta = iDbContext.Preguntas.Include(x => x.Conjunto).ToList()
.Where(x => x.Nombre == pNombre && x.Conjunto.Nombre == pConjunto).Any();



Expand Down Expand Up @@ -110,5 +111,34 @@ public IEnumerable<Categoria> ObtenerCategorias(int pConjunto)
}
return listaCategorias;
}

/// <summary>
/// Este método se utiliza para obtener todas las instancias de la clase Pregunta
/// las cuales poseen una sesión activa, a partir de su ID.
/// </summary>
/// <param name="pIdSesion">El ID de la sesión activa</param>
/// <returns></returns>
public IEnumerable<Pregunta> ObtenerPreguntasPorSesion(int pIdSesion)
{
var preguntasFiltradas = (from p in iDbContext.Preguntas.Include(x => x.Respuestas)
where p.SesionActualId == pIdSesion
select p);
return preguntasFiltradas;
}

/// <summary>
/// Este método se utiliza para obtener una pregunta y sus respuestas
/// a partir de si ID.
/// </summary>
/// <param name="pIdPregunta">El ID de la pregunta a traer</param>
/// <returns></returns>
public Pregunta ObtenerPreguntaPorId(int pIdPregunta)
{
var pregunta = (from p in iDbContext.Preguntas.Include(x => x.Respuestas)
where p.PreguntaId == pIdPregunta
select p
);
return pregunta.First();
}
}
}
45 changes: 45 additions & 0 deletions ShockQuiz/DAL/EntityFramework/RepositorioSesion.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ShockQuiz.Dominio;
using System.Collections.Generic;
using System.Linq;
using System;

namespace ShockQuiz.DAL.EntityFramework
{
Expand Down Expand Up @@ -36,5 +37,49 @@ public IEnumerable<Sesion> ObtenerTodas(string pUsuario)
{
return this.iDbContext.Set<Sesion>().Where(x => x.Usuario.Nombre == pUsuario);
}

/// <summary>
/// Devuelve la sesion que se encuentre activa en la base de datos.
/// </summary>
/// <returns></returns>
public IEnumerable<Sesion> ObtenerSesionActiva()
{
var sesionActiva = from s in iDbContext.Sesiones
.Include("Conjunto")
.Include("Categoria")
.Include("Dificultad")
where !s.SesionFinalizada
select s;
return sesionActiva;
}

/// <summary>
/// Este método se utiliza para obtener la última sesión que se ha
/// subido a la base de datos.
/// </summary>
/// <returns></returns>
public Sesion ObtenerUltimaSesion()
{
var ultimaSesion = from s in iDbContext.Sesiones
.Include("Conjunto")
select s;
return ultimaSesion.OrderByDescending(x => x.SesionId).First();
}

/// <summary>
/// Este método se utiliza para obtener una sesión de la base de datos
/// a partir de su ID, así como su conjunto y dificultad.
/// </summary>
/// <param name="pIdSesion">El ID de la sesión a traer</param>
/// <returns></returns>
public Sesion ObtenerSesionId(int pIdSesion)
{
var sesionActiva = from s in iDbContext.Sesiones
.Include("Conjunto")
.Include("Dificultad")
where s.SesionId == pIdSesion
select s;
return sesionActiva.First();
}
}
}
5 changes: 4 additions & 1 deletion ShockQuiz/DAL/EntityFramework/RepositorioUsuario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public IEnumerable<Usuario> ObtenerTodos()
/// <returns></returns>
public Usuario ObtenerPorNombre(string pNombre)
{
return this.iDbContext.Set<Usuario>().First(x => x.Nombre == pNombre);
var usuarios = (from u in iDbContext.Usuarios
where u.Nombre == pNombre
select u);
return usuarios.First();
}
}
}
2 changes: 1 addition & 1 deletion ShockQuiz/DAL/EntityFramework/ShockQuizDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class ShockQuizDbContext : DbContext
{
public ShockQuizDbContext() : base("ShockQuiz")
{
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ShockQuizDbContext, Migrations.Configuration>());
//Database.SetInitializer(new MigrateDatabaseToLatestVersion<ShockQuizDbContext, Migrations.Configuration>());
}

public DbSet<Pregunta> Preguntas { get; set; }
Expand Down
4 changes: 3 additions & 1 deletion ShockQuiz/DAL/IRepositorioPregunta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ public interface IRepositorioPregunta : IRepositorio<Pregunta>

{
void AgregarPreguntas(IEnumerable<Pregunta> pPreguntas);
IEnumerable<Pregunta> ObtenerPreguntas(Categoria pCategoria, Dificultad pDificultad, Conjunto pConjunto, int pCantidad);
IEnumerable<Pregunta> ObtenerPreguntas(int pCategoria, int pDificultad, int pConjunto, int pCantidad);
IEnumerable<Pregunta> ObtenerTodas();
string GetOrCreate(string pNombre, string pConjunto);
IEnumerable<Categoria> ObtenerCategorias(int pConjunto);
IEnumerable<Pregunta> ObtenerPreguntasPorSesion(int pIdSesion);
Pregunta ObtenerPreguntaPorId(int pIdPregunta);
}
}
3 changes: 3 additions & 0 deletions ShockQuiz/DAL/IRepositorioSesion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ public interface IRepositorioSesion : IRepositorio<Sesion>
{
IEnumerable<Sesion> ObtenerTodas(string pUsuario);
IEnumerable<Sesion> ObtenerRanking(int pTop);
IEnumerable<Sesion> ObtenerSesionActiva();
Sesion ObtenerUltimaSesion();
Sesion ObtenerSesionId(int pIdSesion);
}
}
77 changes: 34 additions & 43 deletions ShockQuiz/DAL/OpenTriviaDB/JsonMapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using ShockQuiz.DAL.EntityFramework;
using ShockQuiz.Dominio;
using ShockQuiz.IO;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -55,7 +56,7 @@ public static string ObtenerToken()
/// <param name="pToken">API Token</param>
/// <param name="pNumber">Cantidad de Preguntas</param>
/// <returns></returns>
public static List<Pregunta> AlmacenarPreguntas(string pToken = null, int pNumber = 10)
public static List<Pregunta> GetPreguntas(string pToken = null, int pNumber = 10)
{
List<Pregunta> listaPreguntas = new List<Pregunta>();
string CONJUNTO = "OpenTDB";
Expand All @@ -82,56 +83,46 @@ public static List<Pregunta> AlmacenarPreguntas(string pToken = null, int pNumbe
// Se parsea la respuesta y se serializa a JSON a un objeto dynamic
dynamic mResponseJSON = JsonConvert.DeserializeObject(reader.ReadToEnd());

using (var bDbContext = new ShockQuizDbContext())
// Se iteran cada uno de los resultados.
foreach (var bResponseItem in mResponseJSON.results)
{
using (UnitOfWork bUoW = new UnitOfWork(bDbContext))
{
// Se iteran cada uno de los resultados.
foreach (var bResponseItem in mResponseJSON.results)
{

string preguntaDesc = HttpUtility.HtmlDecode(bResponseItem.question.ToString());
string categoria = HttpUtility.HtmlDecode(bResponseItem.category.ToString());
string dificultad = HttpUtility.HtmlDecode(bResponseItem.difficulty.ToString());
string preguntaDesc = HttpUtility.HtmlDecode(bResponseItem.question.ToString());
string categoria = HttpUtility.HtmlDecode(bResponseItem.category.ToString());
string dificultad = HttpUtility.HtmlDecode(bResponseItem.difficulty.ToString());

List<Respuesta> respuestas = new List<Respuesta>();
Respuesta respuestaCorrecta = new Respuesta()
{
EsCorrecta = true,
DefRespuesta = HttpUtility.HtmlDecode(bResponseItem.correct_answer.ToString())
};
respuestas.Add(respuestaCorrecta);
List<Respuesta> respuestas = new List<Respuesta>();
Respuesta respuestaCorrecta = new Respuesta()
{
EsCorrecta = true,
DefRespuesta = HttpUtility.HtmlDecode(bResponseItem.correct_answer.ToString())
};
respuestas.Add(respuestaCorrecta);

for (int i = 0; i < 3; i++)
{
Respuesta res = new Respuesta()
{
DefRespuesta = HttpUtility.HtmlDecode(bResponseItem.incorrect_answers[i].ToString()),
EsCorrecta = false
};
respuestas.Add(res);
}
for (int i = 0; i < 3; i++)
{
Respuesta res = new Respuesta()
{
DefRespuesta = HttpUtility.HtmlDecode(bResponseItem.incorrect_answers[i].ToString()),
EsCorrecta = false
};
respuestas.Add(res);
}

Pregunta pregunta = new Pregunta()
{
Nombre = bUoW.RepositorioPregunta.GetOrCreate(preguntaDesc, CONJUNTO),
Categoria = bUoW.RepositorioCategoria.GetOrCreate(categoria),
Dificultad = bUoW.RepositorioDificultad.GetOrCreate(dificultad),
Conjunto = bUoW.RepositorioConjunto.Get(CONJUNTO),
Respuestas = respuestas
};
if (pregunta.Nombre != string.Empty)
{
bUoW.RepositorioPregunta.Agregar(pregunta);
}
}
bUoW.GuardarCambios();
Pregunta pregunta = new Pregunta()
{
Nombre = preguntaDesc,
Categoria = new Categoria() { Nombre = categoria },
Dificultad = new Dificultad() { Nombre = dificultad },
ConjuntoNombre = CONJUNTO,
Respuestas = respuestas
};
if (pregunta.Nombre != string.Empty)
{
listaPreguntas.Add(pregunta);
}
}
}
}


catch (WebException ex)
{
WebResponse mErrorResponse = ex.Response;
Expand Down
1 change: 0 additions & 1 deletion ShockQuiz/Dominio/Categoria.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class Categoria
{
public int Id { get; set; }
public string Nombre { get; set; }

public ICollection<Sesion> Sesiones { get; set; }
public ICollection<Pregunta> Preguntas { get; set; }
}
Expand Down
14 changes: 10 additions & 4 deletions ShockQuiz/Dominio/ConjuntoOTDB.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using ShockQuiz.DAL.OpenTriviaDB;
using ShockQuiz.Forms;
using System;
using System.Collections.Generic;

namespace ShockQuiz.Dominio
{
public class ConjuntoOTDB : Conjunto
{
FachadaConfiguracionAdmin fachada = new FachadaConfiguracionAdmin();

public override double CalcularPuntaje(Sesion pSesion)
{
int TIEMPO_LIMITE_1 = 5;
Expand All @@ -25,7 +29,7 @@ public override double CalcularPuntaje(Sesion pSesion)
break;
}
double FACTOR_TIEMPO = 1;
double tiempoPorPregunta = pSesion.Duracion().TotalSeconds / pSesion.CantidadPreguntas;
double tiempoPorPregunta = pSesion.SegundosTranscurridos / pSesion.CantidadTotalPreguntas;
if (tiempoPorPregunta < TIEMPO_LIMITE_1)
{
FACTOR_TIEMPO = 5;
Expand All @@ -38,7 +42,7 @@ public override double CalcularPuntaje(Sesion pSesion)
{
FACTOR_TIEMPO = 3;
}
double puntaje = ((double)pSesion.RespuestasCorrectas / (double)pSesion.CantidadPreguntas) * FACTOR_DIFICULTAD * FACTOR_TIEMPO;
double puntaje = ((double)pSesion.RespuestasCorrectas / (double)pSesion.CantidadTotalPreguntas) * FACTOR_DIFICULTAD * FACTOR_TIEMPO;
return Math.Round(puntaje, 2);
}

Expand All @@ -50,13 +54,15 @@ public override void AgregarPreguntas(int pCantidad, string pToken = null)
int aux = pCantidad;
while (aux > 0)
{
JsonMapper.AlmacenarPreguntas(pToken, aux);
List<Pregunta> preguntas = JsonMapper.GetPreguntas(pToken, aux);
fachada.AlmacenarPreguntas(preguntas);
aux -= 50;
}
}
else
{
JsonMapper.AlmacenarPreguntas(pToken, pCantidad);
List<Pregunta> preguntas = JsonMapper.GetPreguntas(pToken, pCantidad);
fachada.AlmacenarPreguntas(preguntas);
}
}
}
Expand Down
Loading