Skip to content

Instantly share code, notes, and snippets.

@ketch
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ketch/41725e506b019720de92 to your computer and use it in GitHub Desktop.
Save ketch/41725e506b019720de92 to your computer and use it in GitHub Desktop.
Script to read in a course schedule Excel spreadsheet and output a visual calendar.
"""
Script to read in a course schedule Excel spreadsheet and output a visual calendar
"""
def time_to_float(time_str):
if time_str is '':
return None
t = time_str.split(':')
return float(t[0]) + float(t[1])/60.
# Read and parse CSV file
import csv
f = open('course_schedule.csv','rU')
reader = csv.reader(f,dialect=csv.excel_tab)
data = []
for row in reader:
data.append(row[0].split(','))
f.close()
# Create data structure
headers = data[0]
name_ind = headers.index('Event Pack')
time_ind = headers.index('Start Time')
days = ['Sun','Mon','Tue','Wed','Thu']
courses = {}
times = []
for course in data[1:]:
courses[course[name_ind]] = {}
courses[course[name_ind]]['time'] = time_to_float(course[time_ind])
times.append(time_to_float(course[time_ind]))
courses[course[name_ind]]['days'] = []
for day in days:
if day in course:
courses[course[name_ind]]['days'].append(day)
times = list(set(times))
times.remove(None)
times.sort()
# Plot calendar
import matplotlib.pyplot as plt
plt.figure(figsize=(18,12),facecolor='white')
ndays = float(len(days))+1
ntimes = float(len(times))+1
for i,day in enumerate(days):
plt.text((i+1)/ndays,0.99,day)
for i,time in enumerate(times):
plt.text(0.01,1.-(i+1)/ntimes,time)
import numpy as np
count = np.zeros((ntimes-1,ndays-1)) # number of classes in each slot
avoid = ['AMCS 211','AMCS 251','AMCS 231','AMCS 241']
for course_name,course in courses.iteritems():
if True:
for day in course['days']:
iday = days.index(day)
itime = times.index(course['time'])
xloc = (1+iday)/ndays
yloc = 1.-(1+itime)/ntimes - 0.02*count[itime,iday]
if course_name in avoid:
color = 'red'
else:
color = 'grey'
plt.text(xloc,yloc,course_name,fontsize=12,color=color)
count[itime,iday] += 1
plt.axis('off')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment