Spaces:
Sleeping
Sleeping
feat: update
Browse files
app.py
CHANGED
@@ -1,74 +1,20 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
return None
|
22 |
-
|
23 |
-
# CSVファイルの読み込み
|
24 |
-
df = pd.read_csv(csv_path)
|
25 |
-
|
26 |
-
filtered_df = df[df.iloc[:, 0] == filter]
|
27 |
-
|
28 |
-
# フィルター後のデータフレームを表示
|
29 |
-
print(filtered_df)
|
30 |
-
return filtered_df
|
31 |
-
|
32 |
-
|
33 |
-
def simulate_games(df, num_games: int = 1000, max_score: int = 20000):
|
34 |
-
results = {}
|
35 |
-
|
36 |
-
for index, row in df.iterrows():
|
37 |
-
place = row["place"]
|
38 |
-
win_score = row["win"]
|
39 |
-
lose_score = row["lose"]
|
40 |
-
draw_score = row["draw"]
|
41 |
-
win_rate = row["win_rate"]
|
42 |
-
lose_rate = row["lose_rate"]
|
43 |
-
draw_rate = row["draw_rate"]
|
44 |
-
init_score = row["init_score"]
|
45 |
-
|
46 |
-
scores = [init_score]
|
47 |
-
for _ in range(num_games):
|
48 |
-
result = random.choices([1, 2, 3], weights=[win_rate, lose_rate, draw_rate])[0]
|
49 |
-
if result == 1:
|
50 |
-
scores.append(scores[-1] + win_score)
|
51 |
-
elif result == 2:
|
52 |
-
scores.append(scores[-1] + lose_score)
|
53 |
-
else:
|
54 |
-
scores.append(scores[-1] + draw_score)
|
55 |
-
|
56 |
-
results[place] = scores
|
57 |
-
df.at[index, "reached_goal"] = any([score >= row["rank_up_score"] for score in scores])
|
58 |
-
df.at[index, "rank_down"] = any([score <= 0 for score in scores])
|
59 |
-
|
60 |
-
matplotlib.pyplot.figure(figsize=(10, 6))
|
61 |
-
for place, scores in results.items():
|
62 |
-
matplotlib.pyplot.plot(range(num_games + 1), scores, label=place)
|
63 |
-
matplotlib.pyplot.axhline(y=df.iloc[0]["init_score"], color="black", linestyle="--", label="initial score")
|
64 |
-
matplotlib.pyplot.axhline(y=df.iloc[0]["rank_up_score"], color="red", linestyle="--", label="goal")
|
65 |
-
matplotlib.pyplot.xlabel("Game")
|
66 |
-
matplotlib.pyplot.ylabel("Score")
|
67 |
-
matplotlib.pyplot.ylim(0, max_score)
|
68 |
-
matplotlib.pyplot.title("Score Transition")
|
69 |
-
matplotlib.pyplot.legend()
|
70 |
-
return matplotlib.pyplot
|
71 |
-
|
72 |
-
|
73 |
-
if __name__ == "__main__":
|
74 |
-
main()
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import sample
|
3 |
+
|
4 |
+
st.set_page_config(layout="wide")
|
5 |
+
st.title("rcity 10dan saka Sampling")
|
6 |
+
|
7 |
+
num_games = st.selectbox("Number of games", [100, 500, 1000, 2000, 3000], index=1)
|
8 |
+
num_dan = st.selectbox("Number of dan", [7, 8, 9, 10], index=3)
|
9 |
+
num_max_pt = st.selectbox("Number of max points", [9000, 10000, 15000, 20000], index=3)
|
10 |
+
if num_games is None or num_dan is None:
|
11 |
+
st.stop()
|
12 |
+
df = sample.readcsv(filter=num_dan)
|
13 |
+
if df is not None:
|
14 |
+
if st.button("再計算") or num_games is not None:
|
15 |
+
col1, col2 = st.columns(2)
|
16 |
+
plt = sample.simulate_games(df, num_games=num_games, max_score=num_max_pt)
|
17 |
+
with col1:
|
18 |
+
st.pyplot(plt)
|
19 |
+
with col2:
|
20 |
+
st.dataframe(df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|