4 """get all layout results from the results folder.
6 Depends on the layouts info starting with OA'Evolved Layout'
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
:
21 print("can’t open", textfile
)
23 e
= d
.split("Evolved Layout")
26 layout_strings
.append("\n".join(i
.splitlines()[1:4]))
28 all_layouts
= [string_to_layout(l
) for l
in layout_strings
]
32 def get_all_layouts_in_text_files_in(folder
="results"):
33 """get all layouts from check_neo runs saved in the textfile."""
35 for i
in listdir("results"):
36 if not i
.endswith(".txt"):
38 all_layouts
.extend(get_all_layouts_in_textfile(join("results", i
)))
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()
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")
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
:
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
)])
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
)