Skip to content

Instantly share code, notes, and snippets.

@Findeton
Created February 14, 2017 17:10
Show Gist options
  • Select an option

  • Save Findeton/e5178359cf5f088793ace7aedc8bc4f3 to your computer and use it in GitHub Desktop.

Select an option

Save Findeton/e5178359cf5f088793ace7aedc8bc4f3 to your computer and use it in GitHub Desktop.
gen_votes.py
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# This file is part of agora_elections.
# Copyright (C) 2017 Agora Voting SL <nvotes@nvotes.com>
# agora-results 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.
# agora-results 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 agora-results. If not, see <http://www.gnu.org/licenses/>.
import os
import argparse
import string
def gen_id(length):
alphabet = 'abcdef0123456789'
return ''.join(alphabet[c % len(alphabet)] for c in os.urandom(length))
def gen_votes(args):
num_votes = 10**6
votes_file = "votes"
voter_ids_file = "voter_ids"
vote_example6 = '''{"choices":[{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"}],"issue_date":"05/12/2016","proofs":[{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"}]}'''
vote_example3 = '''{"choices":[{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"},{"alpha":"25882755222282778250311255283381090693581781507481396271987450096477904938765547059415384125494795855924854885165230544240617120220604823745424472526870764955275942240742586445648470028761440238512481196438889259888585682206518583665515333831215017445017107993450318769310222148882822403456688822718051337314374307878933324474711510446295834133288998624070413885608579725918882738877546185450793395297303835586708607959814528707702226860151005833335531738870035085873225808071360975908758197202590125362114955357411805188165146012020200102746085564516818206151432571649258364224080155189638746653077006562829608122353","beta":"28476848545026441488704415495077836825690670064020492976063545525489804882537211198668007238576517548974533267621475642901812225918879426739269361506719582477764094406496031354058494510753880983226396168109078504374022014287094876121160070179881296404967616043768508452003226521910043579560543919169451352882499920635846502430505275770451321058475923107195671522418337308926331760513433833409934552639483440401170315049192850315292678714274439700939896681308216929826896735907029298394051366909667117955598603199340267004443160665152022205595158621230070774161264554024079016784792309521589898301829006247460593814121"}],"issue_date":"05/12/2016","proofs":[{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"},{"challenge":"20383545286574191839577730216696310547742201806269354743793750866031410179438","commitment":"5748124392932912993582310979475906685849113277197033084070978208616190109662406154123619170245586842160036628130366882950412324608672724535717842603085736942447638715752175782725016466411251176415274962590649587866189061998909837995767231085915719995842506531740932053799944150624467833682185988457844020514198749309676984056636845533211109366767532677407052184123998473976537019192511311877514625826392383351040588067965283657890671946889113737160644671510054647150551716610383456974708377092466511598041725159175601992608288955089168428267739422538576194632052136537220104096718716768536612850896234661057141196015","response":"7388208632546742050170316430303926262040577604949114900649017139340454498843010306397399616709279579175810972139099690302566936828131456978769963923485395443559795094942579933743954690515144734211093003515099221669989034466871351499968817166118596921723280195516618075900864189219239458566476548539390514694755273330485482236732779208417969325233522688716179942265794923069437263389935701588514365520841172201736011425367125182095591312502593343985517765818970997531604537975508636084224823022904624734078999269899676729934101659402979123769581615081932449685858474554820474379585927647630395154427771796893213661708"}]}'''
first_list = [ gen_id(14) for r in range(0, num_votes) ]
voter_ids = sorted(list(set(first_list)))
print("voter_ids created")
with open(voter_ids_file, 'w') as output_file:
for voter_id in voter_ids:
output_file.write(voter_id + '\n')
print("voter_ids done")
with open(votes_file, 'w') as output_file:
for voter_id in voter_ids:
output_file.write(voter_id + '|' + vote_example3 + '\n')
print("votes done")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Helps doing tests.')
args = parser.parse_args()
gen_votes(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment