Files
online_sys/frontend_大健康/update_health_ranking.py
KQL a7242f0c69 Initial commit: 教务系统在线平台
- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸
- 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB
- 配置完善的.gitignore文件

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 18:16:55 +08:00

83 lines
3.5 KiB
Python
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
# 读取大健康个人档案数据
with open('网页未导入数据/大健康产业/大健康个人档案.json', 'r', encoding='utf-8') as f:
health_profiles = json.load(f)
# 读取头像列表
with open('网页未导入数据/头像列表.json', 'r', encoding='utf-8') as f:
avatar_list = json.load(f)
# 头像映射(根据学生名称)
avatar_map = {
"于语涵": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/f1dcfee97ade582e97c666ebae40563f.jpg",
"陈沐谦": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/d96aef8e47c87f01ac15e6ca51643e38.jpg",
"魏思涵": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/9c8e2aa5e1f0aad6c3e528f088c9e1f0.jpg",
"沈思宁": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/c825e86e5c2e03f43c38ee1f37f9e925.jpg",
"鲁嘉树": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/2b1e3f5beebf23bb0b949c38e2ea85e1.jpg",
"奚沐辰": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/67c67c0c8a1b4f95cf03ffa5fe12e0f1.jpg",
"何泽": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/152361c6c68a193660cdbdf9074c2cf3.jpg",
"杜思妍": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/d1ac60e4c1bb21e0f93a479e8c19e5f0.jpg",
"张予安": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/c3e7c3c0f1d3e4c9bde1f1e8e9c4f9e0.jpg",
"马哲宇": "https://ddcz-1315997005.cos.ap-nanjing.myqcloud.com/static/avatar/douyin/e9f1c4e8e9c4f9e0f1e8e9c4c3e7c3c0.jpg"
}
# 构建班级排名数据
rankings = []
for profile in health_profiles:
name = profile['学员名称'].rstrip('') # 去除特殊字符
rankings.append({
"rank": int(profile['班级排名']),
"studentId": profile['学号'],
"studentName": name,
"name": name,
"avatar": avatar_map.get(name, avatar_list[int(profile['班级排名']) - 1] if int(profile['班级排名']) <= len(avatar_list) else ""),
"score": int(profile['学分']),
"credits": int(profile['学分']),
"school": profile['学校名称'],
"major": profile['专业名称'],
"isMe": name == "何泽" # 何泽是当前用户
})
# 按排名排序
rankings.sort(key=lambda x: x['rank'])
# 构建完整的ranking对象
ranking_data = {
"myRank": {
"rank": 7, # 何泽排名第7
"score": 94,
"totalStudents": 10,
"trend": "stable",
"change": 0
},
"classInfo": {
"className": "大健康班",
"totalStudents": 10,
"averageScore": 94.9 # (98+98+96+96+95+95+94+93+93+90)/10
},
"rankings": rankings
}
# 读取mockData.js文件
with open('src/data/mockData.js', 'r', encoding='utf-8') as f:
content = f.read()
# 查找并替换ranking部分在profileOverview中
import re
# 找到profileOverview的ranking部分
pattern = r'(mockData\.profileOverview = \{[\s\S]*?ranking: )\{[\s\S]*?\n \},\n( // |\s+\w+:)'
replacement = r'\1' + json.dumps(ranking_data, ensure_ascii=False, indent=6).replace('\n', '\n ') + ',\n\\2'
content = re.sub(pattern, replacement, content)
# 写回文件
with open('src/data/mockData.js', 'w', encoding='utf-8') as f:
f.write(content)
print("✅ 成功更新班级排名数据为大健康产业数据")
print(f"✅ 共更新 {len(rankings)} 个学生的排名信息")