cyberosa commited on
Commit
5b81650
·
1 Parent(s): 1edb6cc

updating notebook with errors handling. Cleaning

Browse files
Files changed (2) hide show
  1. nbs/weekly_analysis.ipynb +0 -0
  2. tabs/error.py +43 -37
nbs/weekly_analysis.ipynb CHANGED
The diff for this file is too large to render. See raw diff
 
tabs/error.py CHANGED
@@ -3,34 +3,38 @@ import gradio as gr
3
  from typing import List
4
 
5
 
6
- HEIGHT=600
7
- WIDTH=1000
8
 
9
- # def set_error(row: pd.Series) -> bool:
10
- # """Sets the error for the given row."""
11
- # if row.error not in [True, False]:
12
- # if not row.prompt_response:
13
- # return True
14
- # return False
15
- # return row.error
16
 
17
  def get_error_data(tools_df: pd.DataFrame, inc_tools: List[str]) -> pd.DataFrame:
18
  """Gets the error data for the given tools and calculates the error percentage."""
19
- tools_inc = tools_df[tools_df['tool'].isin(inc_tools)]
20
- # tools_inc['error'] = tools_inc.apply(set_error, axis=1)
21
- error = tools_inc.groupby(['tool', 'request_month_year_week', 'error']).size().unstack().fillna(0).reset_index()
22
- error['error_perc'] = (error[1] / (error[0] + error[1])) * 100
23
- error['total_requests'] = error[0] + error[1]
 
 
 
 
 
24
  return error
25
 
 
26
  def get_error_data_overall(error_df: pd.DataFrame) -> pd.DataFrame:
27
  """Gets the error data for the given tools and calculates the error percentage."""
28
- error_total = error_df.groupby('request_month_year_week').agg({'total_requests': 'sum', 1: 'sum', 0: 'sum'}).reset_index()
29
- error_total['error_perc'] = (error_total[1] / error_total['total_requests']) * 100
 
 
 
 
30
  error_total.columns = error_total.columns.astype(str)
31
- error_total['error_perc'] = error_total['error_perc'].apply(lambda x: round(x, 4))
32
  return error_total
33
 
 
34
  def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
35
  """Plots the error data for the given tools and calculates the error percentage."""
36
  return gr.BarPlot(
@@ -45,35 +49,37 @@ def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
45
  show_actions_button=True,
46
  tooltip=["request_month_year_week", "error_perc"],
47
  height=HEIGHT,
48
- width=WIDTH
49
  )
50
 
 
51
  def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
52
  """Plots the error data for the given tool."""
53
- error_tool = error_df[error_df['tool'] == tool]
54
  error_tool.columns = error_tool.columns.astype(str)
55
- error_tool['error_perc'] = error_tool['error_perc'].apply(lambda x: round(x, 4))
56
-
57
  return gr.BarPlot(
58
- title="Error Percentage",
59
- x_title="Week",
60
- y_title="Error Percentage",
61
- show_label=True,
62
- interactive=True,
63
- show_actions_button=True,
64
- tooltip=["request_month_year_week", "error_perc"],
65
- value=error_tool,
66
- x="request_month_year_week",
67
- y="error_perc",
68
- height=HEIGHT,
69
- width=WIDTH
70
  )
71
 
 
72
  def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
73
  """Plots the error data for the given week."""
74
- error_week = error_df[error_df['request_month_year_week'] == week]
75
  error_week.columns = error_week.columns.astype(str)
76
- error_week['error_perc'] = error_week['error_perc'].apply(lambda x: round(x, 4))
77
  return gr.BarPlot(
78
  value=error_week,
79
  x="tool",
@@ -86,5 +92,5 @@ def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
86
  show_actions_button=True,
87
  tooltip=["tool", "error_perc"],
88
  height=HEIGHT,
89
- width=WIDTH
90
- )
 
3
  from typing import List
4
 
5
 
6
+ HEIGHT = 600
7
+ WIDTH = 1000
8
 
 
 
 
 
 
 
 
9
 
10
  def get_error_data(tools_df: pd.DataFrame, inc_tools: List[str]) -> pd.DataFrame:
11
  """Gets the error data for the given tools and calculates the error percentage."""
12
+ tools_inc = tools_df[tools_df["tool"].isin(inc_tools)]
13
+ error = (
14
+ tools_inc.groupby(["tool", "request_month_year_week", "error"])
15
+ .size()
16
+ .unstack()
17
+ .fillna(0)
18
+ .reset_index()
19
+ )
20
+ error["error_perc"] = (error[1] / (error[0] + error[1])) * 100
21
+ error["total_requests"] = error[0] + error[1]
22
  return error
23
 
24
+
25
  def get_error_data_overall(error_df: pd.DataFrame) -> pd.DataFrame:
26
  """Gets the error data for the given tools and calculates the error percentage."""
27
+ error_total = (
28
+ error_df.groupby("request_month_year_week")
29
+ .agg({"total_requests": "sum", 1: "sum", 0: "sum"})
30
+ .reset_index()
31
+ )
32
+ error_total["error_perc"] = (error_total[1] / error_total["total_requests"]) * 100
33
  error_total.columns = error_total.columns.astype(str)
34
+ error_total["error_perc"] = error_total["error_perc"].apply(lambda x: round(x, 4))
35
  return error_total
36
 
37
+
38
  def plot_error_data(error_all_df: pd.DataFrame) -> gr.BarPlot:
39
  """Plots the error data for the given tools and calculates the error percentage."""
40
  return gr.BarPlot(
 
49
  show_actions_button=True,
50
  tooltip=["request_month_year_week", "error_perc"],
51
  height=HEIGHT,
52
+ width=WIDTH,
53
  )
54
 
55
+
56
  def plot_tool_error_data(error_df: pd.DataFrame, tool: str) -> gr.BarPlot:
57
  """Plots the error data for the given tool."""
58
+ error_tool = error_df[error_df["tool"] == tool]
59
  error_tool.columns = error_tool.columns.astype(str)
60
+ error_tool["error_perc"] = error_tool["error_perc"].apply(lambda x: round(x, 4))
61
+
62
  return gr.BarPlot(
63
+ title="Error Percentage",
64
+ x_title="Week",
65
+ y_title="Error Percentage",
66
+ show_label=True,
67
+ interactive=True,
68
+ show_actions_button=True,
69
+ tooltip=["request_month_year_week", "error_perc"],
70
+ value=error_tool,
71
+ x="request_month_year_week",
72
+ y="error_perc",
73
+ height=HEIGHT,
74
+ width=WIDTH,
75
  )
76
 
77
+
78
  def plot_week_error_data(error_df: pd.DataFrame, week: str) -> gr.BarPlot:
79
  """Plots the error data for the given week."""
80
+ error_week = error_df[error_df["request_month_year_week"] == week]
81
  error_week.columns = error_week.columns.astype(str)
82
+ error_week["error_perc"] = error_week["error_perc"].apply(lambda x: round(x, 4))
83
  return gr.BarPlot(
84
  value=error_week,
85
  x="tool",
 
92
  show_actions_button=True,
93
  tooltip=["tool", "error_perc"],
94
  height=HEIGHT,
95
+ width=WIDTH,
96
+ )