In [1]:
from dodona import core, keyboards, wordlists
from copy import deepcopy

%pylab
%matplotlib inline

wordlist = core.WordList()
wordlist.LoadFromFile("wordlist.dat")
Using matplotlib backend: Qt5Agg
Populating the interactive namespace from numpy and matplotlib

In [2]:
def make_fitaly_keyboard(letters = "zvchwkfitalynegdorsbqjumpx"):
    keyboard = core.Keyboard()
    
    #Make a square
    polygon = core.Polygon()
    polygon.AddVertex(-0.4, -0.4)
    polygon.AddVertex(-0.4, 0.4)
    polygon.AddVertex(0.4, 0.4)
    polygon.AddVertex(0.4, -0.4)
    
    #cycle through and add each key
    letter_index = 0
    for i in range(5):
        low, high = 0, 6
        if i == 2:
            low, high = 2, 4
        for j in range(low, high):
            new_polygon = deepcopy(polygon)
            new_polygon.Translate(j - 2.5, -i + 2.5)
            keyboard.AddKey(letters[letter_index], new_polygon)
            letter_index += 1
    return keyboard
In [3]:
#Construct the keyboard and test it out on a word
keyboard = make_fitaly_keyboard()
model = core.SimpleGaussianModel()
model.SetScale(0.2)
vector = model.RandomVector("fitaly", keyboard)
keyboards.DrawKeyboard(keyboard, inputvector=vector, wordlist=wordlist,
                       nopalette=True, colormap=mpl.cm.Blues, markersize=20)

print("Stylus Movement:", vector.SpatialLength())
Stylus Movement: 5.206463492697732

In [4]:
def average_distance(keyboard, model):
    weighted_sum = 0
    for i in range(wordlist.Words()):
        word = wordlist.Word(i)
        vector = model.RandomVector(word, keyboard)
        weighted_sum += vector.SpatialLength()*wordlist.Occurances(word)
    return weighted_sum/wordlist.TotalOccurances()          
In [5]:
#Evaluate the average distance for FITALY
print("FITALY average distance:", average_distance(keyboard, model))

#And for a random keyboard
random_keyboard = make_fitaly_keyboard()
random_keyboard.Randomize()
print("Random average distance:", average_distance(random_keyboard, model))
FITALY average distance: 7.932285603356274
Random average distance: 10.224226294878317

In [6]:
#And let's see what the random one looked like
keyboards.DrawKeyboard(random_keyboard, wordlist=wordlist,
                       nopalette=True, colormap=mpl.cm.Blues, markersize=20)
In [ ]: