コード例 #1
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def raceresult_set_race_list_option(date):
    race_df = GetData.get_race_data(date, date)
    bet_df = GetData.get_bet_data(date,
                                  date).groupby("競走コード").sum().reset_index()
    if len(bet_df.index) != 0:
        race_df = pd.merge(race_df, bet_df, on="競走コード", how="left")
        race_df.loc[:, "投票チェック"] = race_df.apply(lambda x: "[的中]"
                                                 if x["結果"] > 0 else
                                                 ("[外れ]"
                                                  if x["金額"] > 0 else ""),
                                                 axis=1)
    else:
        race_df["投票チェック"] = ""
    ba_list_df = race_df[race_df["月日"] == date][[
        "場名", "競走番号", "競走コード", "競走名略称", "投票フラグ", "投票チェック"
    ]]
    ba_list_df.loc[:, "競走名"] = ba_list_df["投票チェック"] + ba_list_df[
        "場名"] + "_" + ba_list_df["競走番号"].astype(
            str) + "R_" + ba_list_df["競走名略称"]
    ba_list_df = ba_list_df[["競走名", "競走コード"]].rename(columns={
        "競走名": "label",
        "競走コード": "value"
    })
    ba_list = ba_list_df.drop_duplicates().to_dict(orient='record')
    return ba_list
コード例 #2
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def return_analytics_render_return_analytics(start_date, end_date):
    if start_date != None and end_date != None:
        raceuma_df = GetData.get_raceuma_data(start_date, end_date)
        bet_df = GetData.get_bet_data(start_date, end_date)
        haraimodoshi_dict = GetData.get_haraimodoshi_dict(start_date, end_date)
        if len(raceuma_df.index) != 0 and len(
                bet_df.index) != 0 and len(haraimodoshi_dict):
            return p2.return_analytics_render(raceuma_df, bet_df,
                                              haraimodoshi_dict)
        else:
            return html.P(
                f"raceuma_df: {len(raceuma_df.index)} , bet_df: {len(bet_df.index)}, haraimodoshi_dict: {len(haraimodoshi_dict)}"
            )
    else:
        return html.P("not loading data")
コード例 #3
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def raceinfo_set_keibajo_list_option(date):
    race_df = GetData.get_race_data(date, date)
    ba_list_df = race_df[race_df["月日"] == date][[
        "場名"
    ]].rename(columns={"場名": "label"})
    ba_list_df.loc[:, "value"] = ba_list_df["label"]
    ba_list = ba_list_df.drop_duplicates().to_dict(orient='record')
    return ba_list
コード例 #4
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def toppage_render_top_dashboard(start_date, end_date):
    if start_date != None and end_date != None:
        race_df = GetData.get_race_data(start_date,
                                        end_date).query("データ区分 == '7'")
        raceuma_df = GetData.get_raceuma_data(start_date,
                                              end_date).query("データ区分 == '7'")
        bet_df = GetData.get_bet_data(start_date, end_date)
        haraimodoshi_dict = GetData.get_haraimodoshi_dict(start_date, end_date)
        if len(race_df.index) != 0 and len(raceuma_df.index) != 0 and len(
                bet_df.index) != 0 and len(haraimodoshi_dict):
            return p1.toppage_render(race_df, raceuma_df, bet_df,
                                     haraimodoshi_dict)
        else:
            return html.P(
                f"race_df: {len(race_df.index)} raceuma_df: {len(raceuma_df.index)} , bet_df: {len(bet_df.index)}, haraimodoshi_dict: {len(haraimodoshi_dict)}"
            )
    else:
        return html.P("not loading data")
コード例 #5
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def kpi_analytics_render_return_analytics(start_date, end_date):
    if start_date != None and end_date != None:
        race_df = GetData.get_race_data(start_date,
                                        end_date).query("データ区分 == '7'")
        raceuma_df = GetData.get_raceuma_data(start_date,
                                              end_date).query("データ区分 == '7'")
        bet_df = GetData.get_bet_data(start_date, end_date)
        haraimodoshi_dict = GetData.get_haraimodoshi_dict(start_date, end_date)
        if len(race_df.index) != 0 and len(raceuma_df.index) != 0 and len(
                bet_df.index) != 0 and len(haraimodoshi_dict):
            return p3.kpi_analytics_render(race_df, raceuma_df, bet_df,
                                           haraimodoshi_dict, end_date)
        else:
            return html.P(
                f"race_df: {len(race_df.index)} raceuma_df: {len(raceuma_df.index)} , bet_df: {len(bet_df.index)}, haraimodoshi_dict: {len(haraimodoshi_dict)}"
            )
    else:
        return html.P("not loading data")
コード例 #6
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def raceinfo_render_raceuma_detail(race_id, umaban, date):
    if type(umaban) == int:
        raceuma_df = GetData.get_raceuma_data(date, date)
        this_raceuma_df = raceuma_df[raceuma_df["競走コード"] == race_id]
        shap_df_win = cd.get_shap_raceuma_df(race_id, this_raceuma_df, umaban,
                                             date, "WIN_FLAG")
        shap_df_jiku = cd.get_shap_raceuma_df(race_id, this_raceuma_df, umaban,
                                              date, "JIKU_FLAG")
        shap_df_are = cd.get_shap_raceuma_df(race_id, this_raceuma_df, umaban,
                                             date, "ANA_FLAG")
        return p5.raceuma_info_render(shap_df_win, shap_df_jiku, shap_df_are)
コード例 #7
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def raceinfo_render_race_detail(race_id, date):
    if type(race_id) == int:
        race_df = GetData.get_race_data(date, date)
        raceuma_df = GetData.get_raceuma_data(date, date)
        this_race_df = race_df[race_df["競走コード"] == race_id]
        this_raceuma_df = raceuma_df[raceuma_df["競走コード"] == race_id]
        if len(this_race_df.index) != 0 and len(this_raceuma_df.index) != 0:
            shap_df_umaren_are = cd.get_shap_race_df(race_id, this_race_df,
                                                     date, "UMAREN_ARE")
            shap_df_umatan_are = cd.get_shap_race_df(race_id, this_race_df,
                                                     date, "UMATAN_ARE")
            shap_df_sanrenpuku_are = cd.get_shap_race_df(
                race_id, this_race_df, date, "SANRENPUKU_ARE")
            return p5.race_info_render(this_race_df, this_raceuma_df,
                                       shap_df_umaren_are, shap_df_umatan_are,
                                       shap_df_sanrenpuku_are)
        else:
            return html.P(
                f"this_race_df: {len(this_race_df.index)} this_raceuma_df: {len(this_raceuma_df.index)}"
            )
    else:
        return html.P("not loading data")
コード例 #8
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def raceinfo_set_raceid_list_option(ba_name, date):
    if type(ba_name) == str:
        race_df = GetData.get_race_data(date, date)
        race_list_df = race_df[race_df["場名"] == ba_name][[
            "競走コード", "競走番号"
        ]].rename(columns={
            "競走番号": "label",
            "競走コード": "value"
        })
        race_list = race_list_df.drop_duplicates().to_dict(orient='record')
    else:
        race_list = []
    return race_list
コード例 #9
0
ファイル: app.py プロジェクト: ikem55/HRdashboard
def raceresult_render_race_detail(race_id, date):
    if type(race_id) == int:
        race_df = GetData.get_race_data(date, date)
        raceuma_df = GetData.get_raceuma_data(date, date)
        haraimodoshi_dict = GetData.get_haraimodoshi_dict(date, date)
        bet_df = GetData.get_bet_data(date, date)
        this_tansho_df = haraimodoshi_dict["tansho_df"].query(
            f"競走コード == {race_id}")
        this_fukusho_df = haraimodoshi_dict["fukusho_df"].query(
            f"競走コード == {race_id}")
        this_umaren_df = haraimodoshi_dict["umaren_df"].query(
            f"競走コード == {race_id}")
        this_umatan_df = haraimodoshi_dict["umatan_df"].query(
            f"競走コード == {race_id}")
        this_wide_df = haraimodoshi_dict["wide_df"].query(
            f"競走コード == {race_id}")
        this_sanrenpuku_df = haraimodoshi_dict["sanrenpuku_df"].query(
            f"競走コード == {race_id}")
        this_race_df = race_df[race_df["競走コード"] == race_id]
        this_raceuma_df = raceuma_df[raceuma_df["競走コード"] == race_id]
        this_bet_df = bet_df.query(f"競走コード == {race_id}")
        this_haraimodoshi_dict = {
            "tansho_df": this_tansho_df,
            "fukusho_df": this_fukusho_df,
            "umaren_df": this_umaren_df,
            "umatan_df": this_umatan_df,
            "wide_df": this_wide_df,
            "sanrenpuku_df": this_sanrenpuku_df
        }
        if len(this_race_df.index) != 0 and len(this_raceuma_df.index) != 0:
            return p8.race_result_render(this_race_df, this_raceuma_df,
                                         this_bet_df, this_haraimodoshi_dict)
        else:
            return html.P(
                f"this_race_df: {len(this_race_df.index)} this_raceuma_df: {len(this_raceuma_df.index)} this_bet_df: {len(this_bet_df)} this_haraimodoshi_dict: {len(this_haraimodoshi_dict)}"
            )
    else:
        return html.P("not loading data")
