Last active
May 30, 2018 03:47
-
-
Save 9999years/c2e17c195c1bdefef0662b0686c5c71e to your computer and use it in GitHub Desktop.
hand stats for keyboard layouts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # code for determining how much of a word is typed with different hands in a given keyboard layout | |
| # for the corncob list (http://www.mieliestronk.com/corncob_lowercase.txt), i got: | |
| # >>> fingerstats.wordsfile('corncob.txt', fingerstats.qwerty) | |
| # the left hand typed 59.29% of the letters | |
| # the right hand typed 40.71% | |
| # | |
| # >>> fingerstats.wordsfile('corncob.txt', fingerstats.colemak) | |
| # the left hand typed 50.56% of the letters | |
| # the right hand typed 49.44% | |
| # | |
| # >>> fingerstats.wordsfile('corncob.txt', fingerstats.dvorak) | |
| # the left hand typed 43.38% of the letters | |
| # the right hand typed 56.62% | |
| from collections import namedtuple | |
| Hands = namedtuple('Hands', ['left', 'right']) | |
| qwerty = Hands('qwertasdfgzxcvb', 'yuiophjklnm') | |
| colemak = Hands('qwfpgarstdzxcvb', 'jluyhneiokm') | |
| dvorak = Hands('pyaoeuiqjkx', 'fgcrldhtnsbmwvz') | |
| def percent(num): | |
| return '{: .2%}'.format(num) | |
| def ratio(word, layout: Hands=qwerty) -> Hands: | |
| """ | |
| portion of letters in word belonging to left and right, respectivly | |
| """ | |
| lefts = 0 | |
| rights = 0 | |
| total = 0 | |
| for letter in word: | |
| letter = letter.lower() | |
| if letter in layout.left: | |
| lefts += 1 | |
| total += 1 | |
| elif letter in layout.right: | |
| rights += 1 | |
| total += 1 | |
| return Hands(lefts / total, rights / total) | |
| def wordslist(words, layout: Hands=qwerty): | |
| lefts = 0 | |
| rights = 0 | |
| count = 0 | |
| for word in words: | |
| word = word.strip() | |
| rat = ratio(word, layout) | |
| lefts += rat.left | |
| rights += rat.right | |
| count += 1 | |
| return Hands(lefts / count, rights / count) | |
| def wordsfile(fname, layout: Hands=qwerty): | |
| with open(fname, 'r') as f: | |
| ret = wordslist(f, layout) | |
| print(f'the left hand typed {percent(ret.left)} of the letters') | |
| print(f'the right hand typed {percent(ret.right)}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment