Skip to content

Commit

Permalink
Merge pull request #30 from egc-sierrezuela-3/feature/visualizaciones-1
Browse files Browse the repository at this point in the history
Feature/visualizaciones 1
  • Loading branch information
jesrolcad authored Dec 21, 2021
2 parents f85c53f + 538aa5b commit d057501
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
55 changes: 50 additions & 5 deletions decide/visualizer/templates/visualizer/visualizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,32 @@
</b-navbar>

<div class="voting container">
<h1>[[ voting.id ]] - [[ voting.name ]]</h1>
<div v-if="!voting.start_date">
<h4>Título: [[voting.name]]</h4>
<h6>Estado: Votación no comenzada.</h6>
</div>

<div v-else-if="!voting.end_date">
<div id="head-voting-v">
<h4>Título: [[voting.name]]</h4>
<h6>Estado: Votación en progreso.</h6>

</div>

<h2 v-if="!voting.start_date">Votación no comenzada</h2>
<h2 v-else-if="!voting.end_date">Votación en curso</h2>
<div v-else>
<div id="statistics-voting" class="row">
<h6>Censo: {{stats_census_size}}</h6>
<h6>Porcentaje de participación: {{stats_participation_ratio}}</h6>
<h6>Número de votos: {{stats_voters_turnout}}</h6>
</div>
<div>
<h4>Gráfico</h4>
<canvas id="graficoPorcentajeVotaciones"></canvas>

</div>
</div>
<div v-else-if="voting.end_date">
<h4>Título: [[voting.name]]</h4>
<h6>Estado: Cerrada</h6>
<h2 class="heading">Resultados:</h2>

<table class="table table-bordered table-striped">
Expand All @@ -41,9 +62,13 @@ <h2 class="heading">Resultados:</h2>
</tbody>
</table>
</div>

</div>
</div>





{% endblock %}

{% block extrabody %}
Expand All @@ -62,5 +87,25 @@ <h2 class="heading">Resultados:</h2>
}
})
</script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@latest/dist/Chart.min.js"></script>
<script>
var ctx = document.getElementById('graficoPorcentajeVotaciones').getContext('2d');
var a1="{{stats_census_size}}";
var a2="{{stats_voters_turnout}}";

var chart = new Chart(ctx, {
type: 'doughnut',
data:{
datasets: [{
data: [a1,a2],
backgroundColor: [ 'red','blue'],
label: 'Estado de la votación'}],
labels: ['Número de personas que han votado','Número de personas que no han votado']},
options: {responsive: true}
});
</script>

</body>
{% endblock %}


34 changes: 31 additions & 3 deletions decide/visualizer/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +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


Expand All @@ -14,9 +15,36 @@ 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])
except:

if r[0]['end_date'] is None:
stats = {}
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
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

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


0 comments on commit d057501

Please sign in to comment.