Arne Babenhauserheide  committed e237235

included missing stuff

  • Participants
  • Parent commits 946f098
  • Branches t9

Comments (0)

Files changed (2)

 WEIGHT_POSITION_QUADRATIC_BIGRAMS = 0.1 #:100 #: the product of the cost of the letters in a bigram, divided by the number of keystrokes. The numbers are about factor 50 below the position cost — consistently for text of different length.
 WEIGHT_FINGER_REPEATS = 512 #: Cost of a finger repeat. Gets additional +1 from the row change on the same finger.
+WEIGHT_FINGER_REPEATS_INDEXFINGER_MULTIPLIER = 0.5 #: Cost of a finger repeat on rhe indexfinger (hurts less). Warning: Any value different from 1 means that the percentage of finger repeats reported by will be incorrect.
+WEIGHT_FINGER_REPEATS_CRITICAL_FRACTION = 0.0005 #: The cost of finger repeats with a fraction of the bigrams higher than this is increased sharply, relative to the amount by which they exceed the fraction. Value guessed from experience from effchen (adnw ln disturbs writing, below that does not). 0.05% is about once per DinA4-page (30 lines, 60 letters). There should be no single finger repetition which appears once per DinA4 page, because that will stick to ones mind as a cludge.
+WEIGHT_FINGER_REPEATS_CRITICAL_FRACTION_MULTIPLIER = 5 #: The amount of usage higher than the critical fraction is multiplied by this multiplier. Warning: Any value different from 1 means that the percentage of finger repeats reported by will be incorrect.
 WEIGHT_FINGER_REPEATS_TOP_BOTTOM = 2048 #: Additional cost of a finger repetition from the top to the bottom line. Gets added to the cost of the normal finger repetition. Additionally this gets costs as row repetition on the same hand (+4). 


     except: return None
+def single_key_position_cost(pos, layout, cost_per_key=COST_PER_KEY):
+    """Get the position_cost of a single key.
+    @param pos: The position of the key.
+    @type pos: tuple (row, col, layer).
+    @return: the cost of that one position."""
+    if pos is None: # not found
+        return COST_PER_KEY_NOT_FOUND
+    # shift, M3 and M4
+    if COST_LAYER_ADDITION[pos[2]:]:
+        cost = cost_per_key[pos[0]][pos[1]]
+        cost += COST_LAYER_ADDITION[pos[2]]
+        return cost
+    # layer has no addition cost ⇒ undefined layer (higher than layer 6!). Just take the base key…
+    return cost_per_key[pos[0]][pos[1]]
+def is_position_cost_lower(pos, new_pos, layout, doubled_layer=True):
+    """
+    >>> is_position_cost_lower((2, 10, 2), (3, 7, 3), NEO_LAYOUT)
+    False
+    """
+    # use doubled layer cost, because it ignores the additional bigrams.
+    new_cost = single_key_position_cost(new_pos, layout) + COST_LAYER_ADDITION[new_pos[2]]
+    cost = single_key_position_cost(pos, layout) + COST_LAYER_ADDITION[pos[2]]
+    return new_cost < cost
 def update_letter_to_key_cache(key, layout):
     """Update the cache entry for the given key."""
     try: LETTER_TO_KEY_CACHE = layout[5]
             # add the supported layers.
             tmp0 = []
-            for i in range(len(pos1[2])):
             for i in range(max(len(pos1_keys), len(pos0_keys))):
                 if i in switch_layers: