levena commited on
Commit
4c58395
·
1 Parent(s): e3fb9a3

feat: update

Browse files
Files changed (1) hide show
  1. app.py +20 -74
app.py CHANGED
@@ -1,74 +1,20 @@
1
- import matplotlib.pyplot
2
- import pandas as pd
3
- import os
4
- import random
5
-
6
-
7
- def main():
8
- df = readcsv(10)
9
- if df is not None:
10
- plt = simulate_games(df, num_games=2000)
11
- plt.show()
12
-
13
-
14
- def readcsv(filter: int = 10) -> pd.DataFrame | None:
15
- # CSVファイルの存在確認
16
- csv_file = "saka.csv"
17
- current_dir = os.path.dirname(os.path.abspath(__file__))
18
- csv_path = os.path.join(current_dir, csv_file)
19
- if not os.path.isfile(csv_path):
20
- print(f"Error: {csv_file} does not exist.")
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)