Created
June 11, 2012 18:42
-
-
Save ctb/2911843 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# let's use the CSV library: http://docs.python.org/library/csv.html | |
import csv | |
import urllib | |
from datetime import datetime | |
def load_data(url): | |
data = [] | |
fp = urllib.urlopen('http://lyorn.idyll.org/~t/transfer/workout.csv') | |
reader = csv.reader(fp) | |
for line in reader: | |
if line and not line[0].startswith('#'): | |
data.append(line) | |
workouts = [] | |
for (date, exercise, miles, duration) in data: | |
miles = int(miles) | |
duration = int(duration) | |
exercise = exercise.strip() | |
date = datetime.strptime(date, "%Y, %b-%d") | |
workouts.append([date, exercise, miles, duration]) | |
return workouts | |
def get_durations(workouts): | |
durations = [] | |
for row in workouts: | |
durations.append(row[3]) | |
return durations | |
def get_days(workouts): | |
days = [] | |
for row in workouts: | |
date = row[0] | |
day = date.day | |
days.append(day) | |
return days | |
w1 = load_data('http://lyorn.idyll.org/~t/transfer/workout.csv') | |
durations1 = get_durations(w1) | |
days1 = get_days(w1) | |
plot(days1, durations1, 'r--', linewidth=2) | |
xlabel('Day of month') | |
ylabel('Duration of workout') | |
title('My workout') | |
grid() | |
xticks(range(1, max(days) + 1)) | |
axis(ymax=70) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment