Example #1
0
    def __init__(self, timer_name, write_log=False):
        """
        Creates timer. Timer name is name that will be in logs header and part of filename if write_log=True
        If write_log true and timers logging enabled (DUMP_TO_FILE=True) save timer info to file.

        """
        Timer.__init__(self, timer_name)
        self.headers = None
        self.write_log = write_log
        self.log_name = None
Example #2
0
    def __init__(self, timer_name, write_log=False):
        """
        Creates timer. Timer name is name that will be in logs header and part of filename if write_log=True
        If write_log true and timers logging enabled (DUMP_TO_FILE=True) save timer info to file.

        """
        Timer.__init__(self, timer_name)
        self.headers = None
        self.write_log = write_log
        self.log_name = None
Example #3
0
    def stop_print_and_clear(self):
        """
        Stop timer, output result, and clear timers.
        If dumping to file, if headers are not match to prev, new header line will be added.
        """
        Timer.stop_and_print(self)

        if self.write_log and DUMP_TO_FILE:
            turn = fo.currentTurn()
            headers = make_header('Turn', *[x[0] for x in self.timers])
            if self.headers != headers:
                self._write(''.join(headers) + '\n' + ''.join(['-' * (len(x) - 2) + '  ' for x in headers]))
                self.headers = headers

            row = []
            for header, val in zip(self.headers, [turn] + [x[1] for x in self.timers]):
                row.append('%*s ' % (len(header) - 2, int(val)))
            self._write(''.join(row))
Example #4
0
    def stop_print_and_clear(self):
        """
        Stop timer, output result, and clear timers.
        If dumping to file, if headers are not match to prev, new header line will be added.
        """
        Timer.stop_and_print(self)

        if self.write_log and DUMP_TO_FILE:
            turn = fo.currentTurn()
            headers = make_header('Turn', *[x[0] for x in self.timers])
            if self.headers != headers:
                self._write(''.join(headers) + '\n' + ''.join(['-' * (len(x) - 2) + '  ' for x in headers]))
                self.headers = headers

            row = []
            for header, val in zip(self.headers, [turn] + [x[1] for x in self.timers]):
                row.append('%*s ' % (len(header) - 2, int(val)))
            self._write(''.join(row))