Hari-Prasath-M91 commited on
Commit
7db6671
·
1 Parent(s): d6fb46f
Files changed (1) hide show
  1. app.py +97 -24
app.py CHANGED
@@ -11,7 +11,7 @@ from dateutil import parser
11
  from collections import defaultdict
12
  from langchain_openai import ChatOpenAI
13
  from langchain_core.messages import HumanMessage, SystemMessage
14
- from typing import Annotated, List, Optional
15
  from pydantic import BaseModel, Field
16
  from typing_extensions import TypedDict
17
  from langgraph.graph import StateGraph, START, END
@@ -70,27 +70,62 @@ def process_task_data():
70
 
71
  def add_test(roadmap, date, physics = [], chemistry = [], maths = []):
72
  date = parser.parse(date).strftime("%Y-%m-%d")
 
73
  for i, day in enumerate(roadmap["schedule"]):
74
  if day["date"] == date:
75
- roadmap["schedule"][i] = {
76
- "dayNumber": day['dayNumber'],
77
- "date": date,
78
- "test_portion": [
79
- {
80
- "name": "Physics",
81
- "chapters": physics
82
- },
83
- {
84
- "name": "Chemistry",
85
- "chapters": chemistry
86
- },
87
- {
88
- "name": "Maths",
89
- "chapters": maths
90
- }
91
- ],
92
- "subjects": day['subjects']
93
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  return roadmap
95
 
96
  def check_tot_time(day):
@@ -516,11 +551,10 @@ def update_roadmap(current_roadmap, current_dayNumber, max_hours_per_day, depend
516
  ratio = (0, 100)
517
  else:
518
  # No upcoming test: Normal scheduling
519
- if day_index + 4 <= len(current_roadmap['schedule']):
520
  before_checkpoint = current_roadmap['schedule'][day_index:day_index+4]
521
  after_checkpoint = current_roadmap['schedule'][day_index+4:]
522
  else:
523
- print("Helloo")
524
  before_checkpoint = current_roadmap['schedule'][day_index:]
525
  after_checkpoint = []
526
  ratio = (80, 20)
@@ -570,6 +604,13 @@ def update_roadmap(current_roadmap, current_dayNumber, max_hours_per_day, depend
570
  new_roadmap = current_roadmap['schedule'][:ckp_idx+1]
571
  new_roadmap.extend(curr_roadmap[1:])
572
  current_roadmap['schedule'] = new_roadmap
 
 
 
 
 
 
 
573
  elif 0 < time_to_test <= (10 + extra_rev_days):
574
  # Step 1: Add empty days at the end
575
  last_day = current_roadmap['schedule'][-1]
@@ -597,7 +638,7 @@ def update_roadmap(current_roadmap, current_dayNumber, max_hours_per_day, depend
597
  target_day["subjects"] = new_task_day["subjects"]
598
 
599
  else:
600
- if day_index + 4 <= len(current_roadmap['schedule']):
601
  new_checkpoint = copy.deepcopy(after_checkpoint)
602
  day = copy.deepcopy(after_checkpoint[0])
603
  for subject in day['subjects']:
@@ -621,6 +662,13 @@ def update_roadmap(current_roadmap, current_dayNumber, max_hours_per_day, depend
621
  new_roadmap = current_roadmap['schedule'][:ckp_idx+1]
622
  new_roadmap.extend(curr_roadmap[1:])
623
  current_roadmap['schedule'] = new_roadmap
 
 
 
 
 
 
 
624
  else:
625
  for tasks in extra_day_tasks:
626
  day = copy.deepcopy(new_roadmap[-1])
@@ -1197,13 +1245,38 @@ def testscheduler(
1197
  maths : list = Query(["Limits,Continuity and Differentiability"], description="Enter the chapters for test in maths as a list"),
1198
  ):
1199
  """
1200
- Helps in Scheduling of Tests in the roadmap
1201
  """
1202
 
1203
  session_state["data"] = add_test(session_state["data"], date, physics, chemistry, maths)
1204
 
1205
  return {"sucessful": "Test Succesfully Scheduled in the roadmap"}
1206
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1207
  # --- AGENT 2: Roadmap Manager (Roadmap Manager Page) ---
1208
  @app.get("/agent2")
1209
  def agent2(
 
11
  from collections import defaultdict
12
  from langchain_openai import ChatOpenAI
13
  from langchain_core.messages import HumanMessage, SystemMessage
14
+ from typing import Annotated, List, Optional, Literal
15
  from pydantic import BaseModel, Field
16
  from typing_extensions import TypedDict
17
  from langgraph.graph import StateGraph, START, END
 
70
 
71
  def add_test(roadmap, date, physics = [], chemistry = [], maths = []):
72
  date = parser.parse(date).strftime("%Y-%m-%d")
73
+ found = False
74
  for i, day in enumerate(roadmap["schedule"]):
75
  if day["date"] == date:
76
+ found = True
77
+ day["test_portion"] = [{
78
+ "name": "Physics",
79
+ "chapters": physics
80
+ }, {
81
+ "name": "Chemistry",
82
+ "chapters": chemistry
83
+ }, {
84
+ "name": "Maths",
85
+ "chapters": maths
86
+ }]
87
+ break
88
+ if not found:
89
+ print("Kindly check the Entered Date(YYYY-MM-DD), it's not available in the roadmap")
90
+ return roadmap
91
+
92
+ def add_tasks(roadmap, tasks):
93
+ from_date = datetime.strptime(parser.parse(tasks.from_date).strftime("%Y-%m-%d"), "%Y-%m-%d")
94
+ to_date = datetime.strptime(parser.parse(tasks.to_date).strftime("%Y-%m-%d"), "%Y-%m-%d")
95
+
96
+ current_date = from_date
97
+ date_found = False
98
+ while current_date <= to_date:
99
+ date_str = current_date.strftime("%Y-%m-%d")
100
+
101
+ # Find the day in the roadmap
102
+ day = next((d for d in roadmap["schedule"] if d["date"] == date_str), None)
103
+ if not day:
104
+ current_date += timedelta(days=1)
105
+ continue
106
+ date_found = True
107
+ # Ensure 'teacher_tasks' exists
108
+ if "teacher_tasks" not in day:
109
+ day["teacher_tasks"] = []
110
+
111
+ for subject_block in tasks.subjects:
112
+ subject_name = subject_block.subject
113
+ new_tasks = [task.model_dump() for task in subject_block.tasks]
114
+
115
+ # Check if subject already exists for the day
116
+ subject_entry = next((sub for sub in day["teacher_tasks"] if sub["name"] == subject_name), None)
117
+
118
+ if subject_entry:
119
+ subject_entry["tasks"].extend(new_tasks)
120
+ else:
121
+ day["teacher_tasks"].append({
122
+ "name": subject_name,
123
+ "tasks": new_tasks
124
+ })
125
+
126
+ current_date += timedelta(days=1)
127
+ if not date_found:
128
+ print("Kindly check the Entered Dates(YYYY-MM-DD), they are not available in the roadmap")
129
  return roadmap
130
 
131
  def check_tot_time(day):
 
551
  ratio = (0, 100)
552
  else:
553
  # No upcoming test: Normal scheduling
554
+ if day_index + 4 <= len(current_roadmap['schedule'])-1:
555
  before_checkpoint = current_roadmap['schedule'][day_index:day_index+4]
556
  after_checkpoint = current_roadmap['schedule'][day_index+4:]
557
  else:
 
558
  before_checkpoint = current_roadmap['schedule'][day_index:]
559
  after_checkpoint = []
560
  ratio = (80, 20)
 
604
  new_roadmap = current_roadmap['schedule'][:ckp_idx+1]
605
  new_roadmap.extend(curr_roadmap[1:])
606
  current_roadmap['schedule'] = new_roadmap
607
+ for tasks in extra_days:
608
+ day = copy.deepcopy(new_roadmap[-1])
609
+ day["dayNumber"] = current_roadmap['schedule'][-1]["dayNumber"] + 1
610
+ day["date"] = (datetime.strptime(current_roadmap['schedule'][-1]["date"], "%Y-%m-%d")
611
+ + timedelta(days=1)).strftime("%Y-%m-%d")
612
+ day['subjects'] = tasks['subjects']
613
+ current_roadmap['schedule'].append(day)
614
  elif 0 < time_to_test <= (10 + extra_rev_days):
615
  # Step 1: Add empty days at the end
616
  last_day = current_roadmap['schedule'][-1]
 
638
  target_day["subjects"] = new_task_day["subjects"]
639
 
640
  else:
641
+ if day_index + 4 <= len(current_roadmap['schedule'])-1:
642
  new_checkpoint = copy.deepcopy(after_checkpoint)
643
  day = copy.deepcopy(after_checkpoint[0])
644
  for subject in day['subjects']:
 
662
  new_roadmap = current_roadmap['schedule'][:ckp_idx+1]
663
  new_roadmap.extend(curr_roadmap[1:])
664
  current_roadmap['schedule'] = new_roadmap
665
+ for tasks in extra_days:
666
+ day = copy.deepcopy(new_roadmap[-1])
667
+ day["dayNumber"] = current_roadmap['schedule'][-1]["dayNumber"] + 1
668
+ day["date"] = (datetime.strptime(current_roadmap['schedule'][-1]["date"], "%Y-%m-%d")
669
+ + timedelta(days=1)).strftime("%Y-%m-%d")
670
+ day['subjects'] = tasks['subjects']
671
+ current_roadmap['schedule'].append(day)
672
  else:
673
  for tasks in extra_day_tasks:
674
  day = copy.deepcopy(new_roadmap[-1])
 
1245
  maths : list = Query(["Limits,Continuity and Differentiability"], description="Enter the chapters for test in maths as a list"),
1246
  ):
1247
  """
1248
+ Helps the teacher in Scheduling of Tests in the roadmap
1249
  """
1250
 
1251
  session_state["data"] = add_test(session_state["data"], date, physics, chemistry, maths)
1252
 
1253
  return {"sucessful": "Test Succesfully Scheduled in the roadmap"}
1254
 
1255
+
1256
+ class Task(BaseModel):
1257
+ chapter: str = Field(..., description="The chapter associated with this task.")
1258
+ description: str = Field(..., description="A brief explanation of what needs to be done.")
1259
+ estimated_time: int = Field(..., description="Estimated time in hours to complete the task.")
1260
+
1261
+ class SubjectTasks(BaseModel):
1262
+ subject: Literal["Physics", "Chemistry", "Maths"] = Field(..., description="The subject the tasks belong to.")
1263
+ tasks: List[Task] = Field(default_factory=list, description="The list of tasks in this subject.")
1264
+
1265
+ class Tasks(BaseModel):
1266
+ from_date: str = Field(..., description="The start date for the tasks")
1267
+ to_date: str = Field(..., description="The end date for the tasks.")
1268
+ subjects: List[SubjectTasks] = Field(default_factory=list, description="Subjectwise Task list")
1269
+
1270
+ @app.post("/taskadder")
1271
+ def taskadder(tasks: Tasks):
1272
+ """
1273
+ Helps the teacher in scheduling tasks in the roadmap.
1274
+ If no tasks are given, the subject entry will still be added with an empty task list.
1275
+ """
1276
+ session_state["data"] = add_tasks(session_state["data"], tasks)
1277
+
1278
+ return {"successful": "Task successfully added to the roadmap"}
1279
+
1280
  # --- AGENT 2: Roadmap Manager (Roadmap Manager Page) ---
1281
  @app.get("/agent2")
1282
  def agent2(