Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,16 @@ except Exception as e:
|
|
| 15 |
print(f"加载教室到校区映射失败: {e}")
|
| 16 |
classroom_to_campus_mapping = {}
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
# 根据教室名称获取校区的函数
|
| 19 |
def get_campus_by_classroom(location):
|
| 20 |
"""
|
|
@@ -277,6 +287,10 @@ def student_page():
|
|
| 277 |
def classroom_page():
|
| 278 |
return render_template("classroom.html")
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
@app.route("/api/students")
|
| 281 |
def get_students():
|
| 282 |
students = student_data["姓名"].dropna().unique().tolist()
|
|
@@ -386,6 +400,84 @@ def get_courses_by_classroom():
|
|
| 386 |
results = sorted(results, key=lambda x: (x["星期"], x["节次"][0]))
|
| 387 |
return jsonify(results)
|
| 388 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
@app.route("/api/student_courses_v2")
|
| 390 |
def get_student_courses_v2():
|
| 391 |
week = request.args.get("week", 1)
|
|
|
|
| 15 |
print(f"加载教室到校区映射失败: {e}")
|
| 16 |
classroom_to_campus_mapping = {}
|
| 17 |
|
| 18 |
+
# 加载学生过滤名单
|
| 19 |
+
try:
|
| 20 |
+
with open('./数据表/student_filter_list.json', 'r', encoding='utf-8') as f:
|
| 21 |
+
student_filter_data = json.load(f)
|
| 22 |
+
allowed_students = set(student_filter_data.get('allowed_students', []))
|
| 23 |
+
print(f"成功加载学生过滤名单,共{len(allowed_students)}个学生")
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"加载学生过滤名单失败: {e}")
|
| 26 |
+
allowed_students = set()
|
| 27 |
+
|
| 28 |
# 根据教室名称获取校区的函数
|
| 29 |
def get_campus_by_classroom(location):
|
| 30 |
"""
|
|
|
|
| 287 |
def classroom_page():
|
| 288 |
return render_template("classroom.html")
|
| 289 |
|
| 290 |
+
@app.route("/schedule-overlap")
|
| 291 |
+
def schedule_overlap_page():
|
| 292 |
+
return render_template("schedule_overlap.html")
|
| 293 |
+
|
| 294 |
@app.route("/api/students")
|
| 295 |
def get_students():
|
| 296 |
students = student_data["姓名"].dropna().unique().tolist()
|
|
|
|
| 400 |
results = sorted(results, key=lambda x: (x["星期"], x["节次"][0]))
|
| 401 |
return jsonify(results)
|
| 402 |
|
| 403 |
+
@app.route("/api/schedule_overlap")
|
| 404 |
+
def get_schedule_overlap():
|
| 405 |
+
"""
|
| 406 |
+
获取23级大数据1区、24级大数据1/2/3区的课表叠加数据
|
| 407 |
+
"""
|
| 408 |
+
week = request.args.get("week", "1")
|
| 409 |
+
|
| 410 |
+
# 目标班级列表
|
| 411 |
+
target_classes = ["23大数据1区", "24大数据1区", "24大数据2区", "24大数据3区"]
|
| 412 |
+
|
| 413 |
+
try:
|
| 414 |
+
# 解析周次
|
| 415 |
+
week_num = int(week)
|
| 416 |
+
|
| 417 |
+
# 获取所有目标班级的课程数据
|
| 418 |
+
all_courses = []
|
| 419 |
+
for class_name in target_classes:
|
| 420 |
+
# 筛选指定班级和周次的课程
|
| 421 |
+
class_courses = grade_data[
|
| 422 |
+
(grade_data["行政班级"] == class_name) &
|
| 423 |
+
(grade_data["周次"].astype(str).str.contains(str(week_num), na=False))
|
| 424 |
+
]
|
| 425 |
+
|
| 426 |
+
for _, course in class_courses.iterrows():
|
| 427 |
+
# 解析节次和星期
|
| 428 |
+
day_and_period = parse_day_and_period(course["节次"])
|
| 429 |
+
|
| 430 |
+
if day_and_period:
|
| 431 |
+
day, periods = day_and_period
|
| 432 |
+
# 计算日期
|
| 433 |
+
course_date = calculate_date(week_num, day)
|
| 434 |
+
|
| 435 |
+
course_info = {
|
| 436 |
+
"班级": class_name,
|
| 437 |
+
"课程": course["课程"],
|
| 438 |
+
"教师": course["教师"],
|
| 439 |
+
"地点": course["地点"],
|
| 440 |
+
"校区": get_campus_by_classroom(course["地点"]),
|
| 441 |
+
"日期": course_date.strftime("%Y-%m-%d"),
|
| 442 |
+
"星期": day,
|
| 443 |
+
"节次": periods,
|
| 444 |
+
"周次": course["周次"] # 添加周次信息,便于前端区分
|
| 445 |
+
}
|
| 446 |
+
all_courses.append(course_info)
|
| 447 |
+
|
| 448 |
+
return jsonify(all_courses)
|
| 449 |
+
|
| 450 |
+
except Exception as e:
|
| 451 |
+
return jsonify({"error": str(e)}), 500
|
| 452 |
+
|
| 453 |
+
@app.route("/api/class_students")
|
| 454 |
+
def get_class_students():
|
| 455 |
+
"""
|
| 456 |
+
获取指定班级的学生名单
|
| 457 |
+
"""
|
| 458 |
+
class_name = request.args.get("class_name", "")
|
| 459 |
+
|
| 460 |
+
if not class_name:
|
| 461 |
+
return jsonify({"error": "缺少班级名称参数"}), 400
|
| 462 |
+
|
| 463 |
+
try:
|
| 464 |
+
# 使用拷贝的数据,避免修改原始 student_data
|
| 465 |
+
student_data_copy = student_data.copy()
|
| 466 |
+
student_data_copy["区队"] = student_data_copy["区队"].str.extract(r"\](.*)$")[0].str.strip()
|
| 467 |
+
|
| 468 |
+
# 查找指定班级的学生
|
| 469 |
+
class_students = student_data_copy[student_data_copy["区队"] == class_name]
|
| 470 |
+
|
| 471 |
+
# 获取学生名单并过滤
|
| 472 |
+
all_students = class_students["姓名"].tolist()
|
| 473 |
+
# 只返回在过滤名单中的学生
|
| 474 |
+
filtered_students = [student for student in all_students if student in allowed_students]
|
| 475 |
+
|
| 476 |
+
return jsonify(filtered_students)
|
| 477 |
+
|
| 478 |
+
except Exception as e:
|
| 479 |
+
return jsonify({"error": str(e)}), 500
|
| 480 |
+
|
| 481 |
@app.route("/api/student_courses_v2")
|
| 482 |
def get_student_courses_v2():
|
| 483 |
week = request.args.get("week", 1)
|