output actual characters instead of codepoints
[evolve-layout.git] / recheck_all_result_layouts.py
blob0a824397939324e1fb0a9b5255dc05b87bfb841a
1 #!/usr/bin/env python3
2 # encoding: utf-8
4 """get all layout results from the results folder.
6 Depends on the layouts info starting with OA'Evolved Layout'
7 """
9 from check_neo import string_to_layout, print_layout_with_statistics, csv_data, get_all_data
10 from os import listdir
11 from os.path import join
13 def get_all_layouts_in_textfile(textfile):
14 """Get all layouts in the given textfile.
16 @return: a list of layout strings."""
17 with open(textfile, encoding="utf-8") as f:
18 try:
19 d = f.read()
20 except UnicodeError:
21 print("can’t open", textfile)
23 e = d.split("Evolved Layout")
24 layout_strings = []
25 for i in e[1:]:
26 layout_strings.append("\n".join(i.splitlines()[1:4]))
28 all_layouts = [string_to_layout(l) for l in layout_strings]
29 return all_layouts
32 def get_all_layouts_in_text_files_in(folder="results"):
33 """get all layouts from check_neo runs saved in the textfile."""
34 all_layouts = []
35 for i in listdir("results"):
36 if not i.endswith(".txt"):
37 continue
38 all_layouts.extend(get_all_layouts_in_textfile(join("results", i)))
40 return all_layouts
43 if __name__ == "__main__":
45 from optparse import OptionParser
47 parser = OptionParser(description="recheck all result layouts with the current config.")
48 parser.add_option("--file", dest="data", type="string", default=None,
49 help="use the given textfile as korpus", metavar="file")
50 parser.add_option("--csv",
51 action="store_true", dest="print_csv", default=False,
52 help="print a csv instead of the normal layout statistics")
53 (options, args) = parser.parse_args()
55 if options.print_csv:
56 print("total penalty per word;key position cost;finger repeats;disbalance of fingers;top to bottom or vice versa;handswitching in trigram;(rows²/dist)²;shortcut keys;handswitching after unbalancing;movement pattern")
58 if options.data:
59 with open(options.data) as f:
60 options.data = f.read()
62 all_layouts = get_all_layouts_in_text_files_in("results")
64 letters, number_of_letters, repeats, number_of_bigrams, trigrams, number_of_trigrams = get_all_data(data=options.data)
66 for lay in all_layouts:
67 if options.print_csv:
68 print(";".join([str(i)
69 for i in csv_data(lay, letters=letters, repeats=repeats, number_of_letters=number_of_letters, number_of_bigrams=number_of_bigrams, trigrams=trigrams, number_of_trigrams=number_of_trigrams)])
71 else:
72 print("# Evolved Layout")
73 print_layout_with_statistics(lay, verbose=True, letters=letters, repeats=repeats, number_of_letters=number_of_letters, number_of_bigrams=number_of_bigrams, trigrams=trigrams, number_of_trigrams=number_of_trigrams)
74 print()