Update app.py
Browse files
app.py
CHANGED
|
@@ -173,6 +173,10 @@ def get_student_courses():
|
|
| 173 |
grade = request.args.get("grade", None)
|
| 174 |
admin_class = request.args.get("admin_class", None)
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
# 筛选数据
|
| 177 |
filtered_data = grade_data
|
| 178 |
|
|
@@ -180,11 +184,15 @@ def get_student_courses():
|
|
| 180 |
# if grade:
|
| 181 |
# filtered_data = filtered_data[filtered_data["grade"] == grade]
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
-
#
|
| 187 |
-
filtered_data = filtered_data[filtered_data["课程类别"].str.contains("必修课", na=False)]
|
| 188 |
|
| 189 |
if week:
|
| 190 |
week = int(week)
|
|
@@ -201,8 +209,9 @@ def get_student_courses():
|
|
| 201 |
course_date = calculate_date(week, day) # 计算课程日期
|
| 202 |
|
| 203 |
# 根据地点判断校区
|
| 204 |
-
|
| 205 |
-
|
|
|
|
| 206 |
# 简化校区名称显示
|
| 207 |
campus_display = campus.replace("校区", "")
|
| 208 |
|
|
@@ -239,10 +248,18 @@ def get_courses_by_teacher():
|
|
| 239 |
week = request.args.get("week", 1)
|
| 240 |
teacher = request.args.get("teacher", None)
|
| 241 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
# 筛选数据
|
| 243 |
filtered_data = teacher_data
|
| 244 |
-
|
| 245 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
if week:
|
| 247 |
week = int(week)
|
| 248 |
filtered_data = filtered_data[filtered_data["周次"].apply(lambda x: week in parse_weeks(x) if pd.notna(x) else False)]
|
|
@@ -256,8 +273,9 @@ def get_courses_by_teacher():
|
|
| 256 |
course_date = calculate_date(week, day) # 计算课程日期
|
| 257 |
|
| 258 |
# 根据地点判断校区
|
| 259 |
-
|
| 260 |
-
|
|
|
|
| 261 |
# 简化校区名称显示
|
| 262 |
campus_display = campus.replace("校区", "")
|
| 263 |
|
|
@@ -330,7 +348,9 @@ def get_courses_by_classroom():
|
|
| 330 |
classroom = request.args.get("classroom", None)
|
| 331 |
campus = request.args.get("campus", None)
|
| 332 |
|
| 333 |
-
|
|
|
|
|
|
|
| 334 |
|
| 335 |
if classroom_data.empty:
|
| 336 |
return jsonify({"error": "教室数据未加载"}), 500
|
|
@@ -340,8 +360,13 @@ def get_courses_by_classroom():
|
|
| 340 |
|
| 341 |
if campus:
|
| 342 |
filtered_data = filtered_data[filtered_data["校区"] == campus]
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
if week:
|
| 347 |
week = int(week)
|
|
@@ -505,9 +530,9 @@ def get_student_courses_v2():
|
|
| 505 |
else:
|
| 506 |
return jsonify([])
|
| 507 |
|
| 508 |
-
#
|
| 509 |
-
if '课程类别' in filtered_data.columns:
|
| 510 |
-
|
| 511 |
|
| 512 |
# 按周次筛选
|
| 513 |
if week:
|
|
@@ -530,8 +555,9 @@ def get_student_courses_v2():
|
|
| 530 |
course_date = calculate_date(week, day) # 计算课程日期
|
| 531 |
|
| 532 |
# 根据地点判断校区
|
| 533 |
-
|
| 534 |
-
|
|
|
|
| 535 |
# 简化校区名称显示
|
| 536 |
campus_display = campus.replace("校区", "")
|
| 537 |
|
|
|
|
| 173 |
grade = request.args.get("grade", None)
|
| 174 |
admin_class = request.args.get("admin_class", None)
|
| 175 |
|
| 176 |
+
# 参数验证:如果没有提供admin_class参数,返回空结果
|
| 177 |
+
if not admin_class:
|
| 178 |
+
return jsonify([])
|
| 179 |
+
|
| 180 |
# 筛选数据
|
| 181 |
filtered_data = grade_data
|
| 182 |
|
|
|
|
| 184 |
# if grade:
|
| 185 |
# filtered_data = filtered_data[filtered_data["grade"] == grade]
|
| 186 |
|
| 187 |
+
# 筛选指定班级的数据
|
| 188 |
+
filtered_data = filtered_data[filtered_data["行政班级"].str.contains(admin_class, na=False)]
|
| 189 |
+
|
| 190 |
+
# 如果没有找到匹配的班级,返回空结果
|
| 191 |
+
if filtered_data.empty:
|
| 192 |
+
return jsonify([])
|
| 193 |
|
| 194 |
+
# 移除课程类型筛选,显示所有课程(必修课、选修课等)
|
| 195 |
+
# filtered_data = filtered_data[filtered_data["课程类别"].str.contains("必修课", na=False)]
|
| 196 |
|
| 197 |
if week:
|
| 198 |
week = int(week)
|
|
|
|
| 209 |
course_date = calculate_date(week, day) # 计算课程日期
|
| 210 |
|
| 211 |
# 根据地点判断校区
|
| 212 |
+
location_str = str(row["地点"]) if pd.notna(row["地点"]) else ""
|
| 213 |
+
location = location_str.split("(")[0] if "(" in location_str else location_str
|
| 214 |
+
campus = get_campus_by_classroom(location_str)
|
| 215 |
# 简化校区名称显示
|
| 216 |
campus_display = campus.replace("校区", "")
|
| 217 |
|
|
|
|
| 248 |
week = request.args.get("week", 1)
|
| 249 |
teacher = request.args.get("teacher", None)
|
| 250 |
|
| 251 |
+
# 参数验证:如果没有提供teacher参数,返回空结果
|
| 252 |
+
if not teacher:
|
| 253 |
+
return jsonify([])
|
| 254 |
+
|
| 255 |
# 筛选数据
|
| 256 |
filtered_data = teacher_data
|
| 257 |
+
# 筛选指定教师的数据
|
| 258 |
+
filtered_data = filtered_data[filtered_data["教师"] == teacher]
|
| 259 |
+
|
| 260 |
+
# 如果没有找到匹配的教师,返回空结果
|
| 261 |
+
if filtered_data.empty:
|
| 262 |
+
return jsonify([])
|
| 263 |
if week:
|
| 264 |
week = int(week)
|
| 265 |
filtered_data = filtered_data[filtered_data["周次"].apply(lambda x: week in parse_weeks(x) if pd.notna(x) else False)]
|
|
|
|
| 273 |
course_date = calculate_date(week, day) # 计算课程日期
|
| 274 |
|
| 275 |
# 根据地点判断校区
|
| 276 |
+
location_str = str(row["地点"]) if pd.notna(row["地点"]) else ""
|
| 277 |
+
location = location_str.split("(")[0] if "(" in location_str else location_str
|
| 278 |
+
campus = get_campus_by_classroom(location_str)
|
| 279 |
# 简化校区名称显示
|
| 280 |
campus_display = campus.replace("校区", "")
|
| 281 |
|
|
|
|
| 348 |
classroom = request.args.get("classroom", None)
|
| 349 |
campus = request.args.get("campus", None)
|
| 350 |
|
| 351 |
+
# 参数验证:如果没有提供classroom参数,返回空结果
|
| 352 |
+
if not classroom:
|
| 353 |
+
return jsonify([])
|
| 354 |
|
| 355 |
if classroom_data.empty:
|
| 356 |
return jsonify({"error": "教室数据未加载"}), 500
|
|
|
|
| 360 |
|
| 361 |
if campus:
|
| 362 |
filtered_data = filtered_data[filtered_data["校区"] == campus]
|
| 363 |
+
|
| 364 |
+
# 筛选指定教室的数据
|
| 365 |
+
filtered_data = filtered_data[filtered_data["教室"] == classroom]
|
| 366 |
+
|
| 367 |
+
# 如果没有找到匹配的教室,返回空结果
|
| 368 |
+
if filtered_data.empty:
|
| 369 |
+
return jsonify([])
|
| 370 |
|
| 371 |
if week:
|
| 372 |
week = int(week)
|
|
|
|
| 530 |
else:
|
| 531 |
return jsonify([])
|
| 532 |
|
| 533 |
+
# 移除课程类型筛选,显示所有课程(必修课、选修课等)
|
| 534 |
+
# if '课程类别' in filtered_data.columns:
|
| 535 |
+
# filtered_data = filtered_data[filtered_data["课程类别"].str.contains("必修课", na=False)]
|
| 536 |
|
| 537 |
# 按周次筛选
|
| 538 |
if week:
|
|
|
|
| 555 |
course_date = calculate_date(week, day) # 计算课程日期
|
| 556 |
|
| 557 |
# 根据地点判断校区
|
| 558 |
+
location_str = str(row["地点"]) if pd.notna(row["地点"]) else ""
|
| 559 |
+
location = location_str.split("(")[0] if "(" in location_str else location_str
|
| 560 |
+
campus = get_campus_by_classroom(location_str)
|
| 561 |
# 简化校区名称显示
|
| 562 |
campus_display = campus.replace("校区", "")
|
| 563 |
|