Skip to content

Instantly share code, notes, and snippets.

@jinhwanlazy
Created March 9, 2017 21:33
Show Gist options
  • Save jinhwanlazy/acda3542660a8fad94793f4caae3c8a4 to your computer and use it in GitHub Desktop.
Save jinhwanlazy/acda3542660a8fad94793f4caae3c8a4 to your computer and use it in GitHub Desktop.
import sys
import matplotlib.pyplot as plt
import pandas as pd
from matplotlib import cm
from datetime import datetime, timezone, timedelta
plt.style.use('ggplot')
ticks_format = {
'day': '%b, %-d',
'week': '%b, %-d',
'month': '%b',
'year': '%Y'
}
def group_date(gr):
def str_to_datetime(s):
date_format = "%Y-%m-%d %H:%M:%S"
return datetime.strptime(s, date_format)
def utc_to_local(utc_dt):
return utc_dt.replace(tzinfo=timezone.utc).astimezone(tz=None)
group_method = {
'day': datetime.date,
'week': lambda dt: dt.date() + timedelta(days=6-(dt.weekday() % 7)),
'month': lambda dt: datetime(dt.year, dt.month, 1),
'year': lambda dt: datetime(dt.year, 1, 1)
}
return lambda s: group_method[gr](utc_to_local(str_to_datetime(s)))
if __name__ == "__main__":
data = pd.read_csv(sys.argv[1], sep=',')
gr = sys.argv[2] if (
len(sys.argv) > 2 and sys.argv[2] in ticks_format) else 'day'
data['date'] = data['Date/Time (UTC)'].map(group_date(gr))
avg = []
for date in set(data['date']):
d = data.loc[data['date'] == date]
avg.append((len(d), d['Accuracy'].mean(), d['WPM'].mean()))
_, acc, wpm = zip(*avg)
plt.scatter(acc, wpm)
for n, *coord in avg:
plt.annotate(n, coord)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment