Commit
·
79e26e1
1
Parent(s):
a035e35
cleaning non-used functions
Browse files- tabs/error.py +0 -89
- tabs/tool_win.py +0 -80
tabs/error.py
CHANGED
|
@@ -9,21 +9,6 @@ HEIGHT = 600
|
|
| 9 |
WIDTH = 1000
|
| 10 |
|
| 11 |
|
| 12 |
-
def get_error_data(tools_df: pd.DataFrame, inc_tools: List[str]) -> pd.DataFrame:
|
| 13 |
-
"""Gets the error data for the given tools and calculates the error percentage."""
|
| 14 |
-
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 15 |
-
error = (
|
| 16 |
-
tools_inc.groupby(["tool", "request_month_year_week", "error"])
|
| 17 |
-
.size()
|
| 18 |
-
.unstack()
|
| 19 |
-
.fillna(0)
|
| 20 |
-
.reset_index()
|
| 21 |
-
)
|
| 22 |
-
error["error_perc"] = (error[1] / (error[0] + error[1])) * 100
|
| 23 |
-
error["total_requests"] = error[0] + error[1]
|
| 24 |
-
return error
|
| 25 |
-
|
| 26 |
-
|
| 27 |
def get_error_data_by_market(
|
| 28 |
tools_df: pd.DataFrame, inc_tools: List[str]
|
| 29 |
) -> pd.DataFrame:
|
|
@@ -43,19 +28,6 @@ def get_error_data_by_market(
|
|
| 43 |
return error
|
| 44 |
|
| 45 |
|
| 46 |
-
def get_error_data_overall(error_df: pd.DataFrame) -> pd.DataFrame:
|
| 47 |
-
"""Gets the error data for the given tools and calculates the error percentage."""
|
| 48 |
-
error_total = (
|
| 49 |
-
error_df.groupby("request_month_year_week")
|
| 50 |
-
.agg({"total_requests": "sum", 1: "sum", 0: "sum"})
|
| 51 |
-
.reset_index()
|
| 52 |
-
)
|
| 53 |
-
error_total["error_perc"] = (error_total[1] / error_total["total_requests"]) * 100
|
| 54 |
-
error_total.columns = error_total.columns.astype(str)
|
| 55 |
-
error_total["error_perc"] = error_total["error_perc"].apply(lambda x: round(x, 4))
|
| 56 |
-
return error_total
|
| 57 |
-
|
| 58 |
-
|
| 59 |
def get_error_data_overall_by_market(error_df: pd.DataFrame) -> pd.DataFrame:
|
| 60 |
"""Gets the error data for the given tools and calculates the error percentage."""
|
| 61 |
error_total = (
|
|
@@ -69,24 +41,6 @@ def get_error_data_overall_by_market(error_df: pd.DataFrame) -> pd.DataFrame:
|
|
| 69 |
return error_total
|
| 70 |
|
| 71 |
|
| 72 |
-
def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
|
| 73 |
-
"""Plots the error data for the given tools and calculates the error percentage."""
|
| 74 |
-
return gr.BarPlot(
|
| 75 |
-
value=error_all_df,
|
| 76 |
-
x="request_month_year_week",
|
| 77 |
-
y="error_perc",
|
| 78 |
-
title="Error Percentage",
|
| 79 |
-
x_title="Week",
|
| 80 |
-
y_title="Error Percentage",
|
| 81 |
-
show_label=True,
|
| 82 |
-
interactive=True,
|
| 83 |
-
show_actions_button=True,
|
| 84 |
-
tooltip=["request_month_year_week", "error_perc"],
|
| 85 |
-
height=HEIGHT,
|
| 86 |
-
width=WIDTH,
|
| 87 |
-
)
|
| 88 |
-
|
| 89 |
-
|
| 90 |
def plot_error_data_by_market(error_all_df: pd.DataFrame) -> gr.Plot:
|
| 91 |
|
| 92 |
# Sort the unique values of request_month_year_week
|
|
@@ -125,28 +79,6 @@ def plot_error_data_by_market(error_all_df: pd.DataFrame) -> gr.Plot:
|
|
| 125 |
return gr.Plot(value=fig)
|
| 126 |
|
| 127 |
|
| 128 |
-
def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
|
| 129 |
-
"""Plots the error data for the given tool."""
|
| 130 |
-
error_tool = error_df[error_df["tool"] == tool]
|
| 131 |
-
error_tool.columns = error_tool.columns.astype(str)
|
| 132 |
-
error_tool["error_perc"] = error_tool["error_perc"].apply(lambda x: round(x, 4))
|
| 133 |
-
|
| 134 |
-
return gr.BarPlot(
|
| 135 |
-
title="Error Percentage",
|
| 136 |
-
x_title="Week",
|
| 137 |
-
y_title="Error Percentage %",
|
| 138 |
-
show_label=True,
|
| 139 |
-
interactive=True,
|
| 140 |
-
show_actions_button=True,
|
| 141 |
-
tooltip=["request_month_year_week", "error_perc"],
|
| 142 |
-
value=error_tool,
|
| 143 |
-
x="request_month_year_week",
|
| 144 |
-
y="error_perc",
|
| 145 |
-
height=HEIGHT,
|
| 146 |
-
width=WIDTH,
|
| 147 |
-
)
|
| 148 |
-
|
| 149 |
-
|
| 150 |
def plot_tool_error_data_by_market(error_df: pd.DataFrame, tool: str) -> gr.Plot:
|
| 151 |
error_tool = error_df[error_df["tool"] == tool]
|
| 152 |
error_tool.columns = error_tool.columns.astype(str)
|
|
@@ -188,27 +120,6 @@ def plot_tool_error_data_by_market(error_df: pd.DataFrame, tool: str) -> gr.Plot
|
|
| 188 |
return gr.Plot(value=fig)
|
| 189 |
|
| 190 |
|
| 191 |
-
def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
|
| 192 |
-
"""Plots the error data for the given week."""
|
| 193 |
-
error_week = error_df[error_df["request_month_year_week"] == week]
|
| 194 |
-
error_week.columns = error_week.columns.astype(str)
|
| 195 |
-
error_week["error_perc"] = error_week["error_perc"].apply(lambda x: round(x, 4))
|
| 196 |
-
return gr.BarPlot(
|
| 197 |
-
value=error_week,
|
| 198 |
-
x="tool",
|
| 199 |
-
y="error_perc",
|
| 200 |
-
title="Error Percentage",
|
| 201 |
-
x_title="Tool",
|
| 202 |
-
y_title="Error Percentage",
|
| 203 |
-
show_label=True,
|
| 204 |
-
interactive=True,
|
| 205 |
-
show_actions_button=True,
|
| 206 |
-
tooltip=["tool", "error_perc"],
|
| 207 |
-
height=HEIGHT,
|
| 208 |
-
width=WIDTH,
|
| 209 |
-
)
|
| 210 |
-
|
| 211 |
-
|
| 212 |
def plot_week_error_data_by_market(error_df: pd.DataFrame, week: str) -> gr.Plot:
|
| 213 |
error_week = error_df[error_df["request_month_year_week"] == week]
|
| 214 |
error_week.columns = error_week.columns.astype(str)
|
|
|
|
| 9 |
WIDTH = 1000
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def get_error_data_by_market(
|
| 13 |
tools_df: pd.DataFrame, inc_tools: List[str]
|
| 14 |
) -> pd.DataFrame:
|
|
|
|
| 28 |
return error
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def get_error_data_overall_by_market(error_df: pd.DataFrame) -> pd.DataFrame:
|
| 32 |
"""Gets the error data for the given tools and calculates the error percentage."""
|
| 33 |
error_total = (
|
|
|
|
| 41 |
return error_total
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def plot_error_data_by_market(error_all_df: pd.DataFrame) -> gr.Plot:
|
| 45 |
|
| 46 |
# Sort the unique values of request_month_year_week
|
|
|
|
| 79 |
return gr.Plot(value=fig)
|
| 80 |
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
def plot_tool_error_data_by_market(error_df: pd.DataFrame, tool: str) -> gr.Plot:
|
| 83 |
error_tool = error_df[error_df["tool"] == tool]
|
| 84 |
error_tool.columns = error_tool.columns.astype(str)
|
|
|
|
| 120 |
return gr.Plot(value=fig)
|
| 121 |
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
def plot_week_error_data_by_market(error_df: pd.DataFrame, week: str) -> gr.Plot:
|
| 124 |
error_week = error_df[error_df["request_month_year_week"] == week]
|
| 125 |
error_week.columns = error_week.columns.astype(str)
|
tabs/tool_win.py
CHANGED
|
@@ -26,37 +26,6 @@ def prepare_tools(tools: pd.DataFrame) -> pd.DataFrame:
|
|
| 26 |
return tools
|
| 27 |
|
| 28 |
|
| 29 |
-
def get_tool_winning_rate(tools_df: pd.DataFrame, inc_tools: List[str]) -> pd.DataFrame:
|
| 30 |
-
"""Gets the tool winning rate data for the given tools and calculates the winning percentage."""
|
| 31 |
-
tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
|
| 32 |
-
# tools_inc['error'] = tools_inc.apply(set_error, axis=1)
|
| 33 |
-
tools_non_error = tools_inc[tools_inc["error"] != 1]
|
| 34 |
-
tools_non_error.loc[:, "currentAnswer"] = tools_non_error["currentAnswer"].replace(
|
| 35 |
-
{"no": "No", "yes": "Yes"}
|
| 36 |
-
)
|
| 37 |
-
tools_non_error = tools_non_error[
|
| 38 |
-
tools_non_error["currentAnswer"].isin(["Yes", "No"])
|
| 39 |
-
]
|
| 40 |
-
tools_non_error = tools_non_error[tools_non_error["vote"].isin(["Yes", "No"])]
|
| 41 |
-
tools_non_error["win"] = (
|
| 42 |
-
tools_non_error["currentAnswer"] == tools_non_error["vote"]
|
| 43 |
-
).astype(int)
|
| 44 |
-
tools_non_error.columns = tools_non_error.columns.astype(str)
|
| 45 |
-
wins = (
|
| 46 |
-
tools_non_error.groupby(["tool", "request_month_year_week", "win"])
|
| 47 |
-
.size()
|
| 48 |
-
.unstack()
|
| 49 |
-
.fillna(0)
|
| 50 |
-
)
|
| 51 |
-
wins["win_perc"] = (wins[1] / (wins[0] + wins[1])) * 100
|
| 52 |
-
wins.reset_index(inplace=True)
|
| 53 |
-
wins["total_request"] = wins[0] + wins[1]
|
| 54 |
-
wins.columns = wins.columns.astype(str)
|
| 55 |
-
# Convert request_month_year_week to string and explicitly set type for Altair
|
| 56 |
-
wins["request_month_year_week"] = wins["request_month_year_week"].astype(str)
|
| 57 |
-
return wins
|
| 58 |
-
|
| 59 |
-
|
| 60 |
def get_tool_winning_rate_by_market(
|
| 61 |
tools_df: pd.DataFrame, inc_tools: List[str]
|
| 62 |
) -> pd.DataFrame:
|
|
@@ -91,17 +60,6 @@ def get_tool_winning_rate_by_market(
|
|
| 91 |
return wins
|
| 92 |
|
| 93 |
|
| 94 |
-
def get_overall_winning_rate(wins_df: pd.DataFrame) -> pd.DataFrame:
|
| 95 |
-
"""Gets the overall winning rate data for the given tools and calculates the winning percentage."""
|
| 96 |
-
overall_wins = (
|
| 97 |
-
wins_df.groupby("request_month_year_week")
|
| 98 |
-
.agg({"0": "sum", "1": "sum", "win_perc": "mean", "total_request": "sum"})
|
| 99 |
-
.rename(columns={"0": "losses", "1": "wins"})
|
| 100 |
-
.reset_index()
|
| 101 |
-
)
|
| 102 |
-
return overall_wins
|
| 103 |
-
|
| 104 |
-
|
| 105 |
def get_overall_winning_rate_by_market(wins_df: pd.DataFrame) -> pd.DataFrame:
|
| 106 |
"""Gets the overall winning rate data for the given tools and calculates the winning percentage."""
|
| 107 |
overall_wins = (
|
|
@@ -113,26 +71,6 @@ def get_overall_winning_rate_by_market(wins_df: pd.DataFrame) -> pd.DataFrame:
|
|
| 113 |
return overall_wins
|
| 114 |
|
| 115 |
|
| 116 |
-
def plot_tool_winnings_overall(
|
| 117 |
-
wins_df: pd.DataFrame, winning_selector: str = "win_perc"
|
| 118 |
-
) -> gr.BarPlot:
|
| 119 |
-
"""Plots the overall winning rate data for the given tools and calculates the winning percentage."""
|
| 120 |
-
return gr.BarPlot(
|
| 121 |
-
title="Winning Rate",
|
| 122 |
-
x_title="Date",
|
| 123 |
-
y_title=winning_selector,
|
| 124 |
-
show_label=True,
|
| 125 |
-
interactive=True,
|
| 126 |
-
show_actions_button=True,
|
| 127 |
-
tooltip=["request_month_year_week", winning_selector],
|
| 128 |
-
value=wins_df,
|
| 129 |
-
x="request_month_year_week",
|
| 130 |
-
y=winning_selector,
|
| 131 |
-
height=HEIGHT,
|
| 132 |
-
width=WIDTH,
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
|
| 136 |
def sort_key(date_str):
|
| 137 |
month, year_week = date_str.split("-")
|
| 138 |
month_order = [
|
|
@@ -197,24 +135,6 @@ def integrated_plot_tool_winnings_overall_per_market_by_week(
|
|
| 197 |
return gr.Plot(value=fig)
|
| 198 |
|
| 199 |
|
| 200 |
-
def plot_tool_winnings_by_tool(wins_df: pd.DataFrame, tool: str) -> gr.BarPlot:
|
| 201 |
-
"""Plots the winning rate data for the given tool."""
|
| 202 |
-
return gr.BarPlot(
|
| 203 |
-
title="Winning Rate",
|
| 204 |
-
x_title="Week",
|
| 205 |
-
y_title="Winning Rate",
|
| 206 |
-
x="request_month_year_week",
|
| 207 |
-
y="win_perc",
|
| 208 |
-
value=wins_df[wins_df["tool"] == tool],
|
| 209 |
-
show_label=True,
|
| 210 |
-
interactive=True,
|
| 211 |
-
show_actions_button=True,
|
| 212 |
-
tooltip=["request_month_year_week", "win_perc"],
|
| 213 |
-
height=HEIGHT,
|
| 214 |
-
width=WIDTH,
|
| 215 |
-
)
|
| 216 |
-
|
| 217 |
-
|
| 218 |
def integrated_tool_winnings_by_tool_per_market(
|
| 219 |
wins_df: pd.DataFrame, tool: str
|
| 220 |
) -> gr.Plot:
|
|
|
|
| 26 |
return tools
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def get_tool_winning_rate_by_market(
|
| 30 |
tools_df: pd.DataFrame, inc_tools: List[str]
|
| 31 |
) -> pd.DataFrame:
|
|
|
|
| 60 |
return wins
|
| 61 |
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
def get_overall_winning_rate_by_market(wins_df: pd.DataFrame) -> pd.DataFrame:
|
| 64 |
"""Gets the overall winning rate data for the given tools and calculates the winning percentage."""
|
| 65 |
overall_wins = (
|
|
|
|
| 71 |
return overall_wins
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def sort_key(date_str):
|
| 75 |
month, year_week = date_str.split("-")
|
| 76 |
month_order = [
|
|
|
|
| 135 |
return gr.Plot(value=fig)
|
| 136 |
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
def integrated_tool_winnings_by_tool_per_market(
|
| 139 |
wins_df: pd.DataFrame, tool: str
|
| 140 |
) -> gr.Plot:
|