Skip to content
This repository
Browse code

add different kinds of votes

  • Loading branch information...
commit 92a9b2967d125c52ffc4d600f37153e5f8989efa 1 parent f288621
Carlos Villela cv authored

Showing 1 changed file with 14 additions and 11 deletions. Show diff stats Hide diff stats

  1. +14 11 spikes/votes-viz/views/parliamentary.slim
25 spikes/votes-viz/views/parliamentary.slim
@@ -158,26 +158,29 @@ html
158 158 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]}'"
159 159
160 160 d3.json(jsonUrlQuery, function(data) {
161   - var attended = data.filter(function(e) { return e.voto != 'Ausente'; }).length;
  161 + var attended = data.filter(function(e) { return e.voto == 'Presente'; }).length;
162 162 var approvals = data.filter(function(e) { return e.voto == 'Sim'; }).length
163 163 var rejections = data.filter(function(e) { return e.voto == 'Não'; }).length
164 164 var abstained = data.filter(function(e) { return e.voto == 'Não votou'; }).length
165 165 var external = data.filter(function(e) { return e.voto == 'Representação externa'; }).length
166 166
167   - d3.select('#assiduity .value').html(Math.round((attended / data.length) * 100) + '%');
168   - d3.select('#assiduity .detail').html(attended + ' / ' + data.length);
  167 + var presenceData = data.filter(function(e) { return e.voto == 'Presente' || e.voto == 'Ausente'; })
  168 + var votingPoolSize = data.length - presenceData.length;
169 169
170   - d3.select('#approvals .value').html(Math.round((approvals / data.length) * 100) + '%');
171   - d3.select('#approvals .detail').html(approvals + ' / ' + data.length);
  170 + d3.select('#assiduity .value').html(Math.round((attended / presenceData.length) * 100) + '%');
  171 + d3.select('#assiduity .detail').html(attended + ' / ' + presenceData.length);
172 172
173   - d3.select('#rejections .value').html(Math.round((rejections / data.length) * 100) + '%');
174   - d3.select('#rejections .detail').html(rejections + ' / ' + data.length);
  173 + d3.select('#approvals .value').html(Math.round((approvals / votingPoolSize) * 100) + '%');
  174 + d3.select('#approvals .detail').html(approvals + ' / ' + votingPoolSize);
175 175
176   - d3.select('#abstained .value').html(Math.round((abstained / data.length) * 100) + '%');
177   - d3.select('#abstained .detail').html(abstained + ' / ' + data.length);
  176 + d3.select('#rejections .value').html(Math.round((rejections / votingPoolSize) * 100) + '%');
  177 + d3.select('#rejections .detail').html(rejections + ' / ' + votingPoolSize);
178 178
179   - d3.select('#external .value').html(Math.round((external / data.length) * 100) + '%');
180   - d3.select('#external .detail').html(external + ' / ' + data.length);
  179 + d3.select('#abstained .value').html(Math.round((abstained / votingPoolSize) * 100) + '%');
  180 + d3.select('#abstained .detail').html(abstained + ' / ' + votingPoolSize);
  181 +
  182 + d3.select('#external .value').html(Math.round((external / votingPoolSize) * 100) + '%');
  183 + d3.select('#external .detail').html(external + ' / ' + votingPoolSize);
181 184 });
182 185
183 186 div#statistics

0 comments on commit 92a9b29

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