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