-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizations.py
More file actions
47 lines (39 loc) · 1.34 KB
/
Copy pathvisualizations.py
File metadata and controls
47 lines (39 loc) · 1.34 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
import ast
from collections import defaultdict
import plotly.graph_objects as go
def visualize_genre_distribution_from_bundle(bundle_json_path: str):
"""
Reads bundle_data.json, counts genre frequency across all bundles,
and generates an interactive bar chart using Plotly.
"""
with open(bundle_json_path, "r", encoding="utf-8") as f:
raw_lines = f.readlines()
bundle_data = [ast.literal_eval(line) for line in raw_lines if line.strip().startswith("{")]
bundle_items = []
for bundle in bundle_data:
for item in bundle.get("items", []):
genres = item.get("genre", "").split(", ")
bundle_items.append({
"Game": item.get("item_name", "Unknown Game"),
"Genre": genres
})
genre_count = defaultdict(int)
for item in bundle_items:
for genre in item["Genre"]:
if genre:
genre_count[genre.strip()] += 1
genres = list(genre_count.keys())
counts = list(genre_count.values())
fig = go.Figure(data=[go.Bar(
x=genres,
y=counts,
text=counts,
textposition='auto',
hovertext=genres,
)])
fig.update_layout(
title="\U0001F3AE Genre Frequency in Steam Bundles",
xaxis_title="Genre",
yaxis_title="Number of Games",
)
fig.show()