diff --git a/copycat/__init__.py b/copycat/__init__.py index 14c0cc1..4e8bc55 100644 --- a/copycat/__init__.py +++ b/copycat/__init__.py @@ -1,2 +1,3 @@ from .copycat import Copycat, Reporter # noqa from .plot import plot_answers +from .io import save_answers diff --git a/copycat/io.py b/copycat/io.py new file mode 100644 index 0000000..ae1185b --- /dev/null +++ b/copycat/io.py @@ -0,0 +1,9 @@ + +def save_answers(answers, filename): + answers = sorted(answers.items(), key=lambda kv : kv[1]['count']) + keys = [k for k, v in answers] + counts = [str(v['count']) for k, v in answers] + with open(filename, 'w') as outfile: + outfile.write(','.join(keys)) + outfile.write('\n') + outfile.write(','.join(counts)) diff --git a/input/.placeholder b/input/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/input/problems.csv b/input/problems.csv new file mode 100644 index 0000000..3e941fa --- /dev/null +++ b/input/problems.csv @@ -0,0 +1,9 @@ +abc,abd,ijk +aabc,aabd,ijkk +abc,abd,kji +abc,abd,mrrjjj +abc,abd,rssttt +abc,abd,xyz +abc,abd,ijjkkk +rst,rsu,xyz +abc,abd,xyyzzz diff --git a/input/reduced_problems.csv b/input/reduced_problems.csv new file mode 100644 index 0000000..f5fe027 --- /dev/null +++ b/input/reduced_problems.csv @@ -0,0 +1,4 @@ +abc,abd,ijk +aabc,aabd,ijkk +abc,abd,xyz +abc,abd,ijjkkk diff --git a/main.py b/main.py index bae5ce0..3f197ee 100755 --- a/main.py +++ b/main.py @@ -35,8 +35,7 @@ final temperature of the workspace; lower means "more elegant". import argparse import logging -from copycat import Copycat, Reporter, plot_answers - +from copycat import Copycat, Reporter, plot_answers, save_answers class SimpleReporter(Reporter): """Reports results from a single run.""" @@ -70,6 +69,8 @@ def main(): if options.plot: plot_answers(answers, show=not options.noshow) + save_answers(answers, 'output/answers.csv') + if __name__ == '__main__': main()