<commit_before>import matplotlib.pyplot as pp
import matplotlib as mpl
import numpy as np
from scipy import stats as st
import datetime

import stats


def PlotAlt(workout):
    pp.figure()

    alt = workout.GetAltArray()
    dist = workout.GetDistArray()
    #print alt
    pp.plot(dist, alt)
    pp.show()

def MinuteFormatter(x, p):
    return "%02.d:%02.d" % (int(x / 60), x % 60)

def PlotPaceVsDistance(workouts):
    nitems = len(workouts)
    dist = np.zeros(nitems)
    pace = np.zeros(nitems)

    recent_dist = []
    recent_pace = []
    for i, workout in enumerate(workouts):
        dist[i] = workout.GetTotalDist() / 1000.0 # in km
        pace[i] = workout.GetTotalTime() / dist[i]
      
        if datetime.datetime.now() - workout.GetStartTime() < datetime.timedelta(days=60):
            recent_dist.append(dist[i])
            recent_pace.append(pace[i])
        

    f = pp.figure()
    ax = pp.subplot(111)
    pp.scatter(dist, pace)

    pp.scatter(recent_dist, recent_pace, color='#08C43A')

    pp.ylabel("Run pace (min / km)")
    pp.xlabel("Run length (km)")

    pp.xlim([0, 47.0])
    pp.ylim([220, 370])

    ax.yaxis.set_major_formatter(mpl.ticker.FuncFormatter(MinuteFormatter))

    slope, intercept, r_value, p_value, std_err = st.linregress(dist, pace)
    regr_x = np.array([5, 42])
    regr_y = intercept + regr_x * slope 
    pp.plot(regr_x, regr_y, '--', color='k')
    pp.annotate("%.2f s/km^2" % slope, (regr_x[1] - 10.0, regr_y[1]))

    pp.show()

def PlotDistanceAtPace(workouts):
    paces = []
    dists = []

    recent_dist = []
    recent_pace = []

    for workout in workouts:
        for lap in workout.laps:
            pace = lap.time / (lap.dist / 1000.0)
            paces.append(pace)
            dists.append(lap.dist / 1000.0)

            if datetime.datetime.now() - workout.GetStartTime() < datetime.timedelta(days=60):
                recent_dist.append(lap.dist / 1000.0)
                recent_pace.append(pace)

    pp.figure()
    ax = pp.subplot(111)

    pp.hist(paces, weights=dists, bins=24, range=[240, 480], color='#52730B')

    pp.hist(recent_pace, weights=recent_dist, bins=24, range=[240, 480], color='r')

    ax.xaxis.set_major_formatter(mpl.ticker.FuncFormatter(MinuteFormatter))

    pp.xlabel("Pace (min / km)")
    pp.ylabel("Total distance at pace (km)")

    pp.legend(["Total", "Last 60 days"])

    pp.show()

def PlotMonthlyDist(workouts):
    monthly = {}

    for workout in workouts:
        month = workout.GetStartTime().month
        year = workout.GetStartTime().year

        month = workout.GetStartTime().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
        if not month in monthly:
            monthly[month] = 0.0
        monthly[month] += workout.GetTotalDist() / 1000.0


    pp.figure()
    ax = pp.subplot(111, aspect=0.4)

    n_items = len(monthly.keys())
    sort_ind = sorted(range(n_items), key=lambda i: monthly.keys()[i])
    months =  [monthly.keys()[ind] for ind in sort_ind]
    totals =  [monthly.values()[ind] for ind in sort_ind]

    AV_MONTHS = 3
    totals_av = []
    # get moving average
    for i in range(AV_MONTHS-1, n_items):
        total = 0.0
        for j in range(AV_MONTHS):
            total += totals[i-j]
        totals_av.append(total / AV_MONTHS)

    pp.plot(months, totals, 'o--', markersize=14, color='k', mfc='b')

    pp.plot(months[AV_MONTHS-1:], totals_av, 'o--', color='k', markersize=14, mfc='g')

    pp.legend(["Monthly", "3-month average"], loc='upper left')
    pp.ylim([0, 240])
    pp.xlim([months[0] - datetime.timedelta(days=31), months[-1] + datetime.timedelta(days=31)])

    ax.yaxis.grid(color='b')

    pp.ylabel("Total distance (km)")

    pp.show()
<commit_msg>Div by zero.<commit_after>import matplotlib.pyplot as pp
import matplotlib as mpl
import numpy as np
from scipy import stats as st
import datetime

import stats


