def load_votes()

in monitoring/stv_tool.py [0:0]


def load_votes(fname):
  """Used by WHATIF.PY.

  Returns a list of names, and a list of vote-lists.
  """

  line = open(fname).readline()
  if line.strip() == 'rank order':
    lines = open(fname).readlines()

    # The input file was processed by nstv-rank.py, or somehow otherwise
    # converted to the standard input for VoteMain.jar
    names = [s.strip() for s in lines[1].strip().split(',')][1:]
    labels = [s.strip() for s in lines[2].strip().split(',')][1:]
    assert len(names) == len(labels)
    remap = dict(zip(labels, names))

    ### this is broken. We need to return a list of lists. Not a dict.
    ### we do not want to flow "who" voted -- that should be discarded.
    raise Exception("This script cannot parse the provided input file. "
                    "Fix the script.")
    votes = { }
    for line in lines[3:]:
      parts = line.strip().split(',')
      votes[parts[0]] = [remap[l] for l in parts[1:]]
    return names, votes

  # Map from "a".."z" to human names.
  labelmap = read_nominees(fname)

  # Construct a label-sorted list of names from the labelmap.
  names = [name for _, name in sorted(labelmap.items())]

  # Load the raw votes that were recorded. (eg. "kbaf")
  votes_by_label = read_votefile(fname)

  # Remap all labels to names in the votes.
  votes = [ [labelmap[l] for l in vote] for vote in votes_by_label ]

  return names, votes