Skip to content
Browse files

add different kinds of votes

  • Loading branch information...
1 parent f288621 commit 92a9b2967d125c52ffc4d600f37153e5f8989efa @cv cv committed Feb 20, 2013
Showing with 14 additions and 11 deletions.
  1. +14 −11 spikes/votes-viz/views/parliamentary.slim
View
25 spikes/votes-viz/views/parliamentary.slim
@@ -158,26 +158,29 @@ html
var jsonUrlQuery = "https://api.scraperwiki.com/api/1.0/datastore/sqlite?format=jsondict&name=votacoes&query=select%20*%20from%20%60presencas%60%0Awhere%20%60parlamentar%60%20%3D%20%20'#{params[:name]}'"
d3.json(jsonUrlQuery, function(data) {
- var attended = data.filter(function(e) { return e.voto != 'Ausente'; }).length;
+ var attended = data.filter(function(e) { return e.voto == 'Presente'; }).length;
var approvals = data.filter(function(e) { return e.voto == 'Sim'; }).length
var rejections = data.filter(function(e) { return e.voto == 'Não'; }).length
var abstained = data.filter(function(e) { return e.voto == 'Não votou'; }).length
var external = data.filter(function(e) { return e.voto == 'Representação externa'; }).length
- d3.select('#assiduity .value').html(Math.round((attended / data.length) * 100) + '%');
- d3.select('#assiduity .detail').html(attended + ' / ' + data.length);
+ var presenceData = data.filter(function(e) { return e.voto == 'Presente' || e.voto == 'Ausente'; })
+ var votingPoolSize = data.length - presenceData.length;
- d3.select('#approvals .value').html(Math.round((approvals / data.length) * 100) + '%');
- d3.select('#approvals .detail').html(approvals + ' / ' + data.length);
+ d3.select('#assiduity .value').html(Math.round((attended / presenceData.length) * 100) + '%');
+ d3.select('#assiduity .detail').html(attended + ' / ' + presenceData.length);
- d3.select('#rejections .value').html(Math.round((rejections / data.length) * 100) + '%');
- d3.select('#rejections .detail').html(rejections + ' / ' + data.length);
+ d3.select('#approvals .value').html(Math.round((approvals / votingPoolSize) * 100) + '%');
+ d3.select('#approvals .detail').html(approvals + ' / ' + votingPoolSize);
- d3.select('#abstained .value').html(Math.round((abstained / data.length) * 100) + '%');
- d3.select('#abstained .detail').html(abstained + ' / ' + data.length);
+ d3.select('#rejections .value').html(Math.round((rejections / votingPoolSize) * 100) + '%');
+ d3.select('#rejections .detail').html(rejections + ' / ' + votingPoolSize);
- d3.select('#external .value').html(Math.round((external / data.length) * 100) + '%');
- d3.select('#external .detail').html(external + ' / ' + data.length);
+ d3.select('#abstained .value').html(Math.round((abstained / votingPoolSize) * 100) + '%');
+ d3.select('#abstained .detail').html(abstained + ' / ' + votingPoolSize);
+
+ d3.select('#external .value').html(Math.round((external / votingPoolSize) * 100) + '%');
+ d3.select('#external .detail').html(external + ' / ' + votingPoolSize);
});
div#statistics

0 comments on commit 92a9b29

Please sign in to comment.
Something went wrong with that request. Please try again.