new errorlisting
This commit is contained in:
parent
d39453d688
commit
d33b6c4226
3 changed files with 75 additions and 66 deletions
|
|
@ -52,12 +52,15 @@ def generate_error_rate_plot(applications_file: str):
|
|||
grouped = grouped.sort_index()
|
||||
|
||||
# Plot
|
||||
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 8), sharex=True)
|
||||
import matplotlib.dates as mdates
|
||||
# Add a third subplot for error rate by company
|
||||
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(12, 12), sharex=True)
|
||||
|
||||
# Stacked bar: successes vs failures (all companies)
|
||||
grouped[['successes','failures']].plot(kind='bar', stacked=True, ax=ax1, color=['#2E8B57','#C44A4A'])
|
||||
ax1.set_ylabel('Count')
|
||||
ax1.set_title('Autopilot: Successes vs Failures (by day)')
|
||||
|
||||
import matplotlib.dates as mdates
|
||||
dates = pd.to_datetime(grouped.index).to_pydatetime()
|
||||
x = mdates.date2num(dates)
|
||||
width = 0.6
|
||||
|
|
@ -69,6 +72,7 @@ def generate_error_rate_plot(applications_file: str):
|
|||
ax1.xaxis.set_major_locator(mdates.AutoDateLocator())
|
||||
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
||||
|
||||
# Line: overall error rate
|
||||
ax2.plot(x, grouped['error_rate'].values, marker='o', color='#3333AA', linewidth=2)
|
||||
ax2.set_ylim(-0.02, 1.02)
|
||||
ax2.set_ylabel('Error rate')
|
||||
|
|
@ -79,6 +83,30 @@ def generate_error_rate_plot(applications_file: str):
|
|||
ax2.set_xlim(min(x) - 1, max(x) + 1)
|
||||
ax2.xaxis.set_major_locator(mdates.AutoDateLocator())
|
||||
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
||||
|
||||
# New: Error rate by company (line plot)
|
||||
# Group by date and company
|
||||
company_grouped = df.groupby(['date', 'company']).agg(total=('id','count'), successes=('success', lambda x: x.sum()))
|
||||
company_grouped['failures'] = company_grouped['total'] - company_grouped['successes']
|
||||
company_grouped['error_rate'] = company_grouped['failures'] / company_grouped['total']
|
||||
company_grouped = company_grouped.reset_index()
|
||||
# Pivot for plotting: index=date, columns=company, values=error_rate
|
||||
error_rate_pivot = company_grouped.pivot(index='date', columns='company', values='error_rate')
|
||||
# Plot each company as a line
|
||||
for company in error_rate_pivot.columns:
|
||||
y = error_rate_pivot[company].values
|
||||
ax3.plot(x, y, marker='o', label=str(company))
|
||||
ax3.set_ylim(-0.02, 1.02)
|
||||
ax3.set_ylabel('Error rate')
|
||||
ax3.set_xlabel('Date')
|
||||
ax3.set_title('Daily Error Rate by Company')
|
||||
ax3.grid(True, alpha=0.3)
|
||||
ax3.set_xticks(x)
|
||||
ax3.set_xlim(min(x) - 1, max(x) + 1)
|
||||
ax3.xaxis.set_major_locator(mdates.AutoDateLocator())
|
||||
ax3.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
|
||||
ax3.legend(title='Company', loc='upper right', fontsize='small')
|
||||
|
||||
fig.autofmt_xdate()
|
||||
|
||||
plot_path = os.path.join(DATA_DIR, 'error_rate.png')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue