Commit af58b4a0 authored by Dominique Merle's avatar Dominique Merle
Browse files

Hm. Bad signature change for main().

But it can be changed later on if needed.
parent 1278b534
...@@ -103,7 +103,7 @@ def sort_two_candidates(judgments_of, tally_of, mentions, ca, cb): ...@@ -103,7 +103,7 @@ def sort_two_candidates(judgments_of, tally_of, mentions, ca, cb):
return positions[mdca] - positions[mdcb] return positions[mdca] - positions[mdcb]
def main(args): def main(args_parser, args):
log("MAJORITY JUDGMENT POLLING -- Version %s" % __version__) log("MAJORITY JUDGMENT POLLING -- Version %s" % __version__)
# In decreasing order. # In decreasing order.
...@@ -122,18 +122,20 @@ def main(args): ...@@ -122,18 +122,20 @@ def main(args):
with open(args.mentions_file) as f: with open(args.mentions_file) as f:
mentions = [l.strip() for l in f.readlines() if l and l.strip()] mentions = [l.strip() for l in f.readlines() if l and l.strip()]
log("Going to use the following mentions:") log("\nGoing to use the following mentions:")
log(''+(', '.join(mentions))) log(''+(', '.join(mentions)))
if args.input_file is not None: if args.input_file is None:
with open(find_file(args.input_file)) as f: exit(1)
input_csv_strings = f.readlines()
else: log("\nWaiting for input judgments...")
input_csv_strings = sys.stdin.readlines() log("(use CTRL+D to exit)")
input_csv_strings = args.input_file.readlines()
if not input_csv_strings: if not input_csv_strings:
log("Provide an input file with --input.") log("Please provide an input CSV file.")
exit(1) args_parser.print_help()
args_parser.exit(1)
judgments_data = csv.reader( judgments_data = csv.reader(
StringIO("".join(input_csv_strings)), StringIO("".join(input_csv_strings)),
...@@ -142,13 +144,11 @@ def main(args): ...@@ -142,13 +144,11 @@ def main(args):
lineterminator='\n' lineterminator='\n'
) )
detected_mentions = list()
candidates_list = list() candidates_list = list()
everyones_judgments = dict() everyones_judgments = dict()
skip_cols = int(args.skip_cols) skip_cols = int(args.skip_cols)
skip_rows = 0 skip_rows = 0
# Set to -1 to disable header header_on_row = skip_rows + 0 # Set to -1 to disable header
header_on_row = skip_rows + 0
current_row = -1 current_row = -1
for judgments in judgments_data: for judgments in judgments_data:
...@@ -184,7 +184,6 @@ def main(args): ...@@ -184,7 +184,6 @@ def main(args):
if candidate not in everyones_judgments: if candidate not in everyones_judgments:
everyones_judgments[candidate] = list() everyones_judgments[candidate] = list()
everyones_judgments[candidate].append(judgments[i]) everyones_judgments[candidate].append(judgments[i])
# print(judgments)
mentions_dict = get_positions(mentions) mentions_dict = get_positions(mentions)
...@@ -230,7 +229,7 @@ def main(args): ...@@ -230,7 +229,7 @@ def main(args):
) )
for i, candidate in enumerate(sorted_candidates): for i, candidate in enumerate(sorted_candidates):
log("%02d. %18s %s" % ( log("%02d.\t%18s\t%s" % (
i+1, i+1,
get_median(judgments_tallies[candidate], mentions), get_median(judgments_tallies[candidate], mentions),
candidate, candidate,
...@@ -240,9 +239,6 @@ def main(args): ...@@ -240,9 +239,6 @@ def main(args):
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# Required positional argument
# parser.add_argument("arg", help="Required positional argument")
# Optional argument flag which defaults to False # Optional argument flag which defaults to False
# parser.add_argument( # parser.add_argument(
# '-f', # '-f',
...@@ -252,13 +248,12 @@ if __name__ == "__main__": ...@@ -252,13 +248,12 @@ if __name__ == "__main__":
# help="" # help=""
# ) # )
# Input CSV file. Overrides stdin when provided.
parser.add_argument( parser.add_argument(
"-i", 'input_file',
"--input", nargs='?',
action="store", type=argparse.FileType('r'),
dest="input_file", help="A CSV file with the judgments.",
help="A CSV file with the judgments." default=sys.stdin
) )
parser.add_argument( parser.add_argument(
...@@ -266,7 +261,10 @@ if __name__ == "__main__": ...@@ -266,7 +261,10 @@ if __name__ == "__main__":
"--mentions", "--mentions",
action="store", action="store",
dest="mentions_file", dest="mentions_file",
help="A text file with one mention per line." help="""
A text file with one mention per line,
in order from highest to lowest.
"""
) )
parser.add_argument( parser.add_argument(
...@@ -294,4 +292,4 @@ if __name__ == "__main__": ...@@ -294,4 +292,4 @@ if __name__ == "__main__":
) )
args = parser.parse_args() args = parser.parse_args()
main(args) main(parser, args)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment