Spaces:
Sleeping
Sleeping
feat: これどこにcommitされるんだ
Browse files
app.py
CHANGED
@@ -1,4 +1,74 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
saka.csv
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
dan,place,win,draw,lose,win_rate,draw_rate,lose_rate,init_score,rank_up_score
|
2 |
+
10,enton,90,0,-120,0.3506,0.3742,0.2752,3800,7600
|
3 |
+
10,enhan,135,0,-180,0.35,0.38,0.30,3800,7600
|
4 |
+
10,ginton,160,0,-180,0.3636,0.3322,0.3042,3800,7600
|
5 |
+
10,ginhan,240,0,-270,0.3481,0.3754,0.2827,3800,7600
|
6 |
+
7,ginton,160,0,-150,0.35,0.38,0.27,2300,4600
|
7 |
+
8,ginton,160,0,-160,0.35,0.38,0.27,2800,5600
|
8 |
+
9,ginton,160,0,-170,0.35,0.38,0.27,3300,6600
|
9 |
+
7,ginhan,240,0,-225,0.35,0.38,0.27,2300,4600
|
10 |
+
8,ginhan,240,0,-240,0.35,0.38,0.27,2800,5600
|
11 |
+
9,ginhan,240,0,-255,0.35,0.38,0.27,3300,6600
|
12 |
+
7,enton,90,0,-90,0.35,0.38,0.27,2300,4600
|
13 |
+
8,enton,90,0,-100,0.35,0.38,0.27,2800,5600
|
14 |
+
9,enton,90,0,-110,0.35,0.38,0.27,3300,6600
|
15 |
+
7,enhan,135,0,-135,0.35,0.38,0.27,2300,4600
|
16 |
+
8,enhan,135,0,-150,0.35,0.38,0.27,2800,5600
|
17 |
+
9,enhan,135,0,-165,0.35,0.38,0.27,3300,6600
|
sample.py
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|