def PlotAlt(workout):
    pp.figure()

    alt = workout.GetAltArray()
    dist = workout.GetDistArray()
    #print alt
    pp.plot(dist, alt)
    pp.show()

def MinuteFormatter(x, p):
    return "%02.d:%02.d" % (int(x / 60), x % 60)

def PlotPaceVsDistance(workouts):
    nitems = len(workouts)
    dist = np.zeros(nitems)
    pace = np.zeros(nitems)

    recent_dist = []
    recent_pace = []
    for i, workout in enumerate(workouts):
        dist[i] = workout.GetTotalDist() / 1000.0 # in km
        pace[i] = workout.GetTotalTime() / dist[i]
      
        if datetime.datetime.now() - workout.GetStartTime() < datetime.timedelta(days=60):
            recent_dist.append(dist[i])
            recent_pace.append(pace[i])
        

    f = pp.figure()
    ax = pp.subplot(111)
    pp.scatter(dist, pace)

    pp.scatter(recent_dist, recent_pace, color='#08C43A')

    pp.ylabel("Run pace (min / km)")
    pp.xlabel("Run length (km)")

    pp.xlim([0, 47.0])
    pp.ylim([220, 370])

    ax.yaxis.set_major_formatter(mpl.ticker.FuncFormatter(MinuteFormatter))

    slope, intercept, r_value, p_value, std_err = st.linregress(dist, pace)
    regr_x = np.array([5, 42])
    regr_y = intercept + regr_x * slope 
    pp.plot(regr_x, regr_y, '--', color='k')
    pp.annotate("%.2f s/km^2" % slope, (regr_x[1] - 10.0, regr_y[1]))

    pp.show()

def PlotDistanceAtPace(workouts):
    paces = []
    dists = []

    recent_dist = []
    recent_pace = []

    for workout in workouts:
        for lap in workout.laps:
            if lap.dist == 0.0:
                continue

            pace = lap.time / (lap.dist / 1000.0)
            paces.append(pace)
            dists.append(lap.dist / 1000.0)

            if datetime.datetime.now() - workout.GetStartTime() < datetime.timedelta(days=60):
                recent_dist.append(lap.dist / 1000.0)
                recent_pace.append(pace)

    pp.figure()
    ax = pp.subplot(111)

    pp.hist(paces, weights=dists, bins=24, range=[240, 480], color='#52730B')

    pp.hist(recent_pace, weights=recent_dist, bins=24, range=[240, 480], color='r')

    ax.xaxis.set_major_formatter(mpl.ticker.FuncFormatter(MinuteFormatter))

    pp.xlabel("Pace (min / km)")
    pp.ylabel("Total distance at pace (km)")

    pp.legend(["Total", "Last 60 days"])

    pp.show()

def PlotMonthlyDist(workouts):
    monthly = {}

    for workout in workouts:
        month = workout.GetStartTime().month
        year = workout.GetStartTime().year

        month = workout.GetStartTime().replace(day=1, hour=0, minute=0, second=0, microsecond=0)
        if not month in monthly:
            monthly[month] = 0.0
        monthly[month] += workout.GetTotalDist() / 1000.0


    pp.figure()
    ax = pp.subplot(111, aspect=0.4)

    n_items = len(monthly.keys())
    sort_ind = sorted(range(n_items), key=lambda i: monthly.keys()[i])
    months =  [monthly.keys()[ind] for ind in sort_ind]
    totals =  [monthly.values()[ind] for ind in sort_ind]

    AV_MONTHS = 3
    totals_av = []
    # get moving average
    for i in range(AV_MONTHS-1, n_items):
        total = 0.0
        for j in range(AV_MONTHS):
            total += totals[i-j]
        totals_av.append(total / AV_MONTHS)

    pp.plot(months, totals, 'o--', markersize=14, color='k', mfc='b')

    pp.plot(months[AV_MONTHS-1:], totals_av, 'o--', color='k', markersize=14, mfc='g')

    pp.legend(["Monthly", "3-month average"], loc='upper left')
    pp.ylim([0, 240])
    pp.xlim([months[0] - datetime.timedelta(days=31), months[-1] + datetime.timedelta(days=31)])

    ax.yaxis.grid(color='b')

    pp.ylabel("Total distance (km)")

    pp.show()

{'fraction_non_alphanumeric': 0.15319261914243992, 'fraction_numerical': 0.0326563122262047, 'mean_word_length': 2.714990138067061, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6735960', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2696, 'n_words': 552}