BananaSauce commited on
Commit
cf4c4b7
·
1 Parent(s): 7a2556d

Update weekly.py

Browse files
Files changed (1) hide show
  1. weekly.py +43 -27
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, 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)
@@ -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
- # 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)
 
 
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)