Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.express as px
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import base64
|
6 |
+
|
7 |
+
def generate_values(n):
|
8 |
+
return {"HealthPoints": np.random.randint(50, 100, size=n),
|
9 |
+
"Coins": np.random.randint(10, 50, size=n)}
|
10 |
+
|
11 |
+
def app():
|
12 |
+
st.title("Game Mechanics Treemap Chart")
|
13 |
+
st.write("This app displays a Treemap chart of game mechanics.")
|
14 |
+
|
15 |
+
n = len(game_mechanics := ["Action Queue โฑ๏ธ", "Action Retrieval ๐",
|
16 |
+
"Campaign / Battle Card Driven ๐๏ธ", "Card Play Conflict Resolution ๐ณ๐ค",
|
17 |
+
"Communication Limits ๐", "Cooperative Game ๐ค๐ฅ", "Critical Hits and Failures ๐ฅ๐",
|
18 |
+
"Deck Construction ๐ด๐ ๏ธ", "Grid Movement ๐บ๏ธ", "Hand Management ๐๏ธ๐",
|
19 |
+
"Hexagon Grid ๐ณ", "Legacy Game ๐๐ฎ", "Line of Sight ๐", "Modular Board ๐งฉ",
|
20 |
+
"Once-Per-Game Abilities ๐", "Role Playing ๐ญ", "Scenario / Mission / Campaign Game ๐ฏ",
|
21 |
+
"Simultaneous Action Selection ๐ค๐ค", "Solo / Solitaire Game ๐บ", "Storytelling ๐",
|
22 |
+
"Variable Player Powers ๐ฆธโโ๏ธ๐ฆนโโ๏ธ"])
|
23 |
+
|
24 |
+
values = generate_values(n)
|
25 |
+
data = pd.DataFrame({"category": ["Category 1"] * n, "mechanic": game_mechanics,
|
26 |
+
"value": list(values.values()), "HealthPoints": values["HealthPoints"],
|
27 |
+
"Coins": values["Coins"], "description": ["Description"] * n})
|
28 |
+
data["value"] = data["value"].apply(lambda x: sum(x))
|
29 |
+
|
30 |
+
fig = px.treemap(data, path=["category", "mechanic"], values="value",
|
31 |
+
color="HealthPoints", hover_data=["Coins"])
|
32 |
+
st.plotly_chart(fig)
|
33 |
+
|
34 |
+
csv = data.to_csv(index=False)
|
35 |
+
b64 = base64.b64encode(csv.encode()).decode()
|
36 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="game_mechanics.csv">Download CSV</a>'
|
37 |
+
st.markdown(href, unsafe_allow_html=True)
|
38 |
+
|
39 |
+
if __name__ == '__main__':
|
40 |
+
app()
|