Spaces:
Sleeping
Sleeping
File size: 2,394 Bytes
cfad59e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import pandas as pd
import streamlit as st
import matplotlib.pyplot as plt
import io
from pre import preprocess_uploaded_file, add_app_description
from collections import defaultdict
def generate_weekly_report(uploaded_files):
# Create a defaultdict to store the number of failures for each day
daily_failures = defaultdict(int)
for uploaded_file in uploaded_files:
# Preprocess the uploaded CSV file (you can use your existing preprocessing code)
data = preprocess_uploaded_file(uploaded_file)
# Extract the start date from the 'Start datetime' column for this file
start_date = data['Start datetime'].dt.date.iloc[0]
# Calculate the number of failures for this file
num_failures = len(data[data['Status'] == 'FAILED'])
# Add the number of failures to the corresponding day in the defaultdict
daily_failures[start_date] += num_failures
# Sort the dictionary by date
sorted_daily_failures = dict(sorted(daily_failures.items()))
# Extract dates and failures from the sorted dictionary
dates = list(sorted_daily_failures.keys())
failures = list(sorted_daily_failures.values())
# Format the dates as "DD-Mon" strings (e.g., "07-Feb")
formatted_dates = [date.strftime("%d-%b") for date in dates]
# Get the environment variable from the first file (assuming it's the same for all files)
environment = data['Environment'].iloc[0]
# Create a larger line chart to show the trend in failure rates over days
plt.figure(figsize=(12, 8))
plt.plot(formatted_dates, failures, marker='o', linestyle='-')
plt.xlabel('Date', fontsize=14) # Increase font size for X-axis label
plt.ylabel('Number of Failures', fontsize=14) # Increase font size for Y-axis label
plt.title(f'Trends in Failure Rates Over Days for Environment: {environment}', fontsize=16) # Increase title font size
plt.xticks(rotation=45, fontsize=12) # Increase font size and rotation for X-axis ticks
plt.yticks(fontsize=12) # Increase font size for Y-axis ticks
plt.grid(False)
# Add labels with the number of failures at each data point with larger font
for i in range(len(dates)):
plt.text(formatted_dates[i], failures[i], str(failures[i]), ha='center', va='bottom', fontsize=12)
plt.tight_layout()
# Display the bar chart
st.pyplot(plt) |