<commit_before>#!/usr/bin/env python
"""
Advanced Statistics for Git log.

How to use:

A.  import and play with log_df DataFrame or log_to_dict (dictionary of log)
B.  Generate csv metadata:

./giteye.py ../web ~/Desktop

This generates metadata about the web repo and outputs csv file to:  
~/Desktop/web_git_metadata.csv

It also creates a chart called:  web_git_metadata.csv.pdf

"""

from subprocess import (call, Popen, PIPE)
import sys
import os
import csv
#Pandas is optional, only needed for some things
#Trying to avoid being an irritating tool and requiring it
try:
    import pandas as pd
except ImportError:
    pass

GIT_COMMIT_FIELDS = ['id', 'author_name', 'author_email', 'date', 'message']
GIT_LOG_FORMAT = ['%H', '%an', '%ae', '%ad', '%s']
GIT_LOG_FORMAT = '%x1f'.join(GIT_LOG_FORMAT) + '%x1e'

def log_to_dict():
    """Converts Git Log To A Python Dict"""
    
    p = Popen('git log --format="%s"' % GIT_LOG_FORMAT, shell=True, stdout=PIPE)
    (log, _) = p.communicate()
    log = log.strip('\n\x1e').split("\x1e")
    log = [row.strip().split("\x1f") for row in log]
    log = [dict(zip(GIT_COMMIT_FIELDS, row)) for row in log]
    return log

def log_df():
    """Returns a Pandas DataFrame of git log history"""

    log = log_to_dict()
    df = pd.DataFrame.from_dict(log)
    return df<commit_msg>adding local timezone for git log<commit_after>#!/usr/bin/env python
"""
Advanced Statistics for Git log.

How to use:

A.  import and play with log_df DataFrame or log_to_dict (dictionary of log)
B.  Generate csv metadata:

./giteye.py ../web ~/Desktop

This generates metadata about the web repo and outputs csv file to:  
~/Desktop/web_git_metadata.csv

It also creates a chart called:  web_git_metadata.csv.pdf

"""

from subprocess import (call, Popen, PIPE)
import sys
import os
import csv
#Pandas is optional, only needed for some things
#Trying to avoid being an irritating tool and requiring it
try:
    import pandas as pd
except ImportError:
    pass

GIT_COMMIT_FIELDS = ['id', 'author_name', 'author_email', 'date', 'message']
GIT_LOG_FORMAT = ['%H', '%an', '%ae', '%ad', '%s']
GIT_LOG_FORMAT = '%x1f'.join(GIT_LOG_FORMAT) + '%x1e'

def log_to_dict():
    """Converts Git Log To A Python Dict"""
    
    p = Popen('git log --date=local --format="%s"' % GIT_LOG_FORMAT, shell=True, stdout=PIPE)
    (log, _) = p.communicate()
    log = log.strip('\n\x1e').split("\x1e")
    log = [row.strip().split("\x1f") for row in log]
    log = [dict(zip(GIT_COMMIT_FIELDS, row)) for row in log]
    return log

def log_df():
    """Returns a Pandas DataFrame of git log history"""

    log = log_to_dict()
    df = pd.DataFrame.from_dict(log)
    return df
{'fraction_non_alphanumeric': 0.13455087588520312, 'fraction_numerical': 0.003727171077152441, 'mean_word_length': 3.853526220614828, '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': '38260', 'n_tokens_mistral': 971, 'n_tokens_neox': 946, 'n_words': 311}