46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
|
|||
|
|
import re
|
|||
|
|
|
|||
|
|
def sync_dashboard_ranking_with_profile():
|
|||
|
|
"""同步Dashboard页面的排名数据与个人档案页面的数据"""
|
|||
|
|
|
|||
|
|
print("同步Dashboard页面的排名数据...")
|
|||
|
|
|
|||
|
|
# 读取mockData.js文件
|
|||
|
|
with open('src/data/mockData.js', 'r', encoding='utf-8') as f:
|
|||
|
|
content = f.read()
|
|||
|
|
|
|||
|
|
# 查找profileOverview.ranking.rankings数据(土木水利数据)
|
|||
|
|
profile_pattern = r'mockData\.profileOverview = \{[\s\S]*?"ranking": \{[\s\S]*?"rankings": \[([\s\S]*?)\]\s*\}\s*\};'
|
|||
|
|
profile_match = re.search(profile_pattern, content)
|
|||
|
|
|
|||
|
|
if not profile_match:
|
|||
|
|
print("❌ 无法找到profileOverview的rankings数据")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
# 提取土木水利的rankings数据
|
|||
|
|
civil_rankings_data = profile_match.group(1)
|
|||
|
|
|
|||
|
|
# 准备替换Dashboard的topStudents数据
|
|||
|
|
# 需要将前10名数据用于topStudents
|
|||
|
|
dashboard_pattern = r'(ranking: \{\s*myRank: \{[\s\S]*?\},\s*topStudents: \[)([\s\S]*?)(\],)'
|
|||
|
|
|
|||
|
|
# 执行替换
|
|||
|
|
content = re.sub(
|
|||
|
|
dashboard_pattern,
|
|||
|
|
r'\1' + civil_rankings_data + r'\3',
|
|||
|
|
content
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# 保存更新后的文件
|
|||
|
|
with open('src/data/mockData.js', 'w', encoding='utf-8') as f:
|
|||
|
|
f.write(content)
|
|||
|
|
|
|||
|
|
print("✅ Dashboard页面的topStudents数据已同步为土木水利数据")
|
|||
|
|
print("📋 数据来源:profileOverview.ranking.rankings")
|
|||
|
|
print("📍 更新位置:mockData.dashboardStatistics.ranking.topStudents")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
sync_dashboard_ranking_with_profile()
|