Skip to content

Commit cc7cad7

Browse files
Add platform game_count and use in UI
Compute and store a game_count field for each platform in src/update_db.py (defaults to 0 when no games) and rewrite platforms/all.json with the counts. Update gh-pages-template/assets/js/item_loader.js to read and display sorted[item]['game_count'] instead of deriving the count from the games array. This ensures the frontend uses the precomputed count when rendering platform cards.
1 parent b72bf66 commit cc7cad7

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

gh-pages-template/assets/js/item_loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ $(document).ready(function(){
205205
card_body.appendChild(igdb_link)
206206

207207
// game count
208-
if (sorted[item]['games'] && sorted[item]['games'].length > 0) {
208+
if (sorted[item]['game_count'] !== undefined && sorted[item]['game_count'] > 0) {
209209
let game_count = document.createElement("div")
210210
game_count.className = "small text-muted mb-2"
211-
game_count.textContent = `${sorted[item]['games'].length} game${sorted[item]['games'].length === 1 ? '' : 's'}`
211+
game_count.textContent = `${sorted[item]['game_count']} game${sorted[item]['game_count'] === 1 ? '' : 's'}`
212212
card_body.appendChild(game_count)
213213
}
214214

src/update_db.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,20 @@ def get_data():
312312
else:
313313
full_dict[end_point][item_id_dest][item_type][-1][field] = field_value
314314

315+
# Add game counts to platforms for the all.json file
316+
print('calculating game counts for platforms')
317+
for platform_id, platform_data in full_dict['platforms'].items():
318+
try:
319+
games = platform_data['games']
320+
platform_data['game_count'] = len(games)
321+
except KeyError:
322+
# no games for this platform
323+
platform_data['game_count'] = 0
324+
325+
# Rewrite platforms/all.json with game counts
326+
file_path = os.path.join(args.out_dir, 'platforms', 'all')
327+
write_json_files(file_path=file_path, data=full_dict['platforms'])
328+
315329
# create buckets and get list of all videos
316330
print('creating buckets / collecting video ids')
317331
buckets = {}

0 commit comments

Comments
 (0)