'''
    DS2000
    Spring 2022
    Working with one runner's data
'''

import matplotlib.pyplot as plt

RUNNER_FILE = "runner_data.txt"

def main():
    # Step one - gather data from the file
    with open(RUNNER_FILE, "r") as infile:
        
        month = infile.readline()
        runner = infile.readline()
        
    # Step two -- computations
    
    # Turn a string into a list using split()
    # Split() without anything in the parens
    # means that we split on white space
    month = month.split()
    runner = runner.split()
    
    # Slicing team!!!!
    # How can I save JUST the running data (not name)
    # in a spearate list?
    # in list slicing, lst[x:] means grab from
    # position x in the list all the way to the end
    runner_data = runner[2:]
    
    
    # Range team!!!!!
    # How can I make a new list, made up of 
    # JUST the milageage from runner_data, and without
    # the extra nonsense?
    
    # We tweak range to give it a start position,
    # an end position, and a step (1, 62, 2)
    
    # Range has three options:
        # one number (range(10))... start at 0, end at 9, and step by 1 at a time
        # two numbers (range(5, 10))... start at 5, end at 9, and step by 1 at a time
        # three numbers (range(5, 10, 2).... start at 5, end at 9, and step by 2 at a time
    mileage = []
    for i in range(1, len(runner_data), 2):
        mileage.append(runner_data[i])
        
    # LIst comprehension team!!!!
    # How can I turn my list of strings into a list
    # of floats, in ONE LINE OF CODE
    mileage = [float(run) for run in mileage]
    
    # Step three -- communication
    
    # sanity-check: print out what's in my variables
    print("month:", month)
    print("runner:", runner)
    print("Runner_data:", runner_data)
    print("Mileage:", mileage)
    
    # Plot the mileage as a line chart
    # (But line chart maybe not the best fit?)
    plt.plot(mileage, "-o", label = "Laney January")
    plt.show()
    
    # Plot the mileage as a scatterplot
    
    # Slicing and list comprehension!!!!
    # Currently have a list of strings that
    # also includes 'january-2022'
    x_values = month[1:]
    x_values = [int(num) for num in x_values]
    plt.scatter(x_values, mileage, color = "magenta") 
    
main()