Created
January 8, 2021 19:41
-
-
Save mdnurahmed/0140bf7058e5d1b3aee7e03f724a307d to your computer and use it in GitHub Desktop.
Full code
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
import csv | |
from collections import defaultdict | |
from datetime import datetime | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def duration_to_seconds(duration): | |
elements = duration.split(':') | |
hour = int(elements[0]) | |
min = int(elements[1]) | |
sec = int(elements[2]) | |
return hour*60*60 + min*60 + sec | |
def sortKey(val): | |
date = val[0] | |
return datetime.strptime(date, '%m/%d/%Y') | |
mydict = defaultdict(int) | |
with open('clockify.csv', 'r') as file: | |
reader = csv.reader(file) | |
line = 0 | |
for row in reader: | |
line += 1 | |
if line > 1 : | |
date = row[8] | |
duration = row[12] | |
mydict[date] += duration_to_seconds(duration) | |
mylist = list(mydict.items()) | |
mylist.sort(key = sortKey) | |
dates = [] | |
mins = [] | |
for i in range(0,len(mylist)): | |
dates.append(mylist[i][0]) | |
mins.append(int(mylist[i][1]/60)) | |
xpos = np.arange(len(dates)) | |
plt.xticks(xpos,dates) | |
plt.bar(xpos,mins) | |
for i in range(0,len(mins)): | |
plt.text(xpos[i]-0.075 , mins[i] + 3, str(mins[i]), color='red') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment