-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rating_style.py
More file actions
205 lines (185 loc) · 5.71 KB
/
test_rating_style.py
File metadata and controls
205 lines (185 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
"""
独立测试脚本:只生成 Rating 样式图并打开查看,不依赖 AstrBot。
需要先安装 Pillow: pip install pillow
"""
import os
import sys
import asyncio
# 确保当前目录在 path 中,便于导入 rating_canvas
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from rating_canvas import generate_rating_canvas_image
def _generate_mock_data():
"""生成示例数据用于测试样式"""
profile = {
"userRanking": 1234,
"newPlayerRating": 19032, # 19.032
"newHighestRating": 19500, # 19.500
"playCount": 1234
}
# 示例 B50 数据
b50_items = [
{
"musicId": 1,
"level": 2,
"value": 1008265,
"rating": 19.32,
"chartConstant": 17.0,
"ratingBonus": 2.32,
"musicInfo": {
"id": 1,
"name": "B50 Sample Song 1",
"artistName": "Artist A",
"level0": "7.0",
"level1": "10.0",
"level2": "14.7",
"level3": "15.5",
"level4": ""
}
},
{
"musicId": 2,
"level": 3,
"value": 1004000,
"rating": 19.05,
"chartConstant": 16.5,
"ratingBonus": 2.55,
"musicInfo": {
"id": 2,
"name": "B50 Sample Song 2",
"artistName": "Artist B",
"level0": "7.5",
"level1": "11.0",
"level2": "14.4",
"level3": "15.8",
"level4": ""
}
},
{
"musicId": 3,
"level": 2,
"value": 998000,
"rating": 18.50,
"chartConstant": 16.0,
"ratingBonus": 2.50,
"musicInfo": {
"id": 3,
"name": "B50 Sample Song 3",
"artistName": "Artist C",
"level0": "6.5",
"level1": "9.5",
"level2": "13.8",
"level3": "15.0",
"level4": ""
}
}
]
# 示例 NEW10 数据
new10_items = [
{
"musicId": 4,
"level": 1,
"value": 997000,
"rating": 18.10,
"chartConstant": 15.5,
"ratingBonus": 2.60,
"musicInfo": {
"id": 4,
"name": "NEW10 Sample Song 1",
"artistName": "Artist D",
"level0": "6.0",
"level1": "9.0",
"level2": "12.5",
"level3": "14.0",
"level4": ""
}
}
]
# 示例 PSCORE 数据
pscore_items = [
{
"musicId": 5,
"level": 3,
"value": 1000000,
"rating": 0.135,
"chartConstant": 14.9,
"ratingBonus": -1.5,
"isPScore": True,
"platinumScoreMax": 100000,
"platinumScoreStar": 4,
"musicInfo": {
"id": 5,
"name": "PSCORE Sample Song 1",
"artistName": "Artist E",
"level0": "7.0",
"level1": "10.5",
"level2": "13.5",
"level3": "14.9",
"level4": ""
}
}
]
categories = [
{
"title": "B50",
"description": "BEST 50",
"items": b50_items,
"totalRating": sum(item["rating"] for item in b50_items),
"averageRating": sum(item["rating"] for item in b50_items) / len(b50_items) if b50_items else 0
},
{
"title": "NEW10",
"description": "NEW 10",
"items": new10_items,
"totalRating": sum(item["rating"] for item in new10_items),
"averageRating": sum(item["rating"] for item in new10_items) / len(new10_items) if new10_items else 0
},
{
"title": "PSCORE 50",
"description": "PLATINUM SCORE 50",
"items": pscore_items,
"totalRating": sum(item["rating"] for item in pscore_items),
"averageRating": sum(item["rating"] for item in pscore_items) / len(pscore_items) if pscore_items else 0
}
]
return profile, categories
async def async_main():
"""异步主函数"""
plugin_dir = os.path.dirname(os.path.abspath(__file__))
output_path = os.path.join(plugin_dir, "assets", "nageki_rating.png")
try:
# 生成示例数据
profile, categories = _generate_mock_data()
# 生成图片(不传 api_client,所以不会下载真实图片)
await generate_rating_canvas_image(
output_path,
profile,
categories,
api_client=None
)
print(f"已生成: {output_path}")
# 用系统默认程序打开图片
if sys.platform == "win32":
os.startfile(output_path)
elif sys.platform == "darwin":
import subprocess
subprocess.run(["open", output_path], check=False)
else:
import subprocess
subprocess.run(["xdg-open", output_path], check=False)
except RuntimeError as e:
if "Pillow" in str(e):
print(e)
print("请先安装: pip install pillow")
else:
raise
sys.exit(1)
except Exception as e:
print(f"生成图片时出错: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
def main():
"""主函数入口"""
asyncio.run(async_main())
if __name__ == "__main__":
main()