<commit_before>#!/usr/bin/env python
"""A collection of git info aggregators for graph commands."""

import time
import subprocess
from collections import defaultdict

class TimeHisto(object):

    def __init__(self):
        self.h = defaultdict(lambda: 0)

    def add_logs(self, directory=None, log_args=['HEAD']):
        args=['git']
        if directory:
            args.append('--git-dir=' + directory)
        args.extend(['log', '--pretty=format:%at'])
        args.extend(log_args)
        sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)

        for l in sub.stdout:
            self.h[time.strftime("%w %H", time.localtime(float(l.strip())))] += 1

    def dump(self):
        for h in range(24):
            for d in range(7):
                sys.stderr.write("%02d %d - %s\n"
                                 % (h, d, self.h["%d %02d" % (d, h)]))

    def to_gchart(self):
        from pygooglechart import ScatterChart
        chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))
<commit_msg>Fix git-timecard to respect time zones.<commit_after>#!/usr/bin/env python
"""A collection of git info aggregators for graph commands."""

import time
import subprocess
from collections import defaultdict

class TimeHisto(object):

    def __init__(self):
        self.h = defaultdict(lambda: 0)

    def add_logs(self, directory=None, log_args=['HEAD']):
        args=['git']
        if directory:
            args.append('--git-dir=' + directory)
        args.extend(['log', '--format=%ad', '--date=raw'])
        args.extend(log_args)
        sub = subprocess.Popen(args, stdout=subprocess.PIPE, close_fds=True)

        for l in sub.stdout:
            t, offset = l.strip().split(' ')
            t = float(t) + int(offset) / 100 * 3600

            self.h[time.strftime("%w %H", time.gmtime(t))] += 1

    def dump(self):
        for h in range(24):
            for d in range(7):
                sys.stderr.write("%02d %d - %s\n"
                                 % (h, d, self.h["%d %02d" % (d, h)]))

    def to_gchart(self):
        from pygooglechart import ScatterChart
        chart = ScatterChart(800, 300, x_range=(-1, 24), y_range=(-1, 7))

{'fraction_non_alphanumeric': 0.15293582157487484, 'fraction_numerical': 0.021392808375056895, 'mean_word_length': 2.3202416918429005, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4464132', 'n_tokens_mistral': 755, 'n_tokens_neox': 703, 'n_words': 178}