Spaces:
Sleeping
Sleeping
Commit
·
aad0805
1
Parent(s):
150662b
multiselect areas and chart update
Browse filesmultiselect functional areas and chart updated based on failing scenarios
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
import csv
|
4 |
-
import io
|
5 |
import matplotlib.pyplot as plt
|
6 |
import numpy as np
|
7 |
from second import double_main
|
@@ -9,7 +9,6 @@ from pre import preprocess_csv, load_data, fill_missing_data
|
|
9 |
|
10 |
|
11 |
|
12 |
-
|
13 |
def single_main(uploaded_file):
|
14 |
# st.title('Single CSV Analyzer')
|
15 |
|
@@ -33,7 +32,14 @@ def single_main(uploaded_file):
|
|
33 |
# Display scenarios with status "failed" grouped by functional area
|
34 |
failed_scenarios = data[data['Status'] == 'FAILED']
|
35 |
passed_scenarios = data[data['Status'] == 'PASSED']
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
# Use radio buttons for selecting status
|
38 |
selected_status = st.radio("Select a status", ['Failed', 'Passed'])
|
39 |
|
@@ -41,11 +47,9 @@ def single_main(uploaded_file):
|
|
41 |
if selected_status == 'Failed':
|
42 |
unique_areas = np.append(failed_scenarios['Functional area'].unique(), "All")
|
43 |
selected_scenarios = failed_scenarios
|
44 |
-
selected_functional_area = st.selectbox("Select a functional area", unique_areas, index=len(unique_areas)-1)
|
45 |
elif selected_status == 'Passed':
|
46 |
unique_areas = np.append(passed_scenarios['Functional area'].unique(), "All")
|
47 |
selected_scenarios = passed_scenarios
|
48 |
-
selected_functional_area = st.selectbox("Select a functional area", unique_areas, index=len(unique_areas)-1)
|
49 |
else:
|
50 |
selected_scenarios = None
|
51 |
|
@@ -53,68 +57,76 @@ def single_main(uploaded_file):
|
|
53 |
# st.write(f"Scenarios with status '{selected_status}' grouped by functional area:")
|
54 |
st.markdown(f"### Scenarios with status '{selected_status}' grouped by functional area:")
|
55 |
|
56 |
-
#
|
57 |
-
|
58 |
-
if selected_functional_area != "All":
|
59 |
-
filtered_scenarios = selected_scenarios[selected_scenarios['Functional area'] == selected_functional_area]
|
60 |
-
else:
|
61 |
-
filtered_scenarios = selected_scenarios
|
62 |
-
|
63 |
-
# Calculate the average time spent for each functional area
|
64 |
-
average_time_spent_seconds = filtered_scenarios.groupby('Functional area')['Time spent'].mean().reset_index()
|
65 |
-
|
66 |
-
# Convert average time spent from seconds to minutes and seconds format
|
67 |
-
average_time_spent_seconds['Time spent'] = pd.to_datetime(average_time_spent_seconds['Time spent'], unit='s').dt.strftime('%M:%S')
|
68 |
-
|
69 |
-
# Group by functional area and get the start datetime for sorting
|
70 |
-
start_datetime_group = filtered_scenarios.groupby('Functional area')['Start datetime'].min().reset_index()
|
71 |
-
|
72 |
-
# Merge average_time_spent_seconds and start_datetime_group
|
73 |
-
average_time_spent_seconds = average_time_spent_seconds.merge(start_datetime_group, on='Functional area')
|
74 |
-
|
75 |
-
# Filter scenarios based on selected functional area
|
76 |
-
if selected_status == 'Failed':
|
77 |
-
grouped_filtered_failed_scenarios = filtered_scenarios.groupby('Functional area')[['Scenario name', 'Error message','Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
78 |
-
elif selected_status == 'Passed':
|
79 |
-
grouped_filtered_failed_scenarios = filtered_scenarios.groupby('Functional area')[['Scenario name', 'Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
80 |
-
else:
|
81 |
-
grouped_filtered_failed_scenarios = None
|
82 |
-
|
83 |
-
|
84 |
-
grouped_filtered_failed_scenarios.reset_index(inplace=True)
|
85 |
-
grouped_filtered_failed_scenarios.drop(columns=['level_1'], inplace=True)
|
86 |
-
# grouped_filtered_failed_scenarios['level_1'] = index
|
87 |
-
grouped_filtered_failed_scenarios.index = grouped_filtered_failed_scenarios.index + 1
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
st.write(f"Failing scenarios Count: {fail_count}")
|
94 |
-
# Display total count of Passing
|
95 |
-
pass_count = len(passed_scenarios)
|
96 |
-
st.write(f"Passing scenarios Count: {pass_count}")
|
97 |
-
|
98 |
-
# Sort the average time spent table by start datetime
|
99 |
-
average_time_spent_seconds = average_time_spent_seconds.sort_values(by='Start datetime')
|
100 |
-
|
101 |
-
# Display average time spent on each functional area in a table
|
102 |
-
st.markdown("### Average Time Spent on Each Functional Area")
|
103 |
-
average_time_spent_seconds.index = average_time_spent_seconds.index + 1
|
104 |
-
st.dataframe(average_time_spent_seconds)
|
105 |
-
|
106 |
-
# Create and display bar graph of errors by functional area
|
107 |
-
st.write("### Bar graph showing number of failures in each functional area:")
|
108 |
-
error_counts = failed_scenarios['Functional area'].value_counts()
|
109 |
-
plt.figure(figsize=(10, 6))
|
110 |
-
plt.bar(error_counts.index, error_counts.values)
|
111 |
-
plt.xlabel('Functional Area')
|
112 |
-
plt.ylabel('Number of Errors')
|
113 |
-
plt.title('Number of Errors by Functional Area')
|
114 |
-
plt.xticks(rotation=45, ha='right')
|
115 |
-
plt.tight_layout() # Add this line to adjust layout
|
116 |
-
st.pyplot(plt)
|
117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
else:
|
119 |
st.write("### No scenarios with status 'failed' found.")
|
120 |
pass
|
|
|
1 |
import pandas as pd
|
2 |
import streamlit as st
|
3 |
import csv
|
4 |
+
import io, os
|
5 |
import matplotlib.pyplot as plt
|
6 |
import numpy as np
|
7 |
from second import double_main
|
|
|
9 |
|
10 |
|
11 |
|
|
|
12 |
def single_main(uploaded_file):
|
13 |
# st.title('Single CSV Analyzer')
|
14 |
|
|
|
32 |
# Display scenarios with status "failed" grouped by functional area
|
33 |
failed_scenarios = data[data['Status'] == 'FAILED']
|
34 |
passed_scenarios = data[data['Status'] == 'PASSED']
|
35 |
+
|
36 |
+
# Display total count of failures
|
37 |
+
fail_count = len(failed_scenarios)
|
38 |
+
st.markdown(f"Failing scenarios Count: {fail_count}")
|
39 |
+
# Display total count of Passing
|
40 |
+
pass_count = len(passed_scenarios)
|
41 |
+
st.markdown(f"Passing scenarios Count: {pass_count}")
|
42 |
+
|
43 |
# Use radio buttons for selecting status
|
44 |
selected_status = st.radio("Select a status", ['Failed', 'Passed'])
|
45 |
|
|
|
47 |
if selected_status == 'Failed':
|
48 |
unique_areas = np.append(failed_scenarios['Functional area'].unique(), "All")
|
49 |
selected_scenarios = failed_scenarios
|
|
|
50 |
elif selected_status == 'Passed':
|
51 |
unique_areas = np.append(passed_scenarios['Functional area'].unique(), "All")
|
52 |
selected_scenarios = passed_scenarios
|
|
|
53 |
else:
|
54 |
selected_scenarios = None
|
55 |
|
|
|
57 |
# st.write(f"Scenarios with status '{selected_status}' grouped by functional area:")
|
58 |
st.markdown(f"### Scenarios with status '{selected_status}' grouped by functional area:")
|
59 |
|
60 |
+
# Select a range of functional areas to filter scenarios
|
61 |
+
selected_functional_areas = st.multiselect("Select functional areas", unique_areas, ["All"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
+
if "All" in selected_functional_areas:
|
64 |
+
filtered_scenarios = selected_scenarios
|
65 |
+
else:
|
66 |
+
filtered_scenarios = selected_scenarios[selected_scenarios['Functional area'].isin(selected_functional_areas)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
+
if not selected_functional_areas: # Check if the list is empty
|
69 |
+
st.error("Please select at least one functional area.")
|
70 |
+
else:
|
71 |
+
# Calculate the average time spent for each functional area
|
72 |
+
average_time_spent_seconds = filtered_scenarios.groupby('Functional area')['Time spent'].mean().reset_index()
|
73 |
+
|
74 |
+
# Convert average time spent from seconds to minutes and seconds format
|
75 |
+
average_time_spent_seconds['Time spent'] = pd.to_datetime(average_time_spent_seconds['Time spent'], unit='s').dt.strftime('%M:%S')
|
76 |
+
|
77 |
+
# Group by functional area and get the start datetime for sorting
|
78 |
+
start_datetime_group = filtered_scenarios.groupby('Functional area')['Start datetime'].min().reset_index()
|
79 |
+
|
80 |
+
# Merge average_time_spent_seconds and start_datetime_group
|
81 |
+
average_time_spent_seconds = average_time_spent_seconds.merge(start_datetime_group, on='Functional area')
|
82 |
+
|
83 |
+
# Filter scenarios based on selected functional area
|
84 |
+
if selected_status == 'Failed':
|
85 |
+
grouped_filtered_scenarios = filtered_scenarios.groupby('Functional area')[['Scenario name', 'Error message','Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
86 |
+
elif selected_status == 'Passed':
|
87 |
+
grouped_filtered_scenarios = filtered_scenarios.groupby('Functional area')[['Scenario name', 'Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
88 |
+
else:
|
89 |
+
grouped_filtered_scenarios = None
|
90 |
+
|
91 |
+
|
92 |
+
grouped_filtered_scenarios.reset_index(inplace=True)
|
93 |
+
grouped_filtered_scenarios.drop(columns=['level_1'], inplace=True)
|
94 |
+
# grouped_filtered_scenarios['level_1'] = index
|
95 |
+
grouped_filtered_scenarios.index = grouped_filtered_scenarios.index + 1
|
96 |
+
|
97 |
+
st.dataframe(grouped_filtered_scenarios)
|
98 |
+
|
99 |
+
# Sort the average time spent table by start datetime
|
100 |
+
average_time_spent_seconds = average_time_spent_seconds.sort_values(by='Start datetime')
|
101 |
+
|
102 |
+
# Display average time spent on each functional area in a table
|
103 |
+
st.markdown("### Average Time Spent on Each Functional Area")
|
104 |
+
average_time_spent_seconds.index = average_time_spent_seconds.index + 1
|
105 |
+
st.dataframe(average_time_spent_seconds)
|
106 |
+
|
107 |
+
# Check if selected_status is 'Failed' and grouped_filtered_scenarios length is less than or equal to 400
|
108 |
+
if selected_status != 'Passed' and len(grouped_filtered_scenarios) <= 400:
|
109 |
+
# Create and display bar graph of errors by functional area
|
110 |
+
st.write(f"### Bar graph showing number of '{selected_status}' scenarios in each functional area:")
|
111 |
+
error_counts = grouped_filtered_scenarios['Functional area'].value_counts()
|
112 |
+
plt.figure(figsize=(10, 6))
|
113 |
+
plt.bar(error_counts.index, error_counts.values)
|
114 |
+
plt.xlabel('Functional Area')
|
115 |
+
plt.ylabel('Number of Failures')
|
116 |
+
plt.title(f"Number of '{selected_status}' scenarios by Functional Area")
|
117 |
+
plt.xticks(rotation=45, ha='right')
|
118 |
+
|
119 |
+
# Set y-axis limits and ticks for consistent interval of 1
|
120 |
+
y_max = max(error_counts.values) + 1
|
121 |
+
plt.ylim(0, y_max)
|
122 |
+
plt.yticks(range(0, y_max, 1))
|
123 |
+
|
124 |
+
# Display individual numbers on y-axis
|
125 |
+
for i, count in enumerate(error_counts.values):
|
126 |
+
plt.text(i, count, str(count), ha='center', va='bottom')
|
127 |
+
|
128 |
+
plt.tight_layout() # Add this line to adjust layout
|
129 |
+
st.pyplot(plt)
|
130 |
else:
|
131 |
st.write("### No scenarios with status 'failed' found.")
|
132 |
pass
|