Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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