<commit_before>#!/usr/bin/env python3
from __future__ import (absolute_import, division, print_function)

import json
import numpy as np
import pandas as pd
from datetime import datetime
### plotly
from plotly import tools as toolsly
from plotly.offline import plot
import plotly.graph_objs as go
### matplotlib
#import matplotlib
#import matplotlib.pyplot as plt
#plt.xkcd()

# location of the script
import os
import sys
scriptdir = os.path.split(os.path.abspath(sys.argv[0]))[0]
docsdir = os.path.abspath(os.path.join(scriptdir, '../docs/AtlantaRagnar2017/'))

######################################################################
############################## calculate everything
# setup list of legs
legs = np.array([4.5, 5.4, 5.5])
#print('short', legs)
legs_full  = np.tile(legs,8)
legs_ultra = legs_full[:12]+legs_full[1:13]
legs_full  = np.insert(legs_full, 0, 0.)
legs_ultra = np.insert(legs_ultra, 0, 0.)
#print('full ', legs_full, legs_full.size, legs_full.sum())
#print('ultra', legs_ultra, legs_ultra.size, legs_ultra.sum())

# setup list of all runners
runner = np.array([1,2,3,4])
runner = np.repeat(runner,2) # since it is an ultra each runner is twice in a row
runner = np.tile(runner,3) # and three of those
runner = np.insert(runner, 0, 0) # get a slot for the time
#print('runner', runner, runner.size)

# accumulate a list of distances
race = pd.DataFrame({'leg':np.arange(25),
                     'distance':legs_full,
                     'runner': runner,
                  })
race['distance_accum'] = np.add.accumulate(race['distance'])
#print(race)
# debug matplotlib plot
#fig, axes  = plt.subplots()
#axes.plot(np.arange(legs_full.size)+1, np.add.accumulate(legs_full), label='full')
#axes.plot(np.arange(legs_ultra.size)+1, np.add.accumulate(legs_ultra), label='ultra')
#axes.legend()

# setup times for runners
runners = pd.DataFrame({'runner':np.arange(5),
                        'name':['NA', 'Josh', 'Ross', 'Dan', 'Pete'],
                        'pace':[np.timedelta64(int(0), 's'),
                                np.timedelta64(int(8*60), 's'),
                                np.timedelta64(int(7*60), 's'),
                                np.timedelta64(int(6*60+45), 's'),
                                np.timedelta64(int(9*60), 's')]})
runners = runners.set_index('runner') # must be a better way
#print(runners)

# taken from https://www.timeanddate.com/sun/usa/atlanta
sunset = np.datetime64('2017-04-21T20:13')
sunrise = np.datetime64('2017-04-22T06:57')

# calculate the leg times for the actual races
time_error = np.timedelta64(int(30), 's')
time_zero = np.timedelta64(int(0), 's')
leg_time = []
leg_time_fast = []
leg_time_slow = []
for index, row in race.iterrows():
    if row.runner == 0:
        leg_time.append(time_zero)
        leg_time_fast.append(time_zero)
        leg_time_slow.append(time_zero)
    else:
        leg_time.append(row.distance*runners.loc[row.runner].pace)
        leg_time_fast.append(row.distance*(runners.loc[row.runner].pace-time_error))
        leg_time_slow.append(row.distance*(runners.loc[row.runner].pace+time_error))
race['time'] = leg_time
race['time_fast'] = leg_time_fast
race['time_slow'] = leg_time_slow
race['time_accum'] = np.add.accumulate(race['time'])
race['time_accum_fast'] = np.add.accumulate(race['time_fast'])
race['time_accum_slow'] = np.add.accumulate(race['time_slow'])
#print(race)

# set a start time and calculate when the magic happens
time_start = np.datetime64('2017-04-21T17:00')
for label in ['time_accum', 'time_accum_fast', 'time_accum_slow']:
    race[label] = [ time_start+time_accum for time_accum in race[label]]
#print(race)

# load in the actual times
with open(os.path.join(docsdir,'actual.json'), 'r') as handle:
    actual = json.load(handle)
    actual = [np.datetime64(item) for item in actual]
while len(actual) < 12: # magic number related to number of legs
    actual.append(None)

# calculate new updated estimated times
est_updating = actual[:]
for i, _ in enumerate(est_updating):
    if i == 0:
        continue
    if est_updating[i] is not None:
        continue
    est_updating[i] = est_updating[i-1] + race.time[2*i-1] + race.time[2*i]
# add the finish time
est_updating.append(est_updating[-1] + race.time[race.time.size-2] + race.time[race.time.size-1])

######################################################################
############################## put together the json document
leg_descr = {0:'gre/yel',
             1:'red/gre',
             2:'yel/red'}
leg_miles = {0:legs[0]+legs[1],
             1:legs[2]+legs[0],
             2:legs[1]+legs[1]}
json_data = []
for index, row in race.iterrows():
    if index%2 != 0: # it is an ultra
        continue
    if index == 0:<commit_msg>Fix typo<commit_after>#!/usr/bin/env python3
from __future__ import (absolute_import, division, print_function)

import json
import numpy as np
import pandas as pd
from datetime import datetime
### plotly
from plotly import tools as toolsly
from plotly.offline import plot
import plotly.graph_objs as go
### matplotlib
#import matplotlib
#import matplotlib.pyplot as plt
#plt.xkcd()

# location of the script
import os
import sys
scriptdir = os.path.split(os.path.abspath(sys.argv[0]))[0]
docsdir = os.path.abspath(os.path.join(scriptdir, '../docs/AtlantaRagnar2017/'))

######################################################################
############################## calculate everything
# setup list of legs
legs = np.array([4.5, 5.4, 5.5])
#print('short', legs)
legs_full  = np.tile(legs,8)
legs_ultra = legs_full[:12]+legs_full[1:13]
legs_full  = np.insert(legs_full, 0, 0.)
legs_ultra = np.insert(legs_ultra, 0, 0.)
#print('full ', legs_full, legs_full.size, legs_full.sum())
#print('ultra', legs_ultra, legs_ultra.size, legs_ultra.sum())

# setup list of all runners
runner = np.array([1,2,3,4])
runner = np.repeat(runner,2) # since it is an ultra each runner is twice in a row
runner = np.tile(runner,3) # and three of those
runner = np.insert(runner, 0, 0) # get a slot for the time
#print('runner', runner, runner.size)

# accumulate a list of distances
race = pd.DataFrame({'leg':np.arange(25),
                     'distance':legs_full,
                     'runner': runner,
                  })
race['distance_accum'] = np.add.accumulate(race['distance'])
#print(race)
# debug matplotlib plot
#fig, axes  = plt.subplots()
#axes.plot(np.arange(legs_full.size)+1, np.add.accumulate(legs_full), label='full')
#axes.plot(np.arange(legs_ultra.size)+1, np.add.accumulate(legs_ultra), label='ultra')
#axes.legend()

# setup times for runners
runners = pd.DataFrame({'runner':np.arange(5),
                        'name':['NA', 'Josh', 'Ross', 'Dan', 'Pete'],
                        'pace':[np.timedelta64(int(0), 's'),
                                np.timedelta64(int(8*60), 's'),
                                np.timedelta64(int(7*60), 's'),
                                np.timedelta64(int(6*60+45), 's'),
                                np.timedelta64(int(9*60), 's')]})
runners = runners.set_index('runner') # must be a better way
#print(runners)

# taken from https://www.timeanddate.com/sun/usa/atlanta
sunset = np.datetime64('2017-04-21T20:13')
sunrise = np.datetime64('2017-04-22T06:57')

# calculate the leg times for the actual races
time_error = np.timedelta64(int(30), 's')
time_zero = np.timedelta64(int(0), 's')
leg_time = []
leg_time_fast = []
leg_time_slow = []
for index, row in race.iterrows():
    if row.runner == 0:
        leg_time.append(time_zero)
        leg_time_fast.append(time_zero)
        leg_time_slow.append(time_zero)
    else:
        leg_time.append(row.distance*runners.loc[row.runner].pace)
        leg_time_fast.append(row.distance*(runners.loc[row.runner].pace-time_error))
        leg_time_slow.append(row.distance*(runners.loc[row.runner].pace+time_error))
race['time'] = leg_time
race['time_fast'] = leg_time_fast
race['time_slow'] = leg_time_slow
race['time_accum'] = np.add.accumulate(race['time'])
race['time_accum_fast'] = np.add.accumulate(race['time_fast'])
race['time_accum_slow'] = np.add.accumulate(race['time_slow'])
#print(race)

# set a start time and calculate when the magic happens
time_start = np.datetime64('2017-04-21T17:00')
for label in ['time_accum', 'time_accum_fast', 'time_accum_slow']:
    race[label] = [ time_start+time_accum for time_accum in race[label]]
#print(race)

# load in the actual times
with open(os.path.join(docsdir,'actual.json'), 'r') as handle:
    actual = json.load(handle)
    actual = [np.datetime64(item) for item in actual]
while len(actual) < 12: # magic number related to number of legs
    actual.append(None)

# calculate new updated estimated times
est_updating = actual[:]
for i, _ in enumerate(est_updating):
    if i == 0:
        continue
    if est_updating[i] is not None:
        continue
    est_updating[i] = est_updating[i-1] + race.time[2*i-1] + race.time[2*i]
# add the finish time
est_updating.append(est_updating[-1] + race.time[race.time.size-2] + race.time[race.time.size-1])

######################################################################
############################## put together the json document
leg_descr = {0:'gre/yel',
             1:'red/gre',
             2:'yel/red'}
leg_miles = {0:legs[0]+legs[1],
             1:legs[2]+legs[0],
             2:legs[1]+legs[2]}
json_data = []
for index, row in race.iterrows():
    if index%2 != 0: # it is an ultra
        continue
    if index == 0:
{'fraction_non_alphanumeric': 0.18753296065815842, 'fraction_numerical': 0.029110853285518407, 'mean_word_length': 3.822990844354018, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1434074', 'n_tokens_mistral': 3519, 'n_tokens_neox': 3252, 'n_words': 706}