Redesign results page
- Replace chart with table - Analyze tiebreak - Merge all info in a single list of cards Closes #25 Closes #13
This commit is contained in:
parent
d429c16a9e
commit
fdc2d53997
9 changed files with 4608 additions and 26673 deletions
1
Gemfile
1
Gemfile
|
|
@ -10,6 +10,5 @@ gem 'base64', '0.1.1'
|
||||||
gem 'forwardable', '1.3.2'
|
gem 'forwardable', '1.3.2'
|
||||||
gem 'bcrypt'
|
gem 'bcrypt'
|
||||||
gem 'gettext'
|
gem 'gettext'
|
||||||
gem 'chartkick'
|
|
||||||
gem 'mail'
|
gem 'mail'
|
||||||
gem 'redcarpet'
|
gem 'redcarpet'
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ GEM
|
||||||
bcrypt (3.1.20)
|
bcrypt (3.1.20)
|
||||||
benchmark (0.4.0)
|
benchmark (0.4.0)
|
||||||
bigdecimal (3.1.9)
|
bigdecimal (3.1.9)
|
||||||
chartkick (5.1.4)
|
|
||||||
concurrent-ruby (1.3.5)
|
concurrent-ruby (1.3.5)
|
||||||
connection_pool (2.5.0)
|
connection_pool (2.5.0)
|
||||||
date (3.4.1)
|
date (3.4.1)
|
||||||
|
|
@ -108,7 +107,6 @@ PLATFORMS
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
base64 (= 0.1.1)
|
base64 (= 0.1.1)
|
||||||
bcrypt
|
bcrypt
|
||||||
chartkick
|
|
||||||
forwardable (= 1.3.2)
|
forwardable (= 1.3.2)
|
||||||
gettext
|
gettext
|
||||||
mail
|
mail
|
||||||
|
|
|
||||||
24043
public/Chart.bundle.js
24043
public/Chart.bundle.js
File diff suppressed because it is too large
Load diff
4494
public/bootstrap.js
vendored
Normal file
4494
public/bootstrap.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
2570
public/chartkick.js
2570
public/chartkick.js
File diff suppressed because it is too large
Load diff
1
vedia.rb
1
vedia.rb
|
|
@ -9,7 +9,6 @@ require 'sinatra/activerecord'
|
||||||
require 'bcrypt'
|
require 'bcrypt'
|
||||||
require 'gettext'
|
require 'gettext'
|
||||||
require 'securerandom'
|
require 'securerandom'
|
||||||
require 'chartkick'
|
|
||||||
require 'mail'
|
require 'mail'
|
||||||
require 'ostruct'
|
require 'ostruct'
|
||||||
require 'tzinfo'
|
require 'tzinfo'
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,7 @@
|
||||||
<% else %>
|
<% else %>
|
||||||
<title>Vedia</title>
|
<title>Vedia</title>
|
||||||
<% end %>
|
<% end %>
|
||||||
<script src="/chartkick.js"></script>
|
<script src="/bootstrap.js"></script>
|
||||||
<script src="/Chart.bundle.js"></script>
|
|
||||||
<link rel="stylesheet" href="/bootstrap.css">
|
<link rel="stylesheet" href="/bootstrap.css">
|
||||||
<link rel="stylesheet" href="/bootstrap-icons.css">
|
<link rel="stylesheet" href="/bootstrap-icons.css">
|
||||||
<link rel="stylesheet" href="/style.css">
|
<link rel="stylesheet" href="/style.css">
|
||||||
|
|
|
||||||
|
|
@ -17,4 +17,8 @@
|
||||||
background-color: <%= v[:color] %>;
|
background-color: <%= v[:color] %>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.mj-cell-<%= v[:id] %> {
|
||||||
|
background-color: <%= v[:color] %> !important;
|
||||||
|
}
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="mb-4"><%= _("Candidates") %></h2>
|
|
||||||
|
|
||||||
<% @vote.candidates.each do |candidate| %>
|
|
||||||
<div class="card mb-4">
|
|
||||||
<div class="card-body">
|
|
||||||
<h3 class="mb-3"><%= candidate.name %></h3>
|
|
||||||
<%= markdown(candidate.description) %>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="mb-5"></div>
|
<div class="mb-5"></div>
|
||||||
|
|
||||||
<h2 class="mb-4"><%= _("Results") %></h2>
|
<h2 class="mb-4"><%= _("Results") %></h2>
|
||||||
|
|
@ -40,49 +29,115 @@
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
||||||
<table class="table mb-4">
|
<% r = 0 %>
|
||||||
<tr>
|
<% @results = @vote.candidates.sort { |a, b| a.mj <=> b.mj }.reverse %>
|
||||||
<th></th>
|
<% @results.each do |c| %>
|
||||||
<th><%= _("Rank") %></th>
|
<% r = r + 1 %>
|
||||||
<th><%= _("Candidate") %></th>
|
<div class="card mb-4">
|
||||||
<th><%= _("Majority Judgment") %></th>
|
<div class="card-body">
|
||||||
<th><%= _("Proponents") %></th>
|
<% if r == 1 %>
|
||||||
<th><%= _("Opponents") %></th>
|
<p class="fs-5">
|
||||||
</tr>
|
<i class="bi bi-trophy-fill"></i>
|
||||||
<% i = 0 %>
|
<%= _("Winning candidate") %>
|
||||||
<% @vote.candidates.sort { |a, b| a.mj <=> b.mj }.reverse.each do |candidate| %>
|
</p>
|
||||||
<% i = i + 1 %>
|
<p><%= _("The winning candidate is the candidate with the highest median vote (↓), called <a href='https://en.wikipedia.org/wiki/Majority_judgment'><i>majority judgment</i></a>.") %></p>
|
||||||
<% if i == 1 %>
|
<% end %>
|
||||||
<tr class="table-success">
|
<p class="fs-5">
|
||||||
<td><i class="bi bi-trophy-fill"></i></td>
|
<%= "##{r}" %>
|
||||||
<td><%= i %></i></td>
|
<% value = settings.values.select { |e| e[:id] == c.mj.mj }.first %>
|
||||||
<% else %>
|
<span class="badge bg-<%= value[:id] %>"><%= _(value[:label]) %></span>
|
||||||
<tr>
|
</p>
|
||||||
<td></td>
|
<h3><%= c.name %></h3>
|
||||||
<td><%= i %></td>
|
<table class="table table-borderless">
|
||||||
<% end %>
|
<tr>
|
||||||
<td><%= candidate.name %></td>
|
<% (1..c.mj.n).each do |i| %>
|
||||||
<% value = settings.values.select { |e| e[:id] == candidate.mj.mj }.first %>
|
<td class="text-center <% unless i == c.mj.majority %>opacity-0<% end %>">↓</td>
|
||||||
<td class="h5"><span class="badge bg-<%= value[:id] %>"><%= _(value[:label]) %></span></td>
|
<% end %>
|
||||||
<td><%= candidate.mj.proponents %></td>
|
</tr>
|
||||||
<td><%= candidate.mj.opponents %></td>
|
<tr>
|
||||||
</tr>
|
<% settings.values.reverse.each do |v| %>
|
||||||
<% end %>
|
<% (1..c.mj.count[v[:id]]).each do |r| %>
|
||||||
</table>
|
<td class="mj-cell-<%= v[:id] %>"> </td>
|
||||||
|
<% end %>
|
||||||
<%
|
<% end %>
|
||||||
data = []
|
</tr>
|
||||||
colors = []
|
</table>
|
||||||
settings.values.reverse.each do |v|
|
<p class="d-inline-flex gap-3">
|
||||||
d = { name: _(v[:label]), data: [] }
|
<a class="btn btn-outline-primary" data-bs-toggle="collapse" href="#description-<%= r %>" role="button" aria-expanded="false" aria-controls="description-<%= r %>">
|
||||||
@vote.candidates.sort { |a, b| a.mj <=> b.mj }.reverse.each do |c|
|
<%= _("See description") %>
|
||||||
d[:data] << [c.name, c.mj.count[v[:id]]]
|
</a>
|
||||||
end
|
<% if r > 1 and c.mj.mj == @results.first.mj.mj %>
|
||||||
data << d
|
<a class="btn btn-primary" data-bs-toggle="collapse" href="#tiebreak-<%= r %>" role="button" aria-expanded="false" aria-controls="tiebreak-<%= r %>">
|
||||||
colors << v[:color]
|
<%= _("Analyze tiebreak") %>
|
||||||
end
|
</a>
|
||||||
%>
|
<% end %>
|
||||||
<%= bar_chart data, colors: colors, stacked: true, legend: 'bottom' %>
|
</p>
|
||||||
|
<div class="collapse" id="description-<%= r %>">
|
||||||
|
<%= markdown(c.description) %>
|
||||||
|
</div>
|
||||||
|
<% if r > 1 and c.mj.mj == @results.first.mj.mj %>
|
||||||
|
<div class="collapse" id="tiebreak-<%= r %>">
|
||||||
|
<p>
|
||||||
|
<%= _("This candidate and the winning candidate have the same majority judgment.") %>
|
||||||
|
</p>
|
||||||
|
<p><%= _("To break the tie, we remove the vote that corresponds to the majority judgment one-by-one until one candidate has a better majority judgment than the other.") %></p>
|
||||||
|
<div class="row fw-bold">
|
||||||
|
<div class="col"><%= _("Votes for this candidate") %></div>
|
||||||
|
<div class="col text-end"><%= _("Votes for the winning candidate") %></div>
|
||||||
|
</div>
|
||||||
|
<% n = 0 %>
|
||||||
|
<% c.mj.break_tie(@results.first.mj).each do |a, b| %>
|
||||||
|
<hr>
|
||||||
|
<% if n == 0 %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col"><%= _("Without removing any vote.") %></div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if n == 1 %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col"><%= _("Removing 1 vote.") %></div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% if n > 1 %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col"><%= _("Removing %{n} votes.") % { n: n } %></div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<table class="table table-borderless">
|
||||||
|
<tr>
|
||||||
|
<% (1..a.n).each do |i| %>
|
||||||
|
<td class="text-center <% unless i == a.majority %>opacity-0<% end %>">↓</td>
|
||||||
|
<% end %>
|
||||||
|
<th class="w-100"></th>
|
||||||
|
<% (1..b.n).each do |i| %>
|
||||||
|
<td class="text-center <% unless b.n - i + 1 == b.majority %>opacity-0<% end %>">↓</td>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<% settings.values.reverse.each do |v| %>
|
||||||
|
<% (1..a.count[v[:id]]).each do |r| %>
|
||||||
|
<td class="mj-cell-<%= v[:id] %>"> </td>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<td class="text-center fw-bold">
|
||||||
|
<% if a.mj < b.mj %><<% end %>
|
||||||
|
<% if a.mj > b.mj %>><% end %>
|
||||||
|
<% if a.mj == b.mj %>=<% end %>
|
||||||
|
</td>
|
||||||
|
<% settings.values.each do |v| %>
|
||||||
|
<% (1..b.count[v[:id]]).each do |r| %>
|
||||||
|
<td class="mj-cell-<%= v[:id] %>"> </td>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<% n = n + 1 %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<div class="mb-5"></div>
|
<div class="mb-5"></div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue