Example #1
0
def generate_n_bids_p(e, synpar):
    """ Generate number of bids for each pbcid. """

    synpar.n_bids_p = {}
    for pbcid in e.pbcids:
        synpar.n_bids_p[pbcid] = syn.geospace_choice(
            e, synpar, synpar.min_n_bids_per_pbcid,
            synpar.max_n_bids_per_pbcid)
Example #2
0
def generate_election_spec_contests(e, synpar):

    # check number of contests
    assert isinstance(synpar.n_cids, int) and synpar.n_cids >= 1
    # make cid for each contest
    e.cids = set("con{}".format(i + 1) for i in range(synpar.n_cids))

    # generate contest types as plurality and additional parameters
    # no write-ins
    for cid in e.cids:
        e.contest_type_c[cid] = "plurality"
        e.params_c[cid] = ""
        e.write_ins_c[cid] = "no"

    # check number of cids with wrong reported outcome
    assert isinstance(synpar.n_cids_wrong, int)
    assert 0 <= synpar.n_cids_wrong <= synpar.n_cids
    # determine which, if any, cids have wrong reported outcome
    cids_list = list(e.cids)
    synpar.RandomState.shuffle(cids_list)  # in-place
    synpar.cids_wrong = cids_list[:synpar.n_cids_wrong]

    # generate selids for each cid
    e.n_selids_c = {}
    e.selids_c = {}
    for cid in e.cids:
        e.n_selids_c[cid] = syn.geospace_choice(e, synpar,
                                                synpar.min_n_selids_per_cid,
                                                synpar.max_n_selids_per_cid)

        e.selids_c[cid] = {
            "sel{}".format(i): True
            for i in range(1, e.n_selids_c[cid] + 1)
        }

    # generate possible votes for each cid
    for cid in e.cids:
        if e.contest_type_c[cid] == "plurality":
            for selid in e.selids_c[cid]:
                utils.nested_set(e.votes_c, [cid, (selid, )], True)
        else:
            utils.myerror(("Contest {} is not plurality---"
                           "Can't generate votes for it.").format(cid))