主要内容: - 包含12个产业的完整教务系统前端代码 - 智能启动脚本 (start-industry.sh) - 可视化产业导航页面 (index.html) - 项目文档 (README.md) 优化内容: - 删除所有node_modules和.yoyo文件夹,从7.5GB减少到2.7GB - 添加.gitignore文件避免上传不必要的文件 - 自动依赖管理和智能启动系统 产业列表: 1. 文旅产业 (5150) 2. 智能制造 (5151) 3. 智能开发 (5152) 4. 财经商贸 (5153) 5. 视觉设计 (5154) 6. 交通物流 (5155) 7. 大健康 (5156) 8. 土木水利 (5157) 9. 食品产业 (5158) 10. 化工产业 (5159) 11. 能源产业 (5160) 12. 环保产业 (5161) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
108 lines
4.5 KiB
Python
108 lines
4.5 KiB
Python
#!/usr/bin/env python3
|
||
"""补充完整的智能制造班级排名数据(10名学生)"""
|
||
|
||
import json
|
||
import re
|
||
from datetime import datetime
|
||
|
||
def load_manufacturing_data():
|
||
"""加载智能制造个人档案数据"""
|
||
with open('网页未导入数据/智能制造产业/智能制造个人档案.json', 'r', encoding='utf-8') as f:
|
||
return json.load(f)
|
||
|
||
def load_avatar_list():
|
||
"""加载头像列表"""
|
||
with open('网页未导入数据/头像列表.json', 'r', encoding='utf-8') as f:
|
||
avatars = json.load(f)
|
||
avatar_urls = []
|
||
for avatar in avatars[:20]:
|
||
url = avatar['file_url']
|
||
base_url = url.split('?')[0] if '?' in url else url
|
||
avatar_urls.append(base_url)
|
||
return avatar_urls
|
||
|
||
def transform_to_top_students(manufacturing_data, avatar_urls):
|
||
"""转换为完整的topStudents格式(10名学生)"""
|
||
top_students = []
|
||
|
||
for idx, student in enumerate(manufacturing_data[:10]): # 取前10名
|
||
top_student = {
|
||
"rank": int(student["班级排名"]),
|
||
"studentId": student["学号"],
|
||
"studentName": student["学员名称"],
|
||
"name": student["学员名称"],
|
||
"avatar": avatar_urls[idx % len(avatar_urls)],
|
||
"score": int(student["学分"]),
|
||
"credits": int(student["学分"]),
|
||
"school": student["学校名称"],
|
||
"major": student["专业名称"],
|
||
"isMe": idx == 1 # 第2名(王强)是当前用户
|
||
}
|
||
top_students.append(top_student)
|
||
|
||
return top_students
|
||
|
||
def update_dashboard_statistics():
|
||
"""更新mockData.js中的dashboardStatistics.ranking部分为完整的10名学生"""
|
||
# 加载数据
|
||
manufacturing_data = load_manufacturing_data()
|
||
avatar_urls = load_avatar_list()
|
||
|
||
# 读取现有文件
|
||
with open('src/data/mockData.js', 'r', encoding='utf-8') as f:
|
||
content = f.read()
|
||
|
||
# 备份
|
||
backup_time = datetime.now().strftime('%Y%m%d_%H%M%S')
|
||
with open(f'src/data/mockData.js.backup_{backup_time}_complete', 'w', encoding='utf-8') as f:
|
||
f.write(content)
|
||
|
||
# 生成完整的10名学生的topStudents数据
|
||
top_students = transform_to_top_students(manufacturing_data, avatar_urls)
|
||
|
||
# 转换为JavaScript格式
|
||
top_students_str = json.dumps(top_students, ensure_ascii=False, indent=6)
|
||
# 去掉属性名的引号
|
||
top_students_str = re.sub(r'"(\w+)":', r'\1:', top_students_str)
|
||
|
||
# 替换dashboardStatistics.ranking.topStudents
|
||
# 使用更精确的模式匹配,确保替换整个数组
|
||
pattern = r'(dashboardStatistics[^}]*?ranking:\s*{[^}]*?topStudents:\s*\[)[^\]]*(\],)'
|
||
|
||
def replace_dashboard_top_students(match):
|
||
return match.group(1) + '\n' + top_students_str + '\n ' + match.group(2)
|
||
|
||
content = re.sub(pattern, replace_dashboard_top_students, content, flags=re.DOTALL)
|
||
|
||
# 更新myRank为王强(第2名)的数据
|
||
current_student = manufacturing_data[1] # 第2名 王强
|
||
|
||
# 更新dashboardStatistics.ranking.myRank
|
||
pattern = r'(dashboardStatistics[^}]*?ranking:\s*{[^}]*?myRank:\s*{[^}]*?)rank:\s*\d+'
|
||
content = re.sub(pattern, rf'\1rank: 2', content, flags=re.DOTALL)
|
||
|
||
pattern = r'(dashboardStatistics[^}]*?ranking:\s*{[^}]*?myRank:\s*{[^}]*?)score:\s*\d+'
|
||
if 'score:' not in content:
|
||
# 如果没有score字段,在rank后添加
|
||
pattern = r'(dashboardStatistics[^}]*?ranking:\s*{[^}]*?myRank:\s*{[^}]*?rank:\s*\d+,)'
|
||
content = re.sub(pattern, rf'\1\n score: {current_student["学分"]},', content, flags=re.DOTALL)
|
||
else:
|
||
content = re.sub(pattern, rf'\1score: {current_student["学分"]}', content, flags=re.DOTALL)
|
||
|
||
# 写回文件
|
||
with open('src/data/mockData.js', 'w', encoding='utf-8') as f:
|
||
f.write(content)
|
||
|
||
print(f"✅ 已更新 dashboardStatistics.ranking 为完整的智能制造数据")
|
||
print(f" - topStudents: {len(top_students)} 条数据")
|
||
print(f" - 当前用户: {current_student['学员名称']} (第{current_student['班级排名']}名)")
|
||
print(f" - 备份文件: mockData.js.backup_{backup_time}_complete")
|
||
print("\n学生列表:")
|
||
for student in top_students:
|
||
me_flag = " (当前用户)" if student["isMe"] else ""
|
||
print(f" {student['rank']}. {student['name']} - {student['score']}分{me_flag}")
|
||
|
||
if __name__ == "__main__":
|
||
print("🚀 开始补充完整的智能制造班级排名数据...")
|
||
update_dashboard_statistics()
|
||
print("🎉 完成!") |