File size: 2,992 Bytes
cfad59e
 
 
 
cf4c4b7
cfad59e
 
 
 
cf4c4b7
 
 
cfad59e
 
 
 
 
 
 
 
 
 
 
cf4c4b7
 
cfad59e
cf4c4b7
 
cfad59e
cf4c4b7
 
 
 
 
cfad59e
cf4c4b7
 
cfad59e
cf4c4b7
 
cfad59e
cf4c4b7
 
 
cfad59e
cf4c4b7
 
cfad59e
cf4c4b7
 
 
 
 
 
 
 
 
 
 
 
 
 
cfad59e
 
cf4c4b7
 
 
 
cfad59e
 
cf4c4b7
 
 
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pandas as pd
import streamlit as st
import matplotlib.pyplot as plt
import io
from pre import preprocess_uploaded_file

from collections import defaultdict

def generate_weekly_report(uploaded_files):

    # Create a dictionary to store the number of failures for each environment and day
    environment_daily_failures = {}

    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'])

        # Get the environment variable from the data frame
        environment = data['Environment'].iloc[0]

        # Create a unique key for each environment and day
        key = (environment, start_date)

        # Add the number of failures to the corresponding environment and day in the dictionary
        if key in environment_daily_failures:
            environment_daily_failures[key] += num_failures
        else:
            environment_daily_failures[key] = num_failures

    # Create a list of unique environments
    unique_environments = list(set([key[0] for key in environment_daily_failures.keys()]))

    # Create a larger line chart with separate lines for each environment
    plt.figure(figsize=(12, 8))

    for environment in unique_environments:
        # Filter the data for the current environment
        environment_data = [(key[1], value) for key, value in environment_daily_failures.items() if key[0] == environment]

        # Sort the data by date
        environment_data.sort(key=lambda x: x[0])

        # Extract dates and failures for the current environment
        dates = [date.strftime("%d-%b") for date, _ in environment_data]
        failures = [count for _, count in environment_data]

        # Plot the data as a line
        plt.plot(dates, failures, marker='o', linestyle='-', label=f'Environment: {environment}')

    plt.xlabel('Date', fontsize=14)
    plt.ylabel('Number of Failures', fontsize=14)
    plt.title('Trends in Failure Rates Over Days', fontsize=16)
    plt.xticks(rotation=45, fontsize=12)
    plt.yticks(fontsize=12)
    plt.grid(True)
    plt.legend(fontsize=12)  # Add a legend to differentiate environments
    
    # Add labels with the number of failures at each data point with larger font
    for environment in unique_environments:
        environment_data = [(key[1], value) for key, value in environment_daily_failures.items() if key[0] == environment]
        for i in range(len(environment_data)):
            plt.text(environment_data[i][0].strftime("%d-%b"), environment_data[i][1], str(environment_data[i][1]), ha='center', va='bottom', fontsize=12)

    plt.tight_layout()

    # Display the larger line chart
    st.pyplot(plt)