Skip to content

Commit

Permalink
Version 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
hbiede committed Mar 4, 2024
1 parent 6c87cfc commit 6afaaee
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 54 deletions.
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,3 @@ Download the CSV of your ballots to data/votes.csv and then run the following co
```
ruby vote_parser.rb data/votes.csv data/tokens.csv
```

##### Parse Ballots from Google Sheets
If your ballots are stored on the first sheet of a Google Sheet in range B1:G, you can
download and parse votes all in one command:
```
make URL=https://docs.google.com/spreadsheets/d/DOCUMENT_ID/export?exportFormat=csv&range=B1:G
```
**Note: you must change DOCUMENT_ID to the alphanumeric code in the link to your Google
Sheet. The Sheet *must* be viewable by anyone.**
40 changes: 0 additions & 40 deletions data/output.txt

This file was deleted.

13 changes: 9 additions & 4 deletions gen_tokens.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# frozen_string_literal: true

# Author: Hundter Biede (hbiede.com)
# Version: 1.2
# Version: 1.3
# License: MIT
require 'csv'
require 'optparse'

# Whether or not to generate PDFs
generate_pdfs = true
OptionParser.new do |opt|
opt.on('-n', '--no-pdfs', 'Disable PDF generation') { generate_pdfs = false }
end.parse!

# Regex to match the following alphabet: ^[a-km-zA-HJ-NPRT-Z2-46-9]{7,7}$
# noinspection SpellCheckingInspection
Expand Down Expand Up @@ -70,9 +74,10 @@ def self.create_latex_content(tex_file, org, org_passwords)
# @param [Integer] longest_org_name_length The length of the longest org name
def self.print_progress_report(index, org, number_of_orgs, longest_name_length)
percent_done = (index + 1.0) / number_of_orgs
filled_char_count = (14 * percent_done).floor
# rubocop:disable Lint/FormatParameterMismatch
format("\r%.2f%%%% [%s%s]: PDF generated for %-#{longest_name_length}s",
100 * percent_done, '=' * (15 * percent_done).ceil, ' ' * (15 * (1 - percent_done)).floor, org)
format("\r%.2f%%%% [=%s%s]: PDF generated for %-#{longest_name_length}s",
100 * percent_done, '=' * filled_char_count, ' ' * (14 - filled_char_count), org)
# rubocop:enable Lint/FormatParameterMismatch
end

Expand All @@ -89,7 +94,7 @@ def self.create_pdfs(all_tokens, tex_file)
printf(print_progress_report(i, org, all_tokens.size, longest_org_name))
end
# Clear the progress bar
print("\r")
print("\rAll PDFs generated!")

system('mv *.pdf pdfs/')
system('rm *.out *.aux *.log *.tex')
Expand Down
5 changes: 5 additions & 0 deletions tests/gen_tokens_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ def test_create_latex_content
end

def test_create_pdfs
orig_stdout = $stdout.clone
$stdout = File.new(File::NULL,"w")

tokens = {
'James Madison' => %w[1 2],
"James Monroe" => %w[3 4],
Expand All @@ -97,6 +100,8 @@ def test_create_pdfs
File.delete "pdfs/JamesMadison.pdf"
File.delete "pdfs/JohnQAdams.pdf"
end
ensure
$stdout = orig_stdout
end
end

Expand Down
13 changes: 12 additions & 1 deletion tests/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@
enable_coverage :branch
end

Test::Unit::AutoRunner.run(true, File.dirname(__FILE__))
def disable_stderr
orig_stderr = $stderr.clone
$stderr = File.new(File::NULL, 'w')

yield
ensure
$stderr = orig_stderr
end

disable_stderr do
Test::Unit::AutoRunner.run(true, File.dirname(__FILE__))
end

if ENV['CI'] == 'true'
require 'codecov'
Expand Down
5 changes: 5 additions & 0 deletions tests/vote_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ def test_process_votes
#noinspection RubyResolve
class TestOutputPrinter < Test::Unit::TestCase
def test_write_output
orig_stdout = $stdout.clone
$stdout = File.new(File::NULL,"w")

begin
OutputPrinter.write_output('REPORT', 'WARNING', nil)
rescue
Expand All @@ -416,6 +419,8 @@ def test_write_output
contents = file.read
assert_true(contents.match?(/\sThis is a fake election report that needs to be seen\s/m))
File.delete file
ensure
$stdout = orig_stdout
end

def test_write_election_report
Expand Down

0 comments on commit 6afaaee

Please sign in to comment.