-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudy_tracker.py
More file actions
113 lines (91 loc) · 2.74 KB
/
study_tracker.py
File metadata and controls
113 lines (91 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import json
from datetime import date,datetime
def main_menu():
print("Welcome to Study Tracker!!")
while True:
print("1.Start Study Session")
print("2.View Statistics")
print("3.View Streaks")
print("4.Exit")
choice=int(input("Enter your choice: "))
if choice==1:
print("Starting study session..")
add_study_session()
elif choice==2:
print("Showing Statistics..")
statistics()
elif choice==3:
print("Showing Streaks..")
show_streaks()
elif choice==4:
print("Thank you for using study tracker!!")
break
else:
print("Invalid Choice!Try again!")
def load_data():
with open("data.json","r") as f:
return json.load(f)
data=load_data()
def save_data():
with open("data.json","w") as f:
json.dump(data,f,indent=4)
def add_study_session():
subject=input("enter your subject name:")
duration=int(input("enter the duration in minutes:"))
xp_earned=duration//10
streaks()
session={
"subject":subject,
"duration":duration,
"date": str(date.today()),
"xp_earned":xp_earned
}
data["sessions"].append(session)
data["total_xp"]+=xp_earned
data["level"]=data["total_xp"]//50
save_data()
print("you earned",xp_earned,"XP today!!")
def statistics():
total_sessions=len(data["sessions"])
total_minutes=0
for session in data["sessions"]:
total_minutes+=session["duration"]
total_hours=int(total_minutes/60)
print("Total hours studied:",total_hours)
print("Total XP earned:",data["total_xp"])
print("Current Level:",data["level"])
print("Total number of sessions completed:",total_sessions)
subject_count={}
for session in data["sessions"]:
subject=session["subject"]
if subject in subject_count:
subject_count[subject]+=1
else:
subject_count[subject]=1
most_studied= ""
max_count=0
for subject in subject_count:
if subject_count[subject]>max_count:
max_count=subject_count[subject]
most_studied=subject
print("Most studied subject is :",most_studied)
def streaks():
if not data["sessions"]:
return
last_session=data["sessions"][-1]
last_date=datetime.strptime(last_session["date"], "%Y-%m-%d").date()
today=date.today()
difference=(today-last_date).days
if difference==0:
return
elif difference==1:
data["current_streak"]+=1
else:
data["current_streak"]=1
if data["current_streak"]>data["longest_streak"]:
data["longest_streak"]=data["current_streak"]
def show_streaks():
print("Your study streak:")
print("Current streak:",data["current_streak"],"days")
print("Longest streak:",data["longest_streak"],"days")
main_menu()