105 lines
3.5 KiB
Python
105 lines
3.5 KiB
Python
import pandas as pd
|
|
|
|
df_teachers = pd.read_excel('老师信息示例.xlsx')
|
|
df_students = pd.read_excel('学生信息示例.xlsx')
|
|
|
|
teachers = []
|
|
for _, row in df_teachers.iterrows():
|
|
availability = {}
|
|
for col in df_teachers.columns:
|
|
if col not in ['老师姓名', '老师类型']:
|
|
val = row.get(col, '')
|
|
if pd.notna(val) and str(val).strip():
|
|
availability[col] = str(val)
|
|
teachers.append({
|
|
'id': row['老师姓名'],
|
|
'name': row['老师姓名'],
|
|
'type': row['老师类型'],
|
|
'availability': availability
|
|
})
|
|
|
|
students = []
|
|
for _, row in df_students.iterrows():
|
|
history_str = row.get('历史匹配老师', '')
|
|
history = []
|
|
if pd.notna(history_str) and str(history_str).strip():
|
|
history = [t.strip() for t in str(history_str).split(',')]
|
|
|
|
availability = {}
|
|
for col in df_students.columns:
|
|
if col not in ['学生姓名', '历史匹配老师']:
|
|
val = row.get(col, '')
|
|
if pd.notna(val) and str(val).strip():
|
|
availability[col] = str(val)
|
|
|
|
students.append({
|
|
'id': row['学生姓名'],
|
|
'name': row['学生姓名'],
|
|
'availability': availability,
|
|
'history': history
|
|
})
|
|
|
|
print('=== 检查数据导入 ===')
|
|
print(f'老师数量: {len(teachers)}')
|
|
print(f'学生数量: {len(students)}')
|
|
print()
|
|
|
|
print('=== 检查老师类型分布 ===')
|
|
new_count = sum(1 for t in teachers if t['type'] == '新')
|
|
old_count = sum(1 for t in teachers if t['type'] == '旧')
|
|
print(f'新老师: {new_count}, 旧老师: {old_count}')
|
|
print()
|
|
|
|
print('=== 检查学生历史记录分布 ===')
|
|
history_counts = {}
|
|
for s in students:
|
|
cnt = len(s['history'])
|
|
history_counts[cnt] = history_counts.get(cnt, 0) + 1
|
|
print('学生历史记录数量分布:')
|
|
for cnt in sorted(history_counts.keys()):
|
|
print(f' {cnt} 个历史老师: {history_counts[cnt]} 人')
|
|
print()
|
|
|
|
def parse_slots(time_str):
|
|
slots = []
|
|
for slot in time_str.split(';'):
|
|
slot = slot.strip()
|
|
if slot and '-' in slot:
|
|
parts = slot.split('-')
|
|
if len(parts) == 2:
|
|
slots.append((parts[0].strip(), parts[1].strip()))
|
|
return slots
|
|
|
|
print('=== 检查时间段匹配情况 ===')
|
|
for student in students[:5]:
|
|
history_count = len(student['history'])
|
|
expected_type = '旧' if history_count == 0 else ('新' if history_count % 2 == 1 else '旧')
|
|
|
|
print(f'\n学生: {student["name"]}')
|
|
print(f' 期望老师类型: {expected_type}')
|
|
print(f' 可用时间: {student["availability"]}')
|
|
print(f' 历史老师: {student["history"]}')
|
|
|
|
found_match = False
|
|
for teacher in teachers:
|
|
if teacher['type'] != expected_type:
|
|
continue
|
|
if teacher['id'] in student['history']:
|
|
continue
|
|
|
|
for day, s_time in student['availability'].items():
|
|
if day not in teacher['availability']:
|
|
continue
|
|
|
|
t_time = teacher['availability'][day]
|
|
s_slots = parse_slots(s_time)
|
|
t_slots = parse_slots(t_time)
|
|
|
|
for s_start, s_end in s_slots:
|
|
for t_start, t_end in t_slots:
|
|
if s_start == t_start and s_end == t_end:
|
|
print(f' ✓ {teacher["name"]} 在 {day} 有匹配时间段: {s_start}-{s_end}')
|
|
found_match = True
|
|
|
|
if not found_match:
|
|
print(f' ✗ 未找到匹配的老师') |