コード例 #10
0
ファイル: race_info.py プロジェクト: ikem55/HRdashboard
def race_info_render(race_df, raceuma_df, shap_df_umaren_are,
                     shap_df_umatan_are, shap_df_sanrenpuku_are):
    race_sr = race_df.iloc[0]
    term_start_date = "2019-12-01"
    term_end_date = race_sr["月日"].strftime("%Y-%m-%d")
    ketto_toroku_bango_list = raceuma_df["血統登録番号"].tolist()
    raceuma_prev_df = GetData.get_raceuma_prev_df(term_start_date,
                                                  term_end_date,
                                                  ketto_toroku_bango_list)
    raceuma_prev_df = pd.merge(raceuma_df[["血統登録番号", "馬名"]],
                               raceuma_prev_df,
                               on="血統登録番号")
    raceuma_df = raceuma_df.sort_values("馬番", ascending=False)
    raceuma_prev_df = raceuma_prev_df.sort_values("馬名", ascending=False)

    # 得点
    fig1 = wp.cp_basic_horizontal_bar_chart_score(raceuma_df)
    # 最大得点分布
    #fig2 = wp.cp_basic_dot_plot_max_score(raceuma_df)
    # 得点バブル
    #fig3 = wp.cp_buble_chart_score(raceuma_df.sort_values("馬番"))
    # レーダーチャート
    fig4 = wp.cp_multiple_trace_rader_chart_score(raceuma_df.sort_values("馬番"))
    # 先行率
    fig5 = wp.cp_basic_horizontal_box_plot_senko_rate(raceuma_prev_df)
    # タイム指数
    fig6 = wp.cp_basic_horizontal_box_plot_time_score(raceuma_prev_df)

    # テーブルデータ
    fig7_df = raceuma_df[[
        "枠番", "馬番", "馬名", "性別コード", "馬齢", "負担重量", "予想タイム指数順位", "予想タイム指数",
        "デフォルト得点", "得点", "馬券評価順位", "先行指数", "予想展開", "騎手名", "調教師名", "所属", "得点V3",
        "WIN_RATE", "JIKU_RATE", "ANA_RATE", "WIN_RANK", "JIKU_RANK",
        "ANA_RANK", "SCORE", "SCORE_RANK", "CK1_RATE", "CK2_RATE", "CK3_RATE",
        "CK1_RANK", "CK2_RANK", "CK3_RANK"
    ]].sort_values("馬番")

    # 馬連荒れ根拠
    #fig8 = wp.cp_controlling_text_fontsize_with_uniformtext_umaren_basis(shap_df_umaren_are)
    # 馬単荒れ根拠
    #fig9 = wp.cp_controlling_text_fontsize_with_uniformtext_umatan_basis(shap_df_umatan_are)
    # 三連複荒れ根拠
    #fig10 = wp.cp_controlling_text_fontsize_with_uniformtext_sanrenpuku_basis(shap_df_sanrenpuku_are)

    raceuma_dropdown_option = raceuma_df[["馬名", "馬番"]].rename(columns={
        "馬名": "label",
        "馬番": "value"
    }).to_dict(orient='record')
    return dcc.Loading(
        id="race-info-render-loading",
        children=[
            dbc.Row([
                wp.dbc_race_info(race_sr, 12),
            ], className="h-8"),
            #            dbc.Row([
            #                wp.dbc_graph("fig8", 4, fig8, "馬連荒れ根拠", 300, bottom=100),
            #                wp.dbc_graph("fig9", 4, fig9, "馬単荒れ根拠", 300, bottom=100),
            #                wp.dbc_graph("fig10", 4, fig10, "三連複荒れ根拠", 300, bottom=100),
            #            ], className="h-30", no_gutters=True),
            dbc.Row([
                wp.dbc_graph("fig1", 6, fig1, "得点", 500),
                wp.dbc_graph("fig4", 6, fig4, "レーダーチャート", 500),
            ],
                    className="h-50",
                    no_gutters=True),
            #            dbc.Row([
            #                wp.dbc_graph("fig2", 6, fig2, "最大得点分布", 500),
            #                wp.dbc_graph("fig3", 6, fig3, "得点バブル", 500),
            #            ], className="h-50", no_gutters=True),
            dbc.Row([
                wp.dbc_graph("fig5", 6, fig5, "先行率", 500),
                wp.dbc_graph("fig6", 6, fig6, "タイム指数", 500),
            ],
                    className="h-50",
                    no_gutters=True),
            wp.dbc_race_info_table("fig7", 16, fig7_df),
            dbc.Row([
                wp.dbc_title("得点根拠", 6),
                dcc.Dropdown(id="raceinfo-dropdown-raceuma",
                             options=raceuma_dropdown_option,
                             style={"width": "300px"}),
            ],
                    className="h-8"),
            dcc.Loading(id="raceuma-info-loading",
                        children=[html.Div(id="raceinfo-raceuma-detail")])
        ])
