Skip to content

Commit

Permalink
Fast segmented mixing (#94)
Browse files Browse the repository at this point in the history
* Implementing support for segmented mixing

* WIP

* WIP

* adding some unit tests
  • Loading branch information
edulix committed Jan 13, 2023
1 parent 27ae882 commit e8915ba
Show file tree
Hide file tree
Showing 7 changed files with 559 additions and 20 deletions.
66 changes: 55 additions & 11 deletions tally-pipes
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,63 @@ from tally_pipes import main
import argparse

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Process and show tally '
'results. If no config is specified, it '
'parses results in raw.')
parser.add_argument('-t', '--tally', nargs='*', help='tally path', default=[])
parser.add_argument('-e', '--election-config', nargs='*', help='Instead of specifying a tally, you can specify an json election config and an empty ephemeral tally with zero votes will be created. recommended to use together with the multipart.append_ballots pipe.', default=[])
parser.add_argument('-x', '--tar', nargs='?', help='tar tallies output path')
parser.add_argument('-p', '--pipes-whitelist', help='path to the file containing the allowed pipes')
parser = argparse.ArgumentParser(
description=(
'Process and show tally results. If no config is specified, it '
'parses results in raw.'
)
)
parser.add_argument(
'-t',
'--tally',
nargs='*',
help='tally path',
default=[]
)
parser.add_argument(
'-e',
'--election-config',
nargs='*',
help=(
'Instead of specifying a tally, you can specify an json election '
'config and an empty ephemeral tally with zero votes will be '
'created. recommended to use together with the '
'multipart.append_ballots pipe.'
),
default=[]
)
parser.add_argument(
'-x',
'--tar',
nargs='?',
help='tar tallies output path'
)
parser.add_argument(
'-p',
'--pipes-whitelist',
help='path to the file containing the allowed pipes'
)
parser.add_argument('-c', '--config', help='config path')
parser.add_argument('-eid', '--election-id', help='election id', type=int)

parser.add_argument('-s', '--stdout', help='print output to stdout',
action='store_true')
parser.add_argument('-o', '--output-format', help='select the output format',
default="json", choices=["json", "csv", "tsv", "pretty", "none", "pdf"])
parser.add_argument(
'-s',
'--stdout',
help='print output to stdout',
action='store_true'
)
parser.add_argument(
'-o',
'--output-format',
help='select the output format',
default="json",
choices=["json", "csv", "tsv", "pretty", "none", "pdf"]
)
parser.add_argument(
'--segmented-election-config',
help='Path to the election config of an election with segmented mixing',
required=False,
default=None
)

main.main(parser.parse_args())
16 changes: 15 additions & 1 deletion tally_pipes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ def ballots_printer(vote, question, question_num, exception):

data_list[0]['ballots_printer'] = ballots_printer

if pargs.segmented_election_config:
from tally_pipes.utils.segmented_tally import apply_segmented_tally
apply_segmented_tally(
data_list=data_list,
segmented_election_config_path=pargs.segmented_election_config
)

execute_pipeline(
pipeline_info,
data_list,
Expand All @@ -539,7 +546,14 @@ def ballots_printer(vote, question, question_num, exception):
if pargs.tar and len(data_list) > 0 and 'results' in data_list[0]:
data_list[0]['results']['results_dirname'] = priv_results_dirname
from tally_pipes.utils.tallies import tar_tallies
tar_tallies(data_list, pipeline_info, pargs.tally, pargs.tar, pargs.election_id)
tar_tallies(
data_list,
pipeline_info,
pargs.tally,
pargs.tar,
pargs.election_id,
pargs.segmented_election_config
)

# dump the results in CSV,JSON and PRETTY format in the
# priv-results dir
Expand Down
Loading

0 comments on commit e8915ba

Please sign in to comment.