Spaces:
Runtime error
Runtime error
neoai-kterasawa
commited on
Commit
·
7131f8d
1
Parent(s):
e80821f
remove archive
Browse files- archive/app.py +0 -42
- archive/app_gradio.py +0 -39
- archive/app_streamlit.py +0 -28
- archive/utils.py +0 -107
- src/model/{odds.py → choices.py} +0 -0
archive/app.py
DELETED
@@ -1,42 +0,0 @@
|
|
1 |
-
from typing import Any
|
2 |
-
|
3 |
-
import gradio as gr
|
4 |
-
|
5 |
-
from archive.utils import get_calculated_df, get_info, text2oddslist
|
6 |
-
|
7 |
-
DEFAULT_AMOUNT = 5000
|
8 |
-
|
9 |
-
|
10 |
-
def calculate(_amount: Any, _text: Any) -> tuple[str, dict]:
|
11 |
-
amount = int(_amount) or DEFAULT_AMOUNT
|
12 |
-
|
13 |
-
df = get_calculated_df(amount, text2oddslist(str(_text)))
|
14 |
-
info = get_info(df)
|
15 |
-
|
16 |
-
# dfの整形
|
17 |
-
display_cols = ["odds", "buy", "refound"]
|
18 |
-
if df["name"].map(lambda name: name != "").any():
|
19 |
-
display_cols = ["name"] + display_cols
|
20 |
-
|
21 |
-
# markdownの整形
|
22 |
-
md_string = (
|
23 |
-
f"**購入額:** ¥ **{info['sum']:,}**<br>"
|
24 |
-
f"**点数:** **{info['num_kind']}** 点<br>"
|
25 |
-
f"**払戻:** ¥ **{info['refound_mean']:,}** (**{info['profit_mean']:+,}** (**{info['rate_min']:+.0%}**))<br>"
|
26 |
-
"---"
|
27 |
-
)
|
28 |
-
|
29 |
-
return md_string, df[["index"] + display_cols]
|
30 |
-
|
31 |
-
|
32 |
-
amount_input = gr.Number(value=DEFAULT_AMOUNT, label="amount")
|
33 |
-
text_input = gr.Textbox(label="text")
|
34 |
-
markdown_output = gr.Markdown()
|
35 |
-
df_output = gr.Dataframe(type="pandas")
|
36 |
-
iface = gr.Interface(
|
37 |
-
fn=calculate,
|
38 |
-
inputs=[amount_input, text_input],
|
39 |
-
outputs=[markdown_output, df_output],
|
40 |
-
)
|
41 |
-
|
42 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
archive/app_gradio.py
DELETED
@@ -1,39 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from archive.utils import get_calculated_df, get_info, text2oddslist
|
3 |
-
|
4 |
-
DEFAULT_AMOUNT = 5000
|
5 |
-
|
6 |
-
|
7 |
-
def calculate(amount, text):
|
8 |
-
amount = amount or DEFAULT_AMOUNT
|
9 |
-
odds_list = text2oddslist(text)
|
10 |
-
df = get_calculated_df(amount, odds_list)
|
11 |
-
info = get_info(df)
|
12 |
-
|
13 |
-
# dfの整形
|
14 |
-
display_cols = ["odds", "buy", "refound"]
|
15 |
-
if df["name"].map(lambda name: name != "").any():
|
16 |
-
display_cols = ["name"] + display_cols
|
17 |
-
|
18 |
-
# markdownの整形
|
19 |
-
md_string = (
|
20 |
-
f"**購入額:** ¥ **{info['sum']:,}**<br>"
|
21 |
-
f"**点数:** **{info['num_kind']}** 点<br>"
|
22 |
-
f"**払戻:** ¥ **{info['refound_mean']:,}** (**{info['profit_mean']:+,}** (**{info['rate_min']:+.0%}**))<br>"
|
23 |
-
"---"
|
24 |
-
)
|
25 |
-
|
26 |
-
return md_string, df[["index"] + display_cols]
|
27 |
-
|
28 |
-
|
29 |
-
amount_input = gr.Number(value=DEFAULT_AMOUNT, label="amount")
|
30 |
-
text_input = gr.Textbox(label="text")
|
31 |
-
markdown_output = gr.Markdown()
|
32 |
-
df_output = gr.Dataframe(type="pandas")
|
33 |
-
iface = gr.Interface(
|
34 |
-
fn=calculate,
|
35 |
-
inputs=[amount_input, text_input],
|
36 |
-
outputs=[markdown_output, df_output],
|
37 |
-
)
|
38 |
-
|
39 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
archive/app_streamlit.py
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
-
from archive.utils import get_calculated_df, get_info, text2oddslist
|
4 |
-
|
5 |
-
amount: int = int(st.number_input("amount", min_value=100, value=3000, step=100))
|
6 |
-
text: str = st.text_area("text", "")
|
7 |
-
# ボタンを作る
|
8 |
-
st.button("calculate")
|
9 |
-
if text:
|
10 |
-
df = get_calculated_df(amount, text2oddslist(text))
|
11 |
-
# dataframeを綺麗に出力する
|
12 |
-
info = get_info(df)
|
13 |
-
col1, col2 = st.columns(2)
|
14 |
-
with col1:
|
15 |
-
st.markdown(f"#### 購入額: ¥ **{info['sum']:,}**")
|
16 |
-
st.markdown(f"#### 点 数: **{info['num_kind']}** 点")
|
17 |
-
with col2:
|
18 |
-
st.metric(
|
19 |
-
label="払戻",
|
20 |
-
value=f"¥ {info['refound_mean']:,}",
|
21 |
-
delta=f"{info['profit_mean']:+,}({info['rate_min']:.0%})",
|
22 |
-
)
|
23 |
-
st.markdown("---")
|
24 |
-
# dfの表示
|
25 |
-
display_cols = ["odds", "buy", "refound"]
|
26 |
-
if df["name"].map(lambda name: name != "").any():
|
27 |
-
display_cols = ["name"] + display_cols
|
28 |
-
st.dataframe(df[display_cols])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
archive/utils.py
DELETED
@@ -1,107 +0,0 @@
|
|
1 |
-
import math
|
2 |
-
from typing import TypedDict
|
3 |
-
|
4 |
-
import pandas as pd
|
5 |
-
|
6 |
-
|
7 |
-
# Typing -----------------------------------------------------------------------
|
8 |
-
class OddsInfo(TypedDict):
|
9 |
-
index: str
|
10 |
-
name: str
|
11 |
-
odds: float
|
12 |
-
|
13 |
-
|
14 |
-
OdddsList = list[OddsInfo]
|
15 |
-
|
16 |
-
|
17 |
-
class Info(TypedDict):
|
18 |
-
sum: int
|
19 |
-
num_kind: int
|
20 |
-
refound_mean: int
|
21 |
-
profit_mean: int
|
22 |
-
rate_min: float
|
23 |
-
rate_max: float
|
24 |
-
rate_mean: float
|
25 |
-
|
26 |
-
|
27 |
-
# text -> odds_list ------------------------------------------------------------
|
28 |
-
def _text2oddslist_pc(text: str) -> OdddsList:
|
29 |
-
odds_list: OdddsList = []
|
30 |
-
tmp_list: list[str] = []
|
31 |
-
lines: list[str] = text.split("\n")
|
32 |
-
for text in lines:
|
33 |
-
if "." in text:
|
34 |
-
odds_list.append(
|
35 |
-
{
|
36 |
-
"index": "-".join(tmp_list),
|
37 |
-
"name": "",
|
38 |
-
"odds": float(text),
|
39 |
-
}
|
40 |
-
)
|
41 |
-
tmp_list = []
|
42 |
-
else:
|
43 |
-
if text.strip():
|
44 |
-
tmp_list.append(text.strip())
|
45 |
-
return odds_list
|
46 |
-
|
47 |
-
|
48 |
-
def _text2oddslist_mobile(text: str) -> OdddsList:
|
49 |
-
odds_list: OdddsList = []
|
50 |
-
lines: list[str] = text.split("\n")
|
51 |
-
for strat_key in ("選択", "オッズ", "組み合わせ", "オッズを見て個別選択"):
|
52 |
-
if strat_key in lines:
|
53 |
-
lines = lines[lines.index(strat_key) + 1 :]
|
54 |
-
if "すべてを選択" in lines:
|
55 |
-
lines = lines[: lines.index("すべてを選択")]
|
56 |
-
for i in range(len(lines) // 3):
|
57 |
-
# oddsが1つ目にある
|
58 |
-
if "." in lines[3 * i + 1]:
|
59 |
-
idx_odds = 1
|
60 |
-
idx_name = 2
|
61 |
-
else:
|
62 |
-
idx_odds = 2
|
63 |
-
idx_name = 1
|
64 |
-
|
65 |
-
odds_list.append(
|
66 |
-
{
|
67 |
-
"index": "-".join(lines[3 * i].split()),
|
68 |
-
"name": "-".join(lines[3 * i + idx_name].split()),
|
69 |
-
"odds": float(lines[3 * i + idx_odds]),
|
70 |
-
}
|
71 |
-
)
|
72 |
-
return odds_list
|
73 |
-
|
74 |
-
|
75 |
-
def text2oddslist(text: str) -> OdddsList:
|
76 |
-
# pcの時
|
77 |
-
if set("".join(text.split())) <= set("0123456789.-"):
|
78 |
-
odds_list = _text2oddslist_pc(text)
|
79 |
-
# moduleの時
|
80 |
-
else:
|
81 |
-
odds_list = _text2oddslist_mobile(text)
|
82 |
-
return odds_list
|
83 |
-
|
84 |
-
|
85 |
-
# odds_list -> df ---------------------------------------------------------------
|
86 |
-
def get_calculated_df(amount: int, odds_list: OdddsList) -> pd.DataFrame:
|
87 |
-
df = pd.DataFrame(odds_list)
|
88 |
-
df["weight"] = (1 / df["odds"]) / (1 / df["odds"]).sum()
|
89 |
-
df["buy"] = (df["weight"] * amount / 100).map(
|
90 |
-
lambda x: max(math.floor(x) * 100, 100)
|
91 |
-
)
|
92 |
-
df["refound"] = (df["buy"] * df["odds"]).astype(int)
|
93 |
-
df["profit"] = df["refound"] - amount
|
94 |
-
return df
|
95 |
-
|
96 |
-
|
97 |
-
def get_info(df: pd.DataFrame) -> Info:
|
98 |
-
info: Info = {
|
99 |
-
"sum": df["buy"].sum(),
|
100 |
-
"num_kind": df.shape[0],
|
101 |
-
"refound_mean": int(df["refound"].mean()),
|
102 |
-
"profit_mean": int(df["profit"].mean()),
|
103 |
-
"rate_min": df["refound"].min() / df["buy"].sum(),
|
104 |
-
"rate_max": df["refound"].max() / df["buy"].sum(),
|
105 |
-
"rate_mean": df["refound"].mean() / df["buy"].sum(),
|
106 |
-
}
|
107 |
-
return info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/model/{odds.py → choices.py}
RENAMED
File without changes
|