Spaces:
Sleeping
Sleeping
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) |