Add function for averaging ratings

master
trémeur 2 years ago
parent b220032d6b
commit f14776b576

@ -6,6 +6,24 @@ from datetime import datetime
thisyear = datetime.now().strftime("%Y")
home = str(Path.home())
stats = []
rates = []
rating = []
rated = []
def rate(line):
if "and rated" in line:
rated.append(1)
if "★★★★★" in line:
rating.append(5)
elif "★★★★" in line:
rating.append(4)
elif "★★★" in line:
rating.append(3)
elif "★★" in line:
rating.append(2)
elif "" in line:
rating.append(1)
def iterate(category,action,year=thisyear,date=False):
basedir = home + "/Documents/drive/org/journal/" + str(year)
@ -36,6 +54,7 @@ def iterate(category,action,year=thisyear,date=False):
print(lines[num].strip() + " " + lines[0].strip())
else:
print(lines[num].strip())
rate(lines[num])
count += 1
else:
break
@ -54,20 +73,28 @@ def iterate(category,action,year=thisyear,date=False):
print(lines[num].strip() + " " + lines[0].strip())
else:
print(lines[num].strip())
count += 1
rate(lines[num])
count += 1
else:
break
else:
break
month += 1
stats.append(count)
if (sum(rated)) != 0:
avg = round((sum(rating)/sum(rated)),2)
else:
avg = "n/a"
rates.append(avg)
rating.clear()
rated.clear()
def yeargrab(year=thisyear):
iterate("books","read",year)
iterate("films","watched",year)
print("* stats")
print("** books read: " + str(stats[0]))
print("** films watched: " + str(stats[1]))
print("** books read: " + str(stats[0]) + ", average rating: " + str(rates[0]))
print("** films watched: " + str(stats[1]) + ", average rating: " + str(rates[1]))
if __name__ == "__main__":
yeargrab()

Loading…
Cancel
Save