From 766d37775b0693e253d6291a7c7b39768b41aefd Mon Sep 17 00:00:00 2001 From: Maria Garcia Date: Sun, 19 Dec 2021 13:54:28 +0100 Subject: [PATCH 1/4] =?UTF-8?q?MOSTRAR=20INFORMACI=C3=93N=20EN=20TIEMPO=20?= =?UTF-8?q?REAL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se ha implementado una modificación en Visualizaciones, concretamente, ahora se puede conocer información en tiempo real relativa al estado, censo total, porcentaje de participación y número de votos de una votación sin finalizar. Para poder visualizar el cambio, iniciar una votación y acceder a /visualizer/idDeLaVotacion. García Cáceres, María <@margarcac1> --- .../templates/visualizer/visualizer.html | 21 ++++++++++++++++--- decide/visualizer/views.py | 21 ++++++++++++++++++- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/decide/visualizer/templates/visualizer/visualizer.html b/decide/visualizer/templates/visualizer/visualizer.html index 0faed6bac3..af30fca49d 100644 --- a/decide/visualizer/templates/visualizer/visualizer.html +++ b/decide/visualizer/templates/visualizer/visualizer.html @@ -17,11 +17,26 @@
-

[[ voting.id ]] - [[ voting.name ]]

+
+

Título: [[voting.name]]

+
Estado: Votación no comenzada.
+
+ +
+
+

Título: [[voting.name]]

+
Estado: Votación en progreso.
+
-

Votación no comenzada

-

Votación en curso

+
+
Censo: {{stats_census_size}}
+
Porcentaje de participación: {{stats_participation_ratio}}
+
Número de votos: {{stats_voters_turnout}}
+
+
+

Título: [[voting.name]]

+
Estado: Cerrada

Resultados:

diff --git a/decide/visualizer/views.py b/decide/visualizer/views.py index 8fea64ecb2..0e9ccb8909 100644 --- a/decide/visualizer/views.py +++ b/decide/visualizer/views.py @@ -2,6 +2,8 @@ from django.views.generic import TemplateView from django.conf import settings from django.http import Http404 +from census.models import Census +from store.models import Vote from base import mods @@ -16,7 +18,24 @@ def get_context_data(self, **kwargs): try: r = mods.get('voting', params={'id': vid}) context['voting'] = json.dumps(r[0]) - except: + + if r[0]['end_date'] is None: + stats = {} + stats['census_size'] = getEstadisticas('census_size', vid) + stats['voters_turnout'] = getEstadisticas('turnout', vid) + stats['participation_ratio'] = round((stats['voters_turnout']/stats['census_size'])*100,2) + for i,j in stats.items(): + context['stats_' + str(i)] = j + + except Exception: raise Http404 return context + +def getEstadisticas(requerido, vid): + if (requerido=="census_size"): + return Census.objects.filter(voting_id=vid).count() + elif (requerido=="turnout"): + return Vote.objects.filter(voting_id=vid).count() + else: + return None \ No newline at end of file From 66f17a27ecc4e253b093e915c3a68b2415413b92 Mon Sep 17 00:00:00 2001 From: Maria Garcia Date: Sun, 19 Dec 2021 14:15:32 +0100 Subject: [PATCH 2/4] MOSTRAR INFORMACION EN TIEMPO REAL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Se ha implementado la posibilidad de conocer la información relativa al censo, porcentaje de votantes,estado y número de votos de una votación si no ha finalizado. Para ver la información se debe iniciar una votación y abir /visualizer/idVotacion García Cáceres, María <@margarcac1> --- decide/visualizer/templates/visualizer/visualizer.html | 1 + decide/visualizer/views.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/decide/visualizer/templates/visualizer/visualizer.html b/decide/visualizer/templates/visualizer/visualizer.html index af30fca49d..18b138ffbf 100644 --- a/decide/visualizer/templates/visualizer/visualizer.html +++ b/decide/visualizer/templates/visualizer/visualizer.html @@ -33,6 +33,7 @@
Censo: {{stats_census_size}}
Porcentaje de participación: {{stats_participation_ratio}}
Número de votos: {{stats_voters_turnout}}
+

Título: [[voting.name]]

