61 lines
2.1 KiB
Python
61 lines
2.1 KiB
Python
import pandas as pd
|
|
import random
|
|
|
|
random.seed(42)
|
|
|
|
days = ['1月1日', '1月2日', '1月3日', '1月4日', '1月5日', '1月6日', '1月7日']
|
|
time_slots = ['9:00-10:30', '10:30-12:00', '14:00-15:30', '15:30-17:00', '18:00-19:30']
|
|
|
|
teacher_count = 30
|
|
student_count = 100
|
|
|
|
teacher_names = [f"张{i}老师" for i in range(1, teacher_count + 1)]
|
|
teacher_types = []
|
|
for i in range(teacher_count):
|
|
if i < teacher_count * 0.4:
|
|
teacher_types.append("新")
|
|
else:
|
|
teacher_types.append("旧")
|
|
random.shuffle(teacher_types)
|
|
|
|
teachers = []
|
|
for i, name in enumerate(teacher_names):
|
|
teacher = {"老师姓名": name}
|
|
teacher["老师类型"] = teacher_types[i]
|
|
available_days = random.sample(days, random.randint(1, 3))
|
|
for day in days:
|
|
if day in available_days:
|
|
num_slots = random.randint(1, 3)
|
|
teacher[day] = '; '.join(random.sample(time_slots, num_slots))
|
|
else:
|
|
teacher[day] = ''
|
|
teachers.append(teacher)
|
|
|
|
df_teachers = pd.DataFrame(teachers)
|
|
df_teachers.to_excel('老师信息示例.xlsx', index=False)
|
|
print(f"已生成 {teacher_count} 位老师数据")
|
|
|
|
student_names = [f"学生{i}" for i in range(1, student_count + 1)]
|
|
students = []
|
|
for i, name in enumerate(student_names):
|
|
student = {"学生姓名": name}
|
|
available_days = random.sample(days, random.randint(2, 5))
|
|
for day in days:
|
|
if day in available_days:
|
|
num_slots = random.randint(1, 3)
|
|
student[day] = '; '.join(random.sample(time_slots, num_slots))
|
|
else:
|
|
student[day] = ''
|
|
|
|
history_count = random.randint(0, 3)
|
|
available_teachers = [t for t in teacher_names if t != name]
|
|
if available_teachers and history_count > 0:
|
|
history_teachers = random.sample(available_teachers, min(history_count, len(available_teachers)))
|
|
student["历史匹配老师"] = ', '.join(history_teachers)
|
|
else:
|
|
student["历史匹配老师"] = ""
|
|
students.append(student)
|
|
|
|
df_students = pd.DataFrame(students)
|
|
df_students.to_excel('学生信息示例.xlsx', index=False)
|
|
print(f"已生成 {student_count} 名学生数据") |