151 lines
8.7 KiB
Python
151 lines
8.7 KiB
Python
from datetime import datetime
|
|||
|
|
from sqlalchemy.orm import Session
|
||
|
|
from database import engine, SessionLocal
|
||
|
|
from models import Base, Teacher, Class, Student, Score, Employment
|
||
|
|
|
||
|
|
def init_db():
|
||
|
|
Base.metadata.create_all(bind=engine)
|
||
|
|
|
||
|
|
|
||
|
|
def seed_data(db: Session):
|
||
|
|
"""Insert sample data if empty"""
|
||
|
|
if db.query(Teacher).count() > 0:
|
||
|
|
return
|
||
|
|
|
||
|
|
teachers = [
|
||
|
|
Teacher(num='T001', name='张伟', age=35, sex=1, home_place='北京', college='清华大学',
|
||
|
|
specialty='计算机科学与技术', enrollment_time=datetime(2008, 9, 1),
|
||
|
|
graduate_time=datetime(2012, 6, 30), education='本科',
|
||
|
|
work_experience='10年Java教学经验', coach_area='应用'),
|
||
|
|
Teacher(num='T002', name='李娜', age=32, sex=2, home_place='上海', college='复旦大学',
|
||
|
|
specialty='软件工程', enrollment_time=datetime(2010, 9, 1),
|
||
|
|
graduate_time=datetime(2014, 6, 30), education='硕士',
|
||
|
|
work_experience='8年前端教学经验', coach_area='项目'),
|
||
|
|
Teacher(num='T003', name='王强', age=40, sex=1, home_place='广州', college='中山大学',
|
||
|
|
specialty='人工智能', enrollment_time=datetime(2004, 9, 1),
|
||
|
|
graduate_time=datetime(2008, 6, 30), education='博士',
|
||
|
|
work_experience='12年算法教学经验', coach_area='算法'),
|
||
|
|
Teacher(num='T004', name='赵敏', age=28, sex=2, home_place='深圳', college='浙江大学',
|
||
|
|
specialty='数据科学', enrollment_time=datetime(2014, 9, 1),
|
||
|
|
graduate_time=datetime(2018, 6, 30), education='硕士',
|
||
|
|
work_experience='5年Python教学经验', coach_area='应用'),
|
||
|
|
Teacher(num='T005', name='陈刚', age=38, sex=1, home_place='成都', college='电子科技大学',
|
||
|
|
specialty='通信工程', enrollment_time=datetime(2006, 9, 1),
|
||
|
|
graduate_time=datetime(2010, 6, 30), education='本科',
|
||
|
|
work_experience='11年嵌入式教学经验', coach_area='项目'),
|
||
|
|
]
|
||
|
|
db.add_all(teachers)
|
||
|
|
db.commit()
|
||
|
|
for t in teachers:
|
||
|
|
db.refresh(t)
|
||
|
|
|
||
|
|
classes = [
|
||
|
|
Class(num='C2024001', name='C2024001', class_start_time=datetime(2024, 3, 1),
|
||
|
|
head_teacher_id=1, coach_teacher_id=2, tutor_teacher_id=4),
|
||
|
|
Class(num='C2024002', name='C2024001', class_start_time=datetime(2024, 4, 1),
|
||
|
|
head_teacher_id=2, coach_teacher_id=3, tutor_teacher_id=5),
|
||
|
|
Class(num='C2024003', name='C2024003', class_start_time=datetime(2024, 5, 1),
|
||
|
|
head_teacher_id=3, coach_teacher_id=1, tutor_teacher_id=4),
|
||
|
|
]
|
||
|
|
db.add_all(classes)
|
||
|
|
db.commit()
|
||
|
|
for c in classes:
|
||
|
|
db.refresh(c)
|
||
|
|
|
||
|
|
students = [
|
||
|
|
Student(num='S2024001', name='刘洋', age=22, sex=1, home_place='北京',
|
||
|
|
college='北京大学', specialty='计算机科学与技术',
|
||
|
|
enrollment_time=datetime(2020, 9, 1), graduate_time=datetime(2024, 6, 30),
|
||
|
|
education='本科', class_id=1, advisor_id=1),
|
||
|
|
Student(num='S2024002', name='孙丽', age=23, sex=2, home_place='上海',
|
||
|
|
college='上海交通大学', specialty='软件工程',
|
||
|
|
enrollment_time=datetime(2019, 9, 1), graduate_time=datetime(2023, 6, 30),
|
||
|
|
education='本科', class_id=1, advisor_id=1),
|
||
|
|
Student(num='S2024003', name='周杰', age=24, sex=1, home_place='广州',
|
||
|
|
college='华南理工大学', specialty='人工智能',
|
||
|
|
enrollment_time=datetime(2018, 9, 1), graduate_time=datetime(2022, 6, 30),
|
||
|
|
education='硕士', class_id=1, advisor_id=2),
|
||
|
|
Student(num='S2024004', name='吴敏', age=21, sex=2, home_place='深圳',
|
||
|
|
college='深圳大学', specialty='数据科学',
|
||
|
|
enrollment_time=datetime(2021, 9, 1), graduate_time=datetime(2025, 6, 30),
|
||
|
|
education='本科', class_id=2, advisor_id=3),
|
||
|
|
Student(num='S2024005', name='郑浩', age=25, sex=1, home_place='成都',
|
||
|
|
college='四川大学', specialty='通信工程',
|
||
|
|
enrollment_time=datetime(2017, 9, 1), graduate_time=datetime(2021, 6, 30),
|
||
|
|
education='本科', class_id=2, advisor_id=4),
|
||
|
|
Student(num='S2024006', name='冯雪', age=22, sex=2, home_place='杭州',
|
||
|
|
college='浙江大学', specialty='计算机科学与技术',
|
||
|
|
enrollment_time=datetime(2020, 9, 1), graduate_time=datetime(2024, 6, 30),
|
||
|
|
education='本科', class_id=2, advisor_id=5),
|
||
|
|
Student(num='S2024007', name='黄磊', age=23, sex=1, home_place='南京',
|
||
|
|
college='南京大学', specialty='软件工程',
|
||
|
|
enrollment_time=datetime(2019, 9, 1), graduate_time=datetime(2023, 6, 30),
|
||
|
|
education='本科', class_id=3, advisor_id=1),
|
||
|
|
Student(num='S2024008', name='徐婷', age=24, sex=2, home_place='武汉',
|
||
|
|
college='武汉大学', specialty='人工智能',
|
||
|
|
enrollment_time=datetime(2018, 9, 1), graduate_time=datetime(2022, 6, 30),
|
||
|
|
education='硕士', class_id=3, advisor_id=2),
|
||
|
|
Student(num='S2024009', name='马超', age=21, sex=1, home_place='西安',
|
||
|
|
college='西安交通大学', specialty='数据科学',
|
||
|
|
enrollment_time=datetime(2021, 9, 1), graduate_time=datetime(2025, 6, 30),
|
||
|
|
education='本科', class_id=3, advisor_id=3),
|
||
|
|
Student(num='S2024010', name='朱琳', age=22, sex=2, home_place='天津',
|
||
|
|
college='南开大学', specialty='通信工程',
|
||
|
|
enrollment_time=datetime(2020, 9, 1), graduate_time=datetime(2024, 6, 30),
|
||
|
|
education='本科', class_id=3, advisor_id=4),
|
||
|
|
Student(num='S2026001', name='牧遥', age=22, sex=1, home_place='北京',
|
||
|
|
college='北京大学', specialty='计算机科学与技术',
|
||
|
|
enrollment_time=datetime(2020, 9, 1), graduate_time=datetime(2024, 6, 30),
|
||
|
|
education='本科', class_id=1, advisor_id=1),
|
||
|
|
]
|
||
|
|
db.add_all(students)
|
||
|
|
db.commit()
|
||
|
|
for s in students:
|
||
|
|
db.refresh(s)
|
||
|
|
|
||
|
|
score_data = [
|
||
|
|
# 刘洋 (id=1)
|
||
|
|
(1, '第一次考核', 85.50), (1, '第二次考核', 90.00), (1, '第三次考核', 88.00),
|
||
|
|
# 孙丽 (id=2)
|
||
|
|
(2, '第一次考核', 92.00), (2, '第二次考核', 87.50), (2, '第三次考核', 91.00),
|
||
|
|
# 周杰 (id=3)
|
||
|
|
(3, '第一次考核', 78.00), (3, '第二次考核', 82.50), (3, '第三次考核', 80.00),
|
||
|
|
# 吴敏 (id=4)
|
||
|
|
(4, '第一次考核', 95.00), (4, '第二次考核', 93.50), (4, '第三次考核', 96.00),
|
||
|
|
# 郑浩 (id=5)
|
||
|
|
(5, '第一次考核', 70.00), (5, '第二次考核', 75.50), (5, '第三次考核', 72.00),
|
||
|
|
# 冯雪 (id=6)
|
||
|
|
(6, '第一次考核', 88.00), (6, '第二次考核', 90.50), (6, '第三次考核', 89.00),
|
||
|
|
# 黄磊 (id=7)
|
||
|
|
(7, '第一次考核', 82.00), (7, '第二次考核', 85.00), (7, '第三次考核', 83.50),
|
||
|
|
# 徐婷 (id=8)
|
||
|
|
(8, '第一次考核', 91.00), (8, '第二次考核', 94.00), (8, '第三次考核', 92.50),
|
||
|
|
# 马超 (id=9)
|
||
|
|
(9, '第一次考核', 76.00), (9, '第二次考核', 79.50), (9, '第三次考核', 77.00),
|
||
|
|
# 朱琳 (id=10)
|
||
|
|
(10, '第一次考核', 89.00), (10, '第二次考核', 86.50), (10, '第三次考核', 90.00),
|
||
|
|
# 牧遥 (id=11) - 有不及格
|
||
|
|
(11, '第一次考核', 56.50), (11, '第二次考核', 30.00), (11, '第三次考核', 88.00),
|
||
|
|
]
|
||
|
|
for sid, num, score in score_data:
|
||
|
|
db.add(Score(sid=sid, num=num, score=score))
|
||
|
|
db.commit()
|
||
|
|
|
||
|
|
employment_data = [
|
||
|
|
(1, 1, datetime(2024, 6, 1), datetime(2024, 7, 15), '字节跳动', 25000.00),
|
||
|
|
(2, 1, datetime(2024, 6, 1), datetime(2024, 7, 20), '腾讯', 28000.00),
|
||
|
|
(3, 1, datetime(2024, 6, 1), datetime(2024, 8, 1), '阿里巴巴', 30000.00),
|
||
|
|
(4, 2, datetime(2024, 7, 1), datetime(2024, 8, 10), '美团', 24000.00),
|
||
|
|
(5, 2, datetime(2024, 7, 1), None, None, None),
|
||
|
|
(6, 2, datetime(2024, 7, 1), datetime(2024, 8, 15), '京东', 26000.00),
|
||
|
|
(7, 3, datetime(2024, 8, 1), datetime(2024, 9, 5), '百度', 27000.00),
|
||
|
|
(8, 3, datetime(2024, 8, 1), datetime(2024, 9, 10), '华为', 32000.00),
|
||
|
|
(9, 3, datetime(2024, 8, 1), None, None, None),
|
||
|
|
(10, 3, datetime(2024, 8, 1), datetime(2024, 9, 20), '小米', 23000.00),
|
||
|
|
]
|
||
|
|
for sid, cid, open_time, offer_time, company, salary in employment_data:
|
||
|
|
db.add(Employment(sid=sid, class_id=cid, employment_open_time=open_time,
|
||
|
|
offer_recived_time=offer_time, employment_company=company,
|
||
|
|
employment_salary=salary))
|
||
|
|
db.commit()
|