diff --git a/decide/visualizer/views.py b/decide/visualizer/views.py index 0e9ccb8909..4d0073b651 100644 --- a/decide/visualizer/views.py +++ b/decide/visualizer/views.py @@ -4,7 +4,6 @@ from django.http import Http404 from census.models import Census from store.models import Vote - from base import mods @@ -16,7 +15,7 @@ def get_context_data(self, **kwargs): vid = kwargs.get('voting_id', 0) try: - r = mods.get('voting', params={'id': vid}) + r = mods.get('voting', params={'id':vid}) context['voting'] = json.dumps(r[0]) if r[0]['end_date'] is None: @@ -24,6 +23,7 @@ def get_context_data(self, **kwargs): stats['census_size'] = getEstadisticas('census_size', vid) stats['voters_turnout'] = getEstadisticas('turnout', vid) stats['participation_ratio'] = round((stats['voters_turnout']/stats['census_size'])*100,2) + for i,j in stats.items(): context['stats_' + str(i)] = j From c6142d17c6bbbc8f8fdccb5bd5bc60a3da95313f Mon Sep 17 00:00:00 2001 From: Maria Garcia Date: Sun, 19 Dec 2021 21:12:20 +0100 Subject: [PATCH 3/4] =?UTF-8?q?SOLUCION=20BUG=20VISUALIZACION=20EN=20TIEMP?= =?UTF-8?q?O=20REAL=20El=20problema=20resid=C3=ADa=20en=20que=20no=20se=20?= =?UTF-8?q?craba=20la=20p=C3=A1gina=20de=20visualizaci=C3=B3n=20si=20todav?= =?UTF-8?q?=C3=ADa=20no=20hab=C3=ADa=20datos,=20es=20decir,=20si=20nadie?= =?UTF-8?q?=20hab=C3=ADa=20votado.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decide/visualizer/views.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/decide/visualizer/views.py b/decide/visualizer/views.py index 4d0073b651..502afb6ee8 100644 --- a/decide/visualizer/views.py +++ b/decide/visualizer/views.py @@ -20,13 +20,20 @@ def get_context_data(self, **kwargs): if r[0]['end_date'] is None: stats = {} - stats['census_size'] = getEstadisticas('census_size', vid) - stats['voters_turnout'] = getEstadisticas('turnout', vid) - stats['participation_ratio'] = round((stats['voters_turnout']/stats['census_size'])*100,2) + if(getEstadisticas('turnout', vid) != 0): + stats['census_size'] = getEstadisticas('census_size', vid) + stats['voters_turnout'] = getEstadisticas('turnout', vid) + stats['participation_ratio'] = round((stats['voters_turnout']/stats['census_size'])*100,2) - for i,j in stats.items(): - context['stats_' + str(i)] = j - + for i,j in stats.items(): + context['stats_' + str(i)] = j + else: + stats['census_size'] = 0 + stats['voters_turnout'] = 0 + stats['participation_ratio'] = 0 + + for i,j in stats.items(): + context['stats_' + str(i)] = j except Exception: raise Http404 From 538aa5b2f8d71ac1ed8e73fe081fbbe5488f3767 Mon Sep 17 00:00:00 2001 From: Maria Garcia Date: Mon, 20 Dec 2021 20:42:57 +0100 Subject: [PATCH 4/4] PINTADO DE GRAFICAS DE VOTACIONES EN CURSO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Las votaciones que se encuentren en curso poseerán un gráfico de anillos que mostrará el número de personas que ya han votado y las que faltan por votar. García Cáceres, María <@margarcac1> --- .../templates/visualizer/visualizer.html | 35 +++++++++++++++++-- decide/visualizer/views.py | 4 ++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/decide/visualizer/templates/visualizer/visualizer.html b/decide/visualizer/templates/visualizer/visualizer.html index 18b138ffbf..a8f1a3c108 100644 --- a/decide/visualizer/templates/visualizer/visualizer.html +++ b/decide/visualizer/templates/visualizer/visualizer.html @@ -26,6 +26,7 @@
Estado: Votación no comenzada.

Título: [[voting.name]]

Estado: Votación en progreso.
+
@@ -33,9 +34,13 @@
Censo: {{stats_census_size}}
Porcentaje de participación: {{stats_participation_ratio}}
Número de votos: {{stats_voters_turnout}}
- +
+

Gráfico

+ + +
-
+

Título: [[voting.name]]

Estado: Cerrada

Resultados:

@@ -57,9 +62,13 @@

Resultados:

-
+ + + + + {% endblock %} {% block extrabody %} @@ -78,5 +87,25 @@

Resultados:

} }) + + + {% endblock %} + + diff --git a/decide/visualizer/views.py b/decide/visualizer/views.py index 502afb6ee8..f96183f52d 100644 --- a/decide/visualizer/views.py +++ b/decide/visualizer/views.py @@ -45,4 +45,6 @@ def getEstadisticas(requerido, vid): elif (requerido=="turnout"): return Vote.objects.filter(voting_id=vid).count() else: - return None \ No newline at end of file + return None + +