Spaces:
Sleeping
Sleeping
Commit
·
a8d73d1
1
Parent(s):
cf4c4b7
Update second.py
Browse files
second.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
|
|
|
2 |
import streamlit as st
|
3 |
import csv
|
4 |
import io
|
@@ -6,63 +7,107 @@ import matplotlib.pyplot as plt
|
|
6 |
import numpy as np
|
7 |
from pre import preprocess_uploaded_file
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Import necessary libraries
|
2 |
+
import pandas as pd
|
3 |
import streamlit as st
|
4 |
import csv
|
5 |
import io
|
|
|
7 |
import numpy as np
|
8 |
from pre import preprocess_uploaded_file
|
9 |
|
10 |
+
# Main function to process 2 uploaded CSV files
|
11 |
+
def double_main(uploaded_file1,uploaded_file2):
|
12 |
|
13 |
+
# Check if both files are uploaded
|
14 |
+
if uploaded_file1 is not None and uploaded_file2 is not None:
|
15 |
+
|
16 |
+
# Preprocess the uploaded CSV files
|
17 |
+
data_1 = preprocess_uploaded_file(uploaded_file1)
|
18 |
+
data_2 = preprocess_uploaded_file(uploaded_file2)
|
19 |
+
|
20 |
+
# Determine which file is older and newer
|
21 |
+
if data_1['Start datetime'].min() < data_2['Start datetime'].min():
|
22 |
+
older_df = data_1
|
23 |
+
newer_df = data_2
|
24 |
+
else:
|
25 |
+
older_df = data_2
|
26 |
+
newer_df = data_1
|
27 |
+
|
28 |
+
# Convert time columns to MM:SS format
|
29 |
+
older_df['Time spent'] = pd.to_datetime(older_df['Time spent'], unit='s').dt.strftime('%M:%S')
|
30 |
+
newer_df['Time spent'] = pd.to_datetime(newer_df['Time spent'], unit='s').dt.strftime('%M:%S')
|
31 |
+
|
32 |
+
# Get start datetime of each file
|
33 |
+
older_datetime = older_df['Start datetime'].min()
|
34 |
+
newer_datetime = newer_df['Start datetime'].min()
|
35 |
+
|
36 |
+
# Display start datetime of each file
|
37 |
+
st.write(f"The older csv started on {older_datetime}")
|
38 |
+
st.write(f"The newer csv started on {newer_datetime}")
|
39 |
+
|
40 |
+
# Merge dataframes on 'scenario name'
|
41 |
+
merged_df = pd.merge(older_df, newer_df, on=['Functional area', 'Scenario name'], suffixes=('_old', '_new'))
|
42 |
+
|
43 |
+
# Filter scenarios that were failing and are still failing
|
44 |
+
fail_to_fail_scenarios = merged_df[(merged_df['Status_old'] == 'FAILED') & (merged_df['Status_new'] == 'FAILED')]
|
45 |
+
|
46 |
+
# Display Consistent Failures section
|
47 |
+
st.markdown("### Consistent Failures(previously failing, now failing)")
|
48 |
+
|
49 |
+
# Get failing scenarios count
|
50 |
+
fail_count = len(fail_to_fail_scenarios)
|
51 |
+
st.write(f"Failing scenarios Count: {fail_count}")
|
52 |
+
|
53 |
+
# Display filtered dataframe
|
54 |
+
columns_to_display1 = ['Functional area', 'Scenario name', 'Error message_old', 'Error message_new']
|
55 |
+
st.write(fail_to_fail_scenarios[columns_to_display1])
|
56 |
+
|
57 |
+
# Filter scenarios that were passing and now failing
|
58 |
+
pass_to_fail_scenarios = merged_df[(merged_df['Status_old'] == 'PASSED') & (merged_df['Status_new'] == 'FAILED')]
|
59 |
+
|
60 |
+
# Display New Failures section
|
61 |
+
st.markdown("### New Failures(previously passing, now failing)")
|
62 |
+
|
63 |
+
# Get failing scenarios count
|
64 |
+
pass_fail_count = len(pass_to_fail_scenarios)
|
65 |
+
st.write(f"Failing scenarios Count: {pass_fail_count}")
|
66 |
+
|
67 |
+
# Display filtered dataframe
|
68 |
+
columns_to_display2 = ['Functional area', 'Scenario name', 'Error message_new', 'Time spent_old','Time spent_new',]
|
69 |
+
st.write(pass_to_fail_scenarios[columns_to_display2])
|
70 |
+
|
71 |
+
# Filter scenarios that were failing and now passing
|
72 |
+
fail_to_pass_scenarios = merged_df[(merged_df['Status_old'] == 'FAILED') & (merged_df['Status_new'] == 'PASSED')]
|
73 |
+
|
74 |
+
# Display New Passes section
|
75 |
+
st.markdown("### New Passes(previously failing, now passing)")
|
76 |
+
|
77 |
+
# Get passing scenarios count
|
78 |
+
pass_count = len(fail_to_pass_scenarios)
|
79 |
+
st.write(f"Passing scenarios Count: {pass_count}")
|
80 |
+
|
81 |
+
# Display filtered dataframe
|
82 |
+
columns_to_display3 = ['Functional area', 'Scenario name', 'Error message_old', 'Time spent_old','Time spent_new',]
|
83 |
+
st.write(fail_to_pass_scenarios[columns_to_display3])
|
84 |
+
|
85 |
+
|
86 |
+
# Create a Pandas Excel writer using XlsxWriter as the engine
|
87 |
+
excel_writer = pd.ExcelWriter('comparison_results.xlsx', engine='xlsxwriter')
|
88 |
+
|
89 |
+
# Write each section to a separate sheet
|
90 |
+
fail_to_fail_scenarios.loc[:, columns_to_display1].to_excel(excel_writer, sheet_name='Consistent Failures', index=False)
|
91 |
+
pass_to_fail_scenarios.loc[:, columns_to_display2].to_excel(excel_writer, sheet_name='New Failures', index=False)
|
92 |
+
fail_to_pass_scenarios.loc[:, columns_to_display3].to_excel(excel_writer, sheet_name='New Passes', index=False)
|
93 |
+
|
94 |
+
|
95 |
+
|
96 |
+
# Add a sheet to store information about CSV versions
|
97 |
+
csv_version_sheet = excel_writer.book.add_worksheet('CSV Details')
|
98 |
+
|
99 |
+
# Write the CSV version information
|
100 |
+
csv_version_sheet.write('A1', 'Older CSV:')
|
101 |
+
csv_version_sheet.write('B1', 'Newer CSV:')
|
102 |
+
csv_version_sheet.write('A2', older_df['Start datetime'].min().strftime('%Y-%m-%d %H:%M:%S'))
|
103 |
+
csv_version_sheet.write('B2', newer_df['Start datetime'].min().strftime('%Y-%m-%d %H:%M:%S'))
|
104 |
+
|
105 |
+
# Save the Excel file
|
106 |
+
excel_writer.save()
|
107 |
+
|
108 |
+
# Create a Download Excel button
|
109 |
+
st.markdown("### Download Excel Report")
|
110 |
+
st.markdown("Click below to download the comparison results in Excel format:")
|
111 |
+
with open('comparison_results.xlsx', 'rb') as excel_file:
|
112 |
+
excel_bytes = excel_file.read()
|
113 |
+
st.download_button(label='Download Excel Report', data=excel_bytes, file_name='comparison_results.xlsx', key='excel-download')
|