一、系统功能模块解析
1.配置管理模块
# 文件路径配置
input_path = r"C:\...\学生大类分方向志愿表.xls"
output_path = r"C:\...\分班结果.xls"
# 专业方向配置
columns_map = {
"嵌入式与移动开发方向": 4,
"网络技术应用方向": 5,
...
}
# 招生限额配置
direction_quota = {
"嵌入式与移动开发方向": 108,
...
}
-
采用集中式配置管理
-
支持灵活调整输入输出路径
-
方便扩展新专业方向
2.数据处理模块
workbook = xlrd.open_workbook(input_path)
sheet = workbook.sheet_by_index(0)
for row_idx in range(4, sheet.nrows):
stu_id = sheet.cell_value(row_idx, 1)
...
-
使用xlrd库读取Excel数据
-
跳过前4行表头数据
-
按列索引获取学生信息
3.智能分配模块
preferences = {}
for direction, col_idx in columns_map.items():
value = sheet.cell_value(row_idx, col_idx)
...
for priority in sorted(preferences.keys()):
...
-
志愿优先级解析
-
两阶段分配机制:
-
优先志愿分配
-
剩余名额调剂
-
4.结果输出模块
wb = xlwt.Workbook(encoding='utf-8')
ws = wb.add_sheet('分班结果')
headers = ['学号', '姓名', ...]
for col, header in enumerate(headers):
...
-
生成结构化结果文件
-
包含详细分配信息
-
明确标注未分配学生
二、数据可视化分析
1.招生计划完成情况
import matplotlib.pyplot as plt
directions = list(direction_quota.keys())
planned = list(direction_quota.values())
actual = [direction_counts[d] for d in directions]
plt.figure(figsize=(10,6))
x = range(len(directions))
plt.bar(x, planned, width=0.4, label='计划')
plt.bar([i+0.4 for i in x], actual, width=0.4, label='实际')
plt.xticks([i+0.2 for i in x], directions, rotation=45)
plt.title('各方向招生计划完成情况')
plt.legend()
2.学生成绩分布
import seaborn as sns
gpas = [s[4] for s in results]
scores = [s[5] for s in results]
plt.figure(figsize=(12,5))
plt.subplot(1,2,1)
sns.histplot(gpas, bins=20, kde=True)
plt.title('GPA分布')
plt.subplot(1,2,2)
sns.boxplot(x=scores)
plt.title('考核成绩分布')
3.志愿满足情况
fulfilled = len(results) - len(unassigned)
labels = ['志愿满足', '未分配']
sizes = [fulfilled, len(unassigned)]
plt.pie(sizes, labels=labels, autopct='%1.1f%%',
colors=['#66b3ff','#ff9999'])
plt.title('志愿总体满足率')
三、系统优化建议
1.异常数据处理
-
增加志愿有效性验证
-
处理重复学号等异常情况
2.分配算法优化
# 伪代码示例:加权排序算法
def calculate_priority(gpa, score):
return 0.7*gpa + 0.3*score
-
引入综合评分机制
-
增加同分比较规则
3.可视化增强
-
添加交互式数据看板
-
生成PDF格式统计报告
4.系统扩展性
-
支持JSON/YAML配置文件
-
添加数据库支持
四、技术实现要点
关键技术 | 实现方案 |
---|---|
Excel处理 | xlrd/xlwt双库协同 |
数据存储 | 字典嵌套数据结构 |
分配算法 | 优先级队列+循环检测 |
异常处理 | 隐式容错机制 |
性能优化 | 内存一次加载 |