Spaces:
Sleeping
Sleeping
Commit
·
cf4c4b7
1
Parent(s):
7a2556d
Update weekly.py
Browse files
weekly.py
CHANGED
|
@@ -2,13 +2,14 @@ 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
|
| 6 |
|
| 7 |
from collections import defaultdict
|
| 8 |
|
| 9 |
def generate_weekly_report(uploaded_files):
|
| 10 |
-
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
for uploaded_file in uploaded_files:
|
| 14 |
# Preprocess the uploaded CSV file (you can use your existing preprocessing code)
|
|
@@ -20,38 +21,53 @@ def generate_weekly_report(uploaded_files):
|
|
| 20 |
# Calculate the number of failures for this file
|
| 21 |
num_failures = len(data[data['Status'] == 'FAILED'])
|
| 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 |
-
plt.
|
| 49 |
-
plt.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
# Add labels with the number of failures at each data point with larger font
|
| 52 |
-
for
|
| 53 |
-
|
|
|
|
|
|
|
| 54 |
|
| 55 |
plt.tight_layout()
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
| 2 |
import streamlit as st
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
import io
|
| 5 |
+
from pre import preprocess_uploaded_file
|
| 6 |
|
| 7 |
from collections import defaultdict
|
| 8 |
|
| 9 |
def generate_weekly_report(uploaded_files):
|
| 10 |
+
|
| 11 |
+
# Create a dictionary to store the number of failures for each environment and day
|
| 12 |
+
environment_daily_failures = {}
|
| 13 |
|
| 14 |
for uploaded_file in uploaded_files:
|
| 15 |
# Preprocess the uploaded CSV file (you can use your existing preprocessing code)
|
|
|
|
| 21 |
# Calculate the number of failures for this file
|
| 22 |
num_failures = len(data[data['Status'] == 'FAILED'])
|
| 23 |
|
| 24 |
+
# Get the environment variable from the data frame
|
| 25 |
+
environment = data['Environment'].iloc[0]
|
| 26 |
|
| 27 |
+
# Create a unique key for each environment and day
|
| 28 |
+
key = (environment, start_date)
|
| 29 |
|
| 30 |
+
# Add the number of failures to the corresponding environment and day in the dictionary
|
| 31 |
+
if key in environment_daily_failures:
|
| 32 |
+
environment_daily_failures[key] += num_failures
|
| 33 |
+
else:
|
| 34 |
+
environment_daily_failures[key] = num_failures
|
| 35 |
|
| 36 |
+
# Create a list of unique environments
|
| 37 |
+
unique_environments = list(set([key[0] for key in environment_daily_failures.keys()]))
|
| 38 |
|
| 39 |
+
# Create a larger line chart with separate lines for each environment
|
| 40 |
+
plt.figure(figsize=(12, 8))
|
| 41 |
|
| 42 |
+
for environment in unique_environments:
|
| 43 |
+
# Filter the data for the current environment
|
| 44 |
+
environment_data = [(key[1], value) for key, value in environment_daily_failures.items() if key[0] == environment]
|
| 45 |
|
| 46 |
+
# Sort the data by date
|
| 47 |
+
environment_data.sort(key=lambda x: x[0])
|
| 48 |
|
| 49 |
+
# Extract dates and failures for the current environment
|
| 50 |
+
dates = [date.strftime("%d-%b") for date, _ in environment_data]
|
| 51 |
+
failures = [count for _, count in environment_data]
|
| 52 |
+
|
| 53 |
+
# Plot the data as a line
|
| 54 |
+
plt.plot(dates, failures, marker='o', linestyle='-', label=f'Environment: {environment}')
|
| 55 |
+
|
| 56 |
+
plt.xlabel('Date', fontsize=14)
|
| 57 |
+
plt.ylabel('Number of Failures', fontsize=14)
|
| 58 |
+
plt.title('Trends in Failure Rates Over Days', fontsize=16)
|
| 59 |
+
plt.xticks(rotation=45, fontsize=12)
|
| 60 |
+
plt.yticks(fontsize=12)
|
| 61 |
+
plt.grid(True)
|
| 62 |
+
plt.legend(fontsize=12) # Add a legend to differentiate environments
|
| 63 |
|
| 64 |
# Add labels with the number of failures at each data point with larger font
|
| 65 |
+
for environment in unique_environments:
|
| 66 |
+
environment_data = [(key[1], value) for key, value in environment_daily_failures.items() if key[0] == environment]
|
| 67 |
+
for i in range(len(environment_data)):
|
| 68 |
+
plt.text(environment_data[i][0].strftime("%d-%b"), environment_data[i][1], str(environment_data[i][1]), ha='center', va='bottom', fontsize=12)
|
| 69 |
|
| 70 |
plt.tight_layout()
|
| 71 |
+
|
| 72 |
+
# Display the larger line chart
|
| 73 |
+
st.pyplot(plt)
|