<commit_before>#!/usr/bin/env python2.7

from gi.repository import Gtk, GLib #pylint: disable=E0611
import cairo # less broken than pygi, seems to be compatible
from math import pi
from collections import defaultdict
import time

from netscramble import res
#from netscramble.game import TileGrid
from netscramble import game
from netscramble.score_dialog import ScoreDialog

class Timer(object):
    """Context manager for simple benchmarking."""

    def __init__(self, print_result):
        self.print_result = print_result
        self.start_time = None

    def __enter__(self):
        self.start_time = time.time()

    def __exit__(self, _type, _value, _traceback):
        end_time = time.time()
        millis_elapsed = 1000 * (end_time - self.start_time)
        if self.print_result:
            print "{} ms elapsed".format(round(millis_elapsed, 2))
        return millis_elapsed


def hex_to_rgb(value):
    # from: http://stackoverflow.com/a/214657
    lv = len(value)
    return tuple(int(value[i:i+lv/3], 16)/255.0 for i in range(0, lv, lv/3))

def set_render_matrix(c, grid_width, grid_height, width, height):
    """Set transformation matrix for rendering the grid.

    (0, 0) will be the top left of the top left grid tile, and each tile is 1
    by 1.<commit_msg>Let Timer raise exceptions properly<commit_after>#!/usr/bin/env python2.7

from gi.repository import Gtk, GLib #pylint: disable=E0611
import cairo # less broken than pygi, seems to be compatible
from math import pi
from collections import defaultdict
import time

from netscramble import res
#from netscramble.game import TileGrid
from netscramble import game
from netscramble.score_dialog import ScoreDialog

class Timer(object):
    """Context manager for simple benchmarking."""

    def __init__(self, print_result):
        self.print_result = print_result
        self.start_time = None

    def __enter__(self):
        self.start_time = time.time()

    def __exit__(self, _type, _value, _traceback):
        millis_elapsed = 1000 * (time.time() - self.start_time)
        if self.print_result:
            print "{} ms elapsed".format(round(millis_elapsed, 2))


def hex_to_rgb(value):
    # from: http://stackoverflow.com/a/214657
    lv = len(value)
    return tuple(int(value[i:i+lv/3], 16)/255.0 for i in range(0, lv, lv/3))

def set_render_matrix(c, grid_width, grid_height, width, height):
    """Set transformation matrix for rendering the grid.

    (0, 0) will be the top left of the top left grid tile, and each tile is 1
    by 1.
{'fraction_non_alphanumeric': 0.09424290220820189, 'fraction_numerical': 0.02365930599369085, 'mean_word_length': 3.5629496402877696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5479673', 'n_tokens_mistral': 848, 'n_tokens_neox': 784, 'n_words': 259}