<commit_before>#!/usr/bin/env python3
# encoding: utf-8

import numpy as np


def time_series_plot(data_set, **kwargs):
    data = _build_data_object(data_set['data'], data_set['data_col'])
    return {'title': data_set['name'], 'x_accessor': 'date',
            'y_accessor': 'value', 'data': [data], 'legend': ['data'],
            **kwargs}

def add_rolling_mean(data_set, collum, viz, window):
    rolling_mean_ts = data_set['data'].rolling(window=window).mean().dropna()
    data = _build_data_object(rolling_mean_ts, collum)
    viz['data'].append(data)
    viz['legend'].append('mean')

def add_rolling_std(data_set, collum, viz, window):
    rolling_std_ts = data_set['data'].rolling(window=window).std().dropna()
    data = _build_data_object(rolling_std_ts, collum)
    viz['data'].append(data)
    viz['legend'].append('std')

def auto_correlation_plot(data_set, max_lag, **kwargs):
    z95 = 1.959963984540054 # z-score for 0.95 of N(0,1)
    time_series = data_set['data']['Internet traffic data (in GB)']

    data = []
    for lag in range (max_lag):
        data.append({
            'lag': lag,
            'autocorrelation': time_series.autocorr(lag),
            'plus95conf': z95 / np.sqrt(len(time_series)),
            'minus95conf': -z95 / np.sqrt(len(time_series)),
            'zero': 0
        })

    return {'title': 'ACF', 'data': data, 'x_accessor': 'lag', 'y_accessor':
            ['autocorrelation', 'plus95conf', 'minus95conf', 'zero'], 'legend':
            ['autocorrelation', '+95% confidence', '-95% confidence',
            'baseline'], 'colors': ['#FF0000', '#808080', '#808080', '#000000'],
            'x_label': 'Lag', 'y_label': 'Autocorrelation', **kwargs}

def _build_data_object(data_set, collum):
    data = []
    for index, row in data_set.iterrows():
        data.append({
            'date': index.to_pydatetime().strftime('%s'),
            'value': row[collum]
        })<commit_msg>repaced zero function with  baseline annotation in the ACF plot<commit_after>#!/usr/bin/env python3
# encoding: utf-8

import numpy as np


def time_series_plot(data_set, **kwargs):
    data = _build_data_object(data_set['data'], data_set['data_col'])
    return {'title': data_set['name'], 'x_accessor': 'date',
            'y_accessor': 'value', 'data': [data], 'legend': ['data'],
            **kwargs}

def add_rolling_mean(data_set, collum, viz, window):
    rolling_mean_ts = data_set['data'].rolling(window=window).mean().dropna()
    data = _build_data_object(rolling_mean_ts, collum)
    viz['data'].append(data)
    viz['legend'].append('mean')

def add_rolling_std(data_set, collum, viz, window):
    rolling_std_ts = data_set['data'].rolling(window=window).std().dropna()
    data = _build_data_object(rolling_std_ts, collum)
    viz['data'].append(data)
    viz['legend'].append('std')

def auto_correlation_plot(data_set, max_lag, **kwargs):
    z95 = 1.959963984540054 # z-score for 0.95 of N(0,1)
    time_series = data_set['data']['Internet traffic data (in GB)']

    data = []
    for lag in range (max_lag):
        data.append({
            'lag': lag,
            'autocorrelation': time_series.autocorr(lag),
            'plus95conf': z95 / np.sqrt(len(time_series)),
            'minus95conf': -z95 / np.sqrt(len(time_series)),
        })

    return {'title': 'ACF', 'data': data, 'x_accessor': 'lag',
            'y_accessor': ['autocorrelation', 'plus95conf', 'minus95conf'],
            'legend': ['autocorrelation', '+95% confidence', '-95% confidence'],
            'colors': ['#FF0000', '#333333', '#333333'], 'x_label': 'Lag',
            'y_label': 'Autocorrelation', 'baselines': [{'value': 0.0}],
            **kwargs}

def _build_data_object(data_set, collum):
    data = []
    for index, row in data_set.iterrows():
        data.append({
            'date': index.to_pydatetime().strftime('%s'),
            'value': row[collum]
        })
{'fraction_non_alphanumeric': 0.17705671946857435, 'fraction_numerical': 0.0314256515074093, 'mean_word_length': 3.4087837837837838, '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': '3920506', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1316, 'n_words': 265}