public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Jorge Manuel B. S. Vicetto" <jmbsvicetto@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elections:master commit in: /
Date: Wed,  6 Feb 2013 00:09:42 +0000 (UTC)	[thread overview]
Message-ID: <1360109242.483bd203ac3946803f533d9d6e2b975366f35914.jmbsvicetto@gentoo> (raw)

commit:     483bd203ac3946803f533d9d6e2b975366f35914
Author:     Jorge Manuel B. S. Vicetto (jmbsvicetto) <jmbsvicetto <AT> gentoo <DOT> org>
AuthorDate: Wed Feb  6 00:07:22 2013 +0000
Commit:     Jorge Manuel B. S. Vicetto <jmbsvicetto <AT> gentoo <DOT> org>
CommitDate: Wed Feb  6 00:07:22 2013 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/elections.git;a=commit;h=483bd203

Add ciaranm's script to generate vote distribution maps for an election.
Applied a small change to have the script take an election name parameter.

---
 election-grapher.rb |   99 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/election-grapher.rb b/election-grapher.rb
new file mode 100755
index 0000000..e316429
--- /dev/null
+++ b/election-grapher.rb
@@ -0,0 +1,99 @@
+#!/usr/bin/ruby19
+
+list = ARGF.argv
+
+if list.size != 1
+	puts "Invalid call. You need to pass the election name to this script"
+    exit(-1)
+end
+
+ElectionName = list.at(0)
+
+ResultsFile  = "master-" + ElectionName + ".txt"
+RankingsFile = ElectionName + "-rank.txt"
+ScaleSize    = 14
+HeightScale  = 5
+BarHeight    = 8
+
+# Get all candidate names and initialise their vote count
+candidates = Hash.new
+ballots = Hash.new
+File.open ResultsFile, "r" do | file |
+    file.each_line do | line |
+        next if line =~ /^-/
+        line.split(%r/\s+/).each do | person |
+            candidates[person] = [0] * ScaleSize unless candidates[person]
+        end
+    end
+
+    file.seek(0, IO::SEEK_SET)
+
+    key = false
+    file.each_line do | line |
+        if line =~ %r/^-/
+            key = line.split(/\s+/).grep(/^[a-fA-F0-9]{4}$/)[0]
+            ballots[key] = []
+        else
+            raise "key not set yet" unless key
+            ballots[key].push line.chomp.split(/\s+/)
+        end
+    end
+end
+
+# Add in missing candidates
+ballots.keys.each do | key |
+    append_candidates = candidates.keys.dup
+    ballots[key].flatten.each do | candidate |
+        append_candidates.delete_if do | item |
+            item == candidate
+        end
+    end
+    unless append_candidates.empty?
+        ballots[key].push append_candidates
+    end
+end
+
+# Calculate distributions
+ballots.each_pair do | ballot, results |
+    scale_by = ScaleSize / (0.0 + results.length)
+    results.each_with_index do | result, index |
+        place = (scale_by * index.to_f).to_i
+        raise "out of range" unless (0..ScaleSize - 1).include? place
+        result.each do | candidate |
+            candidates[candidate][place] += 1
+        end
+    end
+end
+
+# Read in rankings
+rankings = []
+File.open RankingsFile, "r" do | file |
+    file.each_line do | line |
+        key = line.split(/\s+/)[0]
+        rankings << key
+    end
+end
+
+
+# Display distributions
+candidates.keys.sort do | a, b |
+    rankings << a unless rankings.index a
+    rankings << b unless rankings.index b
+    (rankings.index a) <=> (rankings.index b)
+end.each do | candidate |
+    puts "  " + candidate + " (" + (rankings.index(candidate) + 1).to_s + ")"
+    BarHeight.downto(0) do | height |
+        print "|"
+        candidates[candidate].each do | value |
+            if value > (height * HeightScale)
+                print "#"
+            else
+                print " "
+            end
+        end
+        puts
+    end
+    puts "+" + ("-" * ScaleSize)
+    puts
+end
+


             reply	other threads:[~2013-02-06  0:09 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-06  0:09 Jorge Manuel B. S. Vicetto [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-06-02  0:13 [gentoo-commits] proj/elections:master commit in: / Robin H. Johnson
2024-05-25 17:14 Robin H. Johnson
2023-04-19 22:28 Robin H. Johnson
2022-07-01 19:12 Robin H. Johnson
2022-07-01 15:50 Robin H. Johnson
2022-06-30 22:36 Robin H. Johnson
2022-06-25 16:31 Robin H. Johnson
2022-06-25 13:58 Jorge Manuel B. S. Vicetto
2021-06-18  6:57 Robin H. Johnson
2021-06-18  6:57 Robin H. Johnson
2020-07-06  5:10 Robin H. Johnson
2020-06-20  5:17 Robin H. Johnson
2020-06-20  5:17 Robin H. Johnson
2017-06-25  0:04 Robin H. Johnson
2017-06-24 23:54 Robin H. Johnson
2016-07-21 18:07 Robin H. Johnson
2016-07-21 18:07 Robin H. Johnson
2016-07-03 15:01 Robin H. Johnson
2016-07-03 11:04 Jorge Manuel B. S. Vicetto
2016-06-19 12:13 Jorge Manuel B. S. Vicetto
2016-06-19 12:13 Jorge Manuel B. S. Vicetto
2016-06-18 17:28 Robin H. Johnson
2016-06-18 17:28 Robin H. Johnson
2016-06-18 17:28 Robin H. Johnson
2016-06-18 17:28 Robin H. Johnson
2015-06-28  0:12 Jorge Manuel B. S. Vicetto
2015-06-27 16:18 Robin H. Johnson
2013-06-30  6:32 Jorge Manuel B. S. Vicetto
2012-07-16 19:01 Christian Ruppert
2012-06-18 21:08 Christian Ruppert
2012-02-15  2:07 Robin H. Johnson
2011-06-20  6:14 Robin H. Johnson
2011-06-20  6:13 Robin H. Johnson
2011-06-20  6:13 Robin H. Johnson
2011-06-20  6:13 Robin H. Johnson
2011-06-20  6:13 Robin H. Johnson
2011-06-20  6:08 Robin H. Johnson
2011-06-09  7:46 Robin H. Johnson
2011-04-09  0:09 Robin H. Johnson
2011-03-12 18:41 Robin H. Johnson
2011-03-12 10:57 Robin H. Johnson
2011-03-12 10:56 Robin H. Johnson
2011-02-13  2:21 Robin H. Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1360109242.483bd203ac3946803f533d9d6e2b975366f35914.jmbsvicetto@gentoo \
    --to=jmbsvicetto@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox