Skip to content

Commit 22b7f0e

Browse files
committed
修复:同步英雄元数据用于图标显示
1 parent 959ed87 commit 22b7f0e

5 files changed

Lines changed: 33 additions & 4 deletions

File tree

Data_CrawlProcess/champion_stats_sync.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,31 @@ def _champion_meta_by_key() -> dict[str, dict[str, Any]]:
412412
return mapping
413413

414414

415+
@lru_cache(maxsize=1)
416+
def get_tencent_hero_metadata() -> list[dict[str, Any]]:
417+
heroes = []
418+
for hero in _tencent_hero_candidates():
419+
hero_id = hero.get("heroId")
420+
alias = hero.get("alias")
421+
if not hero_id:
422+
continue
423+
heroes.append({
424+
"heroId": hero_id,
425+
"name": hero.get("name") or hero.get("title") or alias or str(hero_id),
426+
"alias": alias or str(hero_id),
427+
"keywords": hero.get("keywords") or ",".join(
428+
str(item)
429+
for item in (hero.get("name"), hero.get("title"), alias, hero_id)
430+
if item
431+
),
432+
"heroLogo": (
433+
_https_url(hero.get("heroLogo"))
434+
or (f"https://game.gtimg.cn/images/lol/act/img/champion/{alias}.png" if alias else None)
435+
),
436+
})
437+
return heroes
438+
439+
415440
@lru_cache(maxsize=1)
416441
def _tencent_rune_lookup() -> dict[str, dict[str, Any]]:
417442
try:

api/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
get_cached_opgg_stats,
2929
get_cached_opgg_region_icon,
3030
get_cached_opgg_role_icon,
31+
get_tencent_hero_metadata,
3132
get_sync_status,
3233
start_champion_stats_scheduler,
3334
sync_opgg_stats,
@@ -743,6 +744,7 @@ def query_cn_win_rate():
743744

744745
payload = {
745746
'data': rows,
747+
'heroes': get_tencent_hero_metadata(),
746748
'source': '101.qq.com',
747749
'tier': tier,
748750
'queue': queue,

frontend/app/champions/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ export default function ChampionsPage() {
10611061
const sourceLabel = selectedRegion.nativeSource
10621062
? '中国 · 101'
10631063
: `${selectedRegion.label} · OP.GG`
1064-
const normalized = normalizeChampions([], positionStats.data || [], {}, source)
1064+
const normalized = normalizeChampions(positionStats.heroes || [], positionStats.data || [], {}, source)
10651065
.map((champion) => ({
10661066
...champion,
10671067
sourceLabel,

frontend/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export default function PredictPage() {
272272
if (!mounted) return
273273

274274
setLaneStats({})
275-
setChampions(normalizeChampions([], championPositionStats.data || [], {}))
275+
setChampions(normalizeChampions(championPositionStats.heroes || [], championPositionStats.data || [], {}))
276276
const normalizedTeams = normalizeTeams(teamPayload.data || [])
277277
setTeams(normalizedTeams)
278278
setTeamsByLeague((state) => ({ ...state, [DEFAULT_LEAGUE]: normalizedTeams }))

frontend/lib/api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ export interface ApiChampionPositionStat {
395395

396396
export interface ApiChampionPositionStatsResponse {
397397
data?: ApiChampionPositionStat[]
398+
heroes?: ApiHero[]
398399
source?: string
399400
region?: string
400401
tier?: string
@@ -726,6 +727,7 @@ export function normalizeChampions(
726727
const statKey = String(stat.key || stat.name || sortIndex)
727728
const officialHero = heroId ? heroById.get(heroId) : undefined
728729
const alias = officialHero?.alias || stat.key || String(heroId)
730+
const fallbackImageUrl = heroId ? `/lol_champion_icon/${heroId}.png` : undefined
729731
const lane = roleToLane[role]
730732
const fallbackWinRate = heroId ? (laneStats[String(heroId)]?.[lane] ?? 0.5) : 0.5
731733
const winRate = Number.isFinite(stat.positionWinRate)
@@ -775,7 +777,7 @@ export function normalizeChampions(
775777
heroId: Number.isFinite(counterHeroId) ? counterHeroId : undefined,
776778
name: officialCounter?.name || counter.name || counter.key || '',
777779
en: officialCounter?.alias || counter.key || String(counterHeroId || ''),
778-
imageUrl: officialCounter?.heroLogo || counter.img_url,
780+
imageUrl: officialCounter?.heroLogo || counter.img_url || (Number.isFinite(counterHeroId) ? `/lol_champion_icon/${counterHeroId}.png` : undefined),
779781
winRate: counterWinRate,
780782
games: Number.isFinite(counterGames) ? counterGames : undefined,
781783
wins: Number.isFinite(counterWins) ? counterWins : undefined,
@@ -792,7 +794,7 @@ export function normalizeChampions(
792794
dataSource: source,
793795
sourceLabel: source === 'cn' ? '中国区 · 101' : '全球 · OP.GG',
794796
role,
795-
imageUrl: officialHero?.heroLogo || stat.image_url,
797+
imageUrl: officialHero?.heroLogo || stat.image_url || fallbackImageUrl,
796798
banRate,
797799
pickRate,
798800
presenceRate,

0 commit comments

Comments
 (0)