<commit_before>#!/usr/bin/env python
#    Copyright © 2016 RunasSudo (<NAME>)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# I love the smell of Python 3 in the morning

import utils
import argparse, itertools, json, sys

parser = argparse.ArgumentParser(description='Convert a Helios election result to an OpenSTV blt file.')

parser.add_argument('election', help='Helios-style election.json specifying candidates')
parser.add_argument('result', help='Helios-style gamma encoded result.json specifying ballots')
parser.add_argument('seats', type=int, help='The number of candidates to elect')
parser.add_argument('question', type=int, help='The question number to tally', nargs='?', default=0)
args = parser.parse_args()

candidates = []
with open(args.election, 'r') as electionFile:
	election = json.load(electionFile)
	
	candidates = []
	for candidate in election["questions"][args.question]["answers"]:
		candidates.append(utils.Candidate(candidate.split("/")[0])) # Just want the name

with open(args.result, 'r') as resultFile:
	results = json.load(resultFile)
	
	ballots = []
	# Preprocess groups
	for result, group in itertools.groupby(sorted(results[args.question])):
		preferences = utils.to_absolute_answers(utils.gamma_decode(result, len(candidates)), len(candidates))
		ballots.append(utils.Ballot([candidates[x] for x in preferences], None, len(list(group))))<commit_msg>Update gamma_to_blt for new result format<commit_after>#!/usr/bin/env python
#    Copyright © 2016 RunasSudo (<NAME>)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

# I love the smell of Python 3 in the morning

import utils
import argparse, itertools, json, sys

parser = argparse.ArgumentParser(description='Convert a Helios election result to an OpenSTV blt file.')

parser.add_argument('election', help='Helios-style election.json specifying candidates')
parser.add_argument('result', help='Helios-style gamma encoded result.json specifying ballots')
parser.add_argument('seats', type=int, help='The number of candidates to elect')
parser.add_argument('question', type=int, help='The question number to tally', nargs='?', default=0)
args = parser.parse_args()

candidates = []
with open(args.election, 'r') as electionFile:
	election = json.load(electionFile)
	
	candidates = []
	for candidate in election["questions"][args.question]["answers"]:
		candidates.append(utils.Candidate(candidate.split("/")[0])) # Just want the name

with open(args.result, 'r') as resultFile:
	results = json.load(resultFile)
	
	result_squashed = [x[0] if isinstance(x, list) else x for x in results[args.question]]
	
	ballots = []
	# Preprocess groups
	for result, group in itertools.groupby(sorted(result_squashed)):
		preferences = utils.to_absolute_answers(utils.gamma_decode(result, len(candidates)), len(candidates))
		ballots.append(utils.Ballot([candidates[x] for x in preferences], None, len(list(group))))
{'fraction_non_alphanumeric': 0.10506116574718158, 'fraction_numerical': 0.004077716478771888, 'mean_word_length': 4.982783357245337, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7128326', 'n_tokens_mistral': 1238, 'n_tokens_neox': 1180, 'n_words': 439}