コード例 #11
0
ファイル: race_trend.py プロジェクト: ikem55/HRdashboard
def race_trend():
    race_df = GetData.get_race_data_real().query("データ区分 == '7'")
    raceuma_df = GetData.get_raceuma_data_real().query("データ区分 == '7'")

    raceuma_df.loc[:, "競走馬コード"] = raceuma_df.apply(lambda x : str(x["競走コード"]) + str(x["馬番"]).zfill(2), axis=1)
    bet_df = GetData.get_bet_data_real()
    haraimodoshi_dict = GetData.get_haraimodoshi_dict_real()
    if len(race_df.index) == 0 or len(raceuma_df.index) == 0:
        return html.P("no data")

    # 得点1位着順
    fig1 = wp.cp_pie_chart_score_1(raceuma_df)

    # 単勝回収率
    fig2_df = raceuma_df[raceuma_df["馬券評価順位"] == 1].copy()
    fig2_value = fig2_df["単勝配当"].mean()
    fig2_reference = 0
    fig2 = gp.add_steps_threshold_anda_delta(fig2_value, fig2_reference)

    # 複勝回収率
    fig3_df = raceuma_df[raceuma_df["馬券評価順位"] == 1].copy()
    fig3_value = fig3_df["複勝配当"].mean()
    fig3_reference = 0
    fig3 = gp.add_steps_threshold_anda_delta(fig3_value, fig3_reference)

    # 1番人気
    fig4 = wp.cp_pie_chart_ninki_1(raceuma_df)

    # 単勝回収率
    fig5_df = raceuma_df[raceuma_df["単勝人気"] == 1].copy()
    fig5_value = fig5_df["単勝配当"].mean()
    fig5_reference = 0
    fig5 = gp.add_steps_threshold_anda_delta(fig5_value, fig5_reference)

    # 複勝回収率
    fig6_df = raceuma_df[raceuma_df["単勝人気"] == 1].copy()
    fig6_value = fig6_df["複勝配当"].mean()
    fig6_reference = 0
    fig6 = gp.add_steps_threshold_anda_delta(fig6_value, fig6_reference)

    # 場所別単複回収率・的中率
    fig7 = wp.cp_multiple_line_and_bar_chart_place_tanpuku_return(race_df, raceuma_df)

    if len(bet_df.index) != 0:
        # 場所別馬券回収率・的中率
        fig8 = wp.cp_multiple_line_and_bar_chart_place_bet_return(bet_df)
        # 券種別結果
        summary_bet_df = cd.get_summary_bet_df(bet_df)
        fig9 = wp.cp_simple_waterfall_chart_balance_change(summary_bet_df)
    else:
        fig8 = ""
        fig9 = ""

    # 単勝配当分布
    #fig10 = wp.cp_pie_chart_tansho_dist(haraimodoshi_dict)
    # 複勝配当分布
    #fig11 = wp.cp_pie_chart_fukusho_dist(haraimodoshi_dict)
    # 馬連配当分布
    #fig12 = wp.cp_pie_chart_umaren_dist(haraimodoshi_dict)
    # 馬単配当分布
    #fig13 = wp.cp_pie_chart_umatan_dist(haraimodoshi_dict)
    # ワイド配当分布
    #fig14 = wp.cp_pie_chart_wide_dist(haraimodoshi_dict)
    # 三連複配当分布
    #fig15 = wp.cp_pie_chart_sanrenpuku_dist(haraimodoshi_dict)
    # 馬連的中1
    fig20 = wp.cp_stacked_funnel_plot_umaren_1(race_df, raceuma_df, haraimodoshi_dict)
    # 馬連的中2
    fig21 = wp.cp_stacked_funnel_plot_umaren_2(race_df, raceuma_df, haraimodoshi_dict)
    # 馬単的中1
    fig22 = wp.cp_stacked_funnel_plot_umatan_1(race_df, raceuma_df, haraimodoshi_dict)
    # 馬単的中2
    fig23 = wp.cp_stacked_funnel_plot_umatan_2(race_df, raceuma_df, haraimodoshi_dict)
    # 馬単的中3
    fig24 = wp.cp_stacked_funnel_plot_umatan_3(race_df, raceuma_df, haraimodoshi_dict)
    # ワイド的中1
    fig25 = wp.cp_stacked_funnel_plot_wide_1(race_df, raceuma_df, haraimodoshi_dict)

    return dcc.Loading(id="racetrend-loading", children=[
        dbc.Container([
            dbc.Row([
                wp.dbc_top_title("todays race trend")
            ], className="h-30"),
            dbc.Row([
                wp.dbc_graph("fig1", 2, fig1, "得点1位着順", 130),
                wp.dbc_graph("fig2", 2, fig2, "単勝回収率", 130),
                wp.dbc_graph("fig3", 2, fig3, "複勝回収率", 130),
                wp.dbc_graph("fig4", 2, fig4, "1番人気", 130),
                wp.dbc_graph("fig5", 2, fig5, "単勝回収率", 130),
                wp.dbc_graph("fig6", 2, fig6, "複勝回収率", 130),
            ], className="h-20", no_gutters=True),
#            dbc.Row([
#                wp.dbc_graph("fig10", 2, fig10, "単勝配当分布", 200),
#                wp.dbc_graph("fig11", 2, fig11, "複勝配当分布", 200),
#                wp.dbc_graph("fig12", 2, fig12, "馬連配当分布", 200),
#                wp.dbc_graph("fig13", 2, fig13, "馬単配当分布", 200),
#                wp.dbc_graph("fig14", 2, fig14, "ワイド配当分布", 200),
#                wp.dbc_graph("fig15", 2, fig15, "三連複配当分布", 200),
#            ], className="h-20", no_gutters=True),
            dbc.Row([
                wp.dbc_graph("fig7", 4, fig7, "場所別単複回収率・的中率", 300),
                wp.dbc_graph("fig8", 4, fig8, "場所別馬券回収率・的中率", 300),
                wp.dbc_graph("fig9", 4, fig9, "券種別結果", 300),
            ], className="h-30", no_gutters=True),
            dbc.Row([
                wp.dbc_graph("fig20", 2, fig20, "馬連的中1", 400),
                wp.dbc_graph("fig21", 2, fig21, "馬連的中2", 400),
                wp.dbc_graph("fig22", 2, fig22, "馬単的中1", 400),
                wp.dbc_graph("fig23", 2, fig23, "馬単的中2", 400),
                wp.dbc_graph("fig24", 2, fig24, "馬単的中3", 400),
                wp.dbc_graph("fig25", 2, fig25, "ワイド的中1", 400),
            ], className="h-30", no_gutters=True),
        ],
        style={"height": "90vh"},
        fluid=True
    )])