Skip to content

Instantly share code, notes, and snippets.

@gkbrk gkbrk/todograph.py
Last active Apr 18, 2017

Embed
What would you like to do?
Todo.txt to graph
#!/usr/bin/python3
import matplotlib.pyplot as plt
import datetime
def get_stats(filename):
data = {}
with open(filename) as todofile:
for line in todofile:
date = line.split()[1]
if date in data:
data[date] += 1
else:
data[date] = 1
return data
def get_last_days(days):
for day in range(days)[::-1]:
date = datetime.datetime.today() - datetime.timedelta(days=day)
yield date.date().isoformat()
plt.grid(True)
plt.title("Todo.txt Progress")
plt.ylabel("Number of tasks done")
stats = get_stats("/home/leonardo/Sync/default/done.txt")
todoCounts = []
for date in get_last_days(15):
todoCounts.append(stats.get(date, 0))
plt.yticks(range(max(todoCounts) + 1))
plt.xticks(range(15), get_last_days(15), rotation=80)
plt.plot(todoCounts, marker="o")
plt.tight_layout()
plt.savefig("public/img/todo.jpeg", dpi=100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.