Spaces:
Sleeping
Sleeping
Commit
·
7a2556d
1
Parent(s):
83c336a
Update multiple.py
Browse files- multiple.py +25 -15
multiple.py
CHANGED
|
@@ -49,31 +49,49 @@ def perform_analysis(uploaded_dataframes):
|
|
| 49 |
average_time_spent_seconds = filtered_scenarios.groupby('Functional area')['Time spent'].mean().reset_index()
|
| 50 |
# Convert average time spent from seconds to minutes and seconds format
|
| 51 |
average_time_spent_seconds['Time spent'] = pd.to_datetime(average_time_spent_seconds['Time spent'], unit='s').dt.strftime('%M:%S')
|
|
|
|
|
|
|
| 52 |
# Group by functional area and get the start datetime for sorting
|
| 53 |
start_datetime_group = filtered_scenarios.groupby('Functional area')['Start datetime'].min().reset_index()
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
average_time_spent_seconds = average_time_spent_seconds.merge(start_datetime_group, on='Functional area')
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
if selected_status == 'Failed':
|
| 58 |
-
grouped_filtered_scenarios = filtered_scenarios.groupby('Environment')[['Functional area', 'Scenario name', 'Error message','Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
| 59 |
elif selected_status == 'Passed':
|
| 60 |
grouped_filtered_scenarios = filtered_scenarios.groupby('Functional area')[['Scenario name', 'Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
| 61 |
else:
|
| 62 |
grouped_filtered_scenarios = None
|
| 63 |
grouped_filtered_scenarios.reset_index(inplace=True)
|
| 64 |
grouped_filtered_scenarios.drop(columns=['level_1'], inplace=True)
|
| 65 |
-
# grouped_filtered_scenarios['level_1'] = index
|
| 66 |
grouped_filtered_scenarios.index = grouped_filtered_scenarios.index + 1
|
| 67 |
-
st.dataframe(grouped_filtered_scenarios)
|
|
|
|
| 68 |
# Sort the average time spent table by start datetime
|
| 69 |
average_time_spent_seconds = average_time_spent_seconds.sort_values(by='Start datetime')
|
| 70 |
|
| 71 |
# Display average time spent on each functional area in a table
|
| 72 |
-
st.markdown("### Average Time Spent on Each Functional Area")
|
| 73 |
average_time_spent_seconds.index = average_time_spent_seconds.index + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
st.dataframe(average_time_spent_seconds)
|
| 75 |
|
| 76 |
-
# Check if selected_status is 'Failed' and
|
| 77 |
if selected_status != 'Passed':
|
| 78 |
# Create and display bar graph of errors by functional area
|
| 79 |
st.write(f"### Bar graph showing number of '{selected_status}' scenarios in each functional area:")
|
|
@@ -114,14 +132,6 @@ def multiple_main():
|
|
| 114 |
for uploaded_file in uploaded_files:
|
| 115 |
# Preprocess the uploaded CSV file
|
| 116 |
data = preprocess_uploaded_file(uploaded_file)
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
# Extract environment name from filename
|
| 120 |
-
filename = uploaded_file.name
|
| 121 |
-
environment = filename.split('_Puppeteer')[0]
|
| 122 |
-
|
| 123 |
-
# Add environment column to the dataframe
|
| 124 |
-
data['Environment'] = environment
|
| 125 |
|
| 126 |
# Append the dataframe to the list
|
| 127 |
uploaded_dataframes.append(data)
|
|
|
|
| 49 |
average_time_spent_seconds = filtered_scenarios.groupby('Functional area')['Time spent'].mean().reset_index()
|
| 50 |
# Convert average time spent from seconds to minutes and seconds format
|
| 51 |
average_time_spent_seconds['Time spent'] = pd.to_datetime(average_time_spent_seconds['Time spent'], unit='s').dt.strftime('%M:%S')
|
| 52 |
+
|
| 53 |
+
|
| 54 |
# Group by functional area and get the start datetime for sorting
|
| 55 |
start_datetime_group = filtered_scenarios.groupby('Functional area')['Start datetime'].min().reset_index()
|
| 56 |
+
end_datetime_group = filtered_scenarios.groupby('Functional area')['End datetime'].max().reset_index()
|
| 57 |
+
|
| 58 |
+
# Calculate the total time spent for each functional area (difference between end and start datetime)
|
| 59 |
+
total_time_spent_seconds = (end_datetime_group['End datetime'] - start_datetime_group['Start datetime']).dt.total_seconds()
|
| 60 |
+
|
| 61 |
+
# Convert total time spent from seconds to minutes and seconds format
|
| 62 |
+
total_time_spent_seconds = pd.to_datetime(total_time_spent_seconds, unit='s').dt.strftime('%M:%S')
|
| 63 |
+
|
| 64 |
+
# Merge the average_time_spent_seconds with start_datetime_group and end_datetime_group
|
| 65 |
average_time_spent_seconds = average_time_spent_seconds.merge(start_datetime_group, on='Functional area')
|
| 66 |
+
average_time_spent_seconds = average_time_spent_seconds.merge(end_datetime_group, on='Functional area')
|
| 67 |
+
average_time_spent_seconds['Total Time Spent'] = total_time_spent_seconds
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Filter scenarios based on selected functional area
|
| 71 |
if selected_status == 'Failed':
|
| 72 |
+
grouped_filtered_scenarios = filtered_scenarios.groupby('Environment')[['Functional area', 'Scenario name', 'Error message','Time spent(m:s)','Start datetime']].apply(lambda x: x.reset_index(drop=True))
|
| 73 |
elif selected_status == 'Passed':
|
| 74 |
grouped_filtered_scenarios = filtered_scenarios.groupby('Functional area')[['Scenario name', 'Time spent(m:s)']].apply(lambda x: x.reset_index(drop=True))
|
| 75 |
else:
|
| 76 |
grouped_filtered_scenarios = None
|
| 77 |
grouped_filtered_scenarios.reset_index(inplace=True)
|
| 78 |
grouped_filtered_scenarios.drop(columns=['level_1'], inplace=True)
|
|
|
|
| 79 |
grouped_filtered_scenarios.index = grouped_filtered_scenarios.index + 1
|
| 80 |
+
st.dataframe(grouped_filtered_scenarios)
|
| 81 |
+
|
| 82 |
# Sort the average time spent table by start datetime
|
| 83 |
average_time_spent_seconds = average_time_spent_seconds.sort_values(by='Start datetime')
|
| 84 |
|
| 85 |
# Display average time spent on each functional area in a table
|
| 86 |
+
st.markdown("### Total and Average Time Spent on Each Functional Area")
|
| 87 |
average_time_spent_seconds.index = average_time_spent_seconds.index + 1
|
| 88 |
+
# Rename the columns for clarity
|
| 89 |
+
average_time_spent_seconds.rename(columns={'Start datetime': 'Start Datetime', 'End datetime': 'End Datetime', 'Time spent':'Average Time Spent'}, inplace=True)
|
| 90 |
+
# Rearrange the columns
|
| 91 |
+
average_time_spent_seconds = average_time_spent_seconds[['Functional area', 'Total Time Spent', 'Start Datetime', 'End Datetime', 'Average Time Spent']]
|
| 92 |
st.dataframe(average_time_spent_seconds)
|
| 93 |
|
| 94 |
+
# Check if selected_status is 'Failed' and grouped_filtered_scenarifos length is less than or equal to 400
|
| 95 |
if selected_status != 'Passed':
|
| 96 |
# Create and display bar graph of errors by functional area
|
| 97 |
st.write(f"### Bar graph showing number of '{selected_status}' scenarios in each functional area:")
|
|
|
|
| 132 |
for uploaded_file in uploaded_files:
|
| 133 |
# Preprocess the uploaded CSV file
|
| 134 |
data = preprocess_uploaded_file(uploaded_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
# Append the dataframe to the list
|
| 137 |
uploaded_dataframes.append(data)
|