BananaSauce commited on
Commit
30590ff
·
verified ·
1 Parent(s): 337328d

Updated ui look for second.py compare

Browse files
Files changed (1) hide show
  1. second.py +107 -89
second.py CHANGED
@@ -1,18 +1,15 @@
1
- # Import necessary libraries
2
  import pandas as pd
3
  import streamlit as st
4
- import csv
5
- import io
6
- import matplotlib.pyplot as plt
7
- import numpy as np
8
  from pre import preprocess_uploaded_file
9
 
 
 
10
 
11
- # Main function to process 2 uploaded CSV files
12
- def double_main(uploaded_file1,uploaded_file2):
13
-
14
- # Check if both files are uploaded
15
- if uploaded_file1 is not None and uploaded_file2 is not None:
16
 
17
  # Preprocess the uploaded CSV files
18
  data_1 = preprocess_uploaded_file(uploaded_file1)
@@ -20,16 +17,14 @@ def double_main(uploaded_file1,uploaded_file2):
20
 
21
  # Determine which file is older and newer
22
  if data_1['Start datetime'].min() < data_2['Start datetime'].min():
23
- older_df = data_1
24
- newer_df = data_2
25
  else:
26
- older_df = data_2
27
- newer_df = data_1
28
 
29
  # Convert time columns to MM:SS format
30
  older_df['Time spent'] = pd.to_datetime(older_df['Time spent'], unit='s').dt.strftime('%M:%S')
31
  newer_df['Time spent'] = pd.to_datetime(newer_df['Time spent'], unit='s').dt.strftime('%M:%S')
32
-
33
  # Get start datetime of each file
34
  older_datetime = older_df['Start datetime'].min()
35
  newer_datetime = newer_df['Start datetime'].min()
@@ -41,84 +36,107 @@ def double_main(uploaded_file1,uploaded_file2):
41
  # Merge dataframes on 'scenario name'
42
  merged_df = pd.merge(older_df, newer_df, on=['Functional area', 'Scenario name'], suffixes=('_old', '_new'))
43
 
44
- # Filter scenarios that were failing and are still failing
45
  fail_to_fail_scenarios = merged_df[(merged_df['Status_old'] == 'FAILED') & (merged_df['Status_new'] == 'FAILED')]
46
-
47
- # Display Consistent Failures section
48
- st.markdown("### Consistent Failures(previously failing, now failing)")
49
-
50
- # Get failing scenarios count
51
- fail_count = len(fail_to_fail_scenarios)
52
- st.write(f"Failing scenarios Count: {fail_count}")
53
-
54
- # Display filtered dataframe
55
- columns_to_display1 = ['Functional area', 'Scenario name', 'Error message_old', 'Error message_new']
56
- st.write(fail_to_fail_scenarios[columns_to_display1])
57
-
58
- # Filter scenarios that were passing and now failing
59
  pass_to_fail_scenarios = merged_df[(merged_df['Status_old'] == 'PASSED') & (merged_df['Status_new'] == 'FAILED')]
 
60
 
61
- # Display New Failures section
62
- st.markdown("### New Failures(previously passing, now failing)")
63
-
64
- # Get failing scenarios count
65
  pass_fail_count = len(pass_to_fail_scenarios)
66
- st.write(f"Failing scenarios Count: {pass_fail_count}")
67
-
68
- # Display filtered dataframe
69
- columns_to_display2 = ['Functional area', 'Scenario name', 'Error message_new', 'Time spent_old','Time spent_new',]
70
- st.write(pass_to_fail_scenarios[columns_to_display2])
71
-
72
- # Filter scenarios that were failing and now passing
73
- fail_to_pass_scenarios = merged_df[(merged_df['Status_old'] == 'FAILED') & (merged_df['Status_new'] == 'PASSED')]
74
 
75
- # Display New Passes section
76
- st.markdown("### New Passes(previously failing, now passing)")
 
 
 
 
 
77
 
78
- # Get passing scenarios count
79
- pass_count = len(fail_to_pass_scenarios)
80
- st.write(f"Passing scenarios Count: {pass_count}")
81
-
82
- # Display filtered dataframe
83
- columns_to_display3 = ['Functional area', 'Scenario name', 'Error message_old', 'Time spent_old','Time spent_new',]
84
- st.write(fail_to_pass_scenarios[columns_to_display3])
85
-
86
-
87
- # Create a Pandas Excel writer using XlsxWriter as the engine
88
- try:
89
- # Create a Pandas Excel writer using XlsxWriter as the engine
90
- excel_writer = pd.ExcelWriter('comparison_results.xlsx', engine='xlsxwriter')
91
-
92
- # Write each section to a separate sheet
93
- fail_to_fail_scenarios.loc[:, columns_to_display1].to_excel(excel_writer, sheet_name='Consistent Failures', index=False)
94
- pass_to_fail_scenarios.loc[:, columns_to_display2].to_excel(excel_writer, sheet_name='New Failures', index=False)
95
- fail_to_pass_scenarios.loc[:, columns_to_display3].to_excel(excel_writer, sheet_name='New Passes', index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
 
97
- # Add a sheet to store information about CSV versions
98
- csv_version_sheet = excel_writer.book.add_worksheet('CSV Details')
99
-
100
- # Write the CSV version information
101
- csv_version_sheet.write('A1', 'Older CSV:')
102
- csv_version_sheet.write('B1', 'Newer CSV:')
103
- csv_version_sheet.write('A2', older_df['Start datetime'].min().strftime('%Y-%m-%d %H:%M:%S'))
104
- csv_version_sheet.write('B2', newer_df['Start datetime'].min().strftime('%Y-%m-%d %H:%M:%S'))
105
-
106
- except Exception as e:
107
- print(f"Error encountered: {e}")
108
- # Handle or print the error
109
- pass
110
-
111
- try:
112
- # Save the Excel file
113
- excel_writer.close()
114
- except Exception as e:
115
- print(f"Error encountered during saving: {e}")
116
- # Handle or print the error
117
- pass
118
-
119
- # Create a Download Excel button
120
- st.markdown("### Download Excel Report")
121
- st.markdown("Click below to download the comparison results in Excel format:")
122
- with open('comparison_results.xlsx', 'rb') as excel_file:
123
- excel_bytes = excel_file.read()
124
- st.download_button(label='Download Excel Report', data=excel_bytes, file_name='comparison_results.xlsx', key='excel-download')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import streamlit as st
3
+ import plotly.graph_objects as go
 
 
 
4
  from pre import preprocess_uploaded_file
5
 
6
+ def convert_df(df):
7
+ return df.to_csv(index=False).encode('utf-8')
8
 
9
+ def double_main(uploaded_file1, uploaded_file2):
10
+ if uploaded_file1 is None or uploaded_file2 is None:
11
+ st.warning("Please upload both CSV files for comparison.")
12
+ return
 
13
 
14
  # Preprocess the uploaded CSV files
15
  data_1 = preprocess_uploaded_file(uploaded_file1)
 
17
 
18
  # Determine which file is older and newer
19
  if data_1['Start datetime'].min() < data_2['Start datetime'].min():
20
+ older_df, newer_df = data_1, data_2
 
21
  else:
22
+ older_df, newer_df = data_2, data_1
 
23
 
24
  # Convert time columns to MM:SS format
25
  older_df['Time spent'] = pd.to_datetime(older_df['Time spent'], unit='s').dt.strftime('%M:%S')
26
  newer_df['Time spent'] = pd.to_datetime(newer_df['Time spent'], unit='s').dt.strftime('%M:%S')
27
+
28
  # Get start datetime of each file
29
  older_datetime = older_df['Start datetime'].min()
30
  newer_datetime = newer_df['Start datetime'].min()
 
36
  # Merge dataframes on 'scenario name'
37
  merged_df = pd.merge(older_df, newer_df, on=['Functional area', 'Scenario name'], suffixes=('_old', '_new'))
38
 
39
+ # Filter scenarios
40
  fail_to_fail_scenarios = merged_df[(merged_df['Status_old'] == 'FAILED') & (merged_df['Status_new'] == 'FAILED')]
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  pass_to_fail_scenarios = merged_df[(merged_df['Status_old'] == 'PASSED') & (merged_df['Status_new'] == 'FAILED')]
42
+ fail_to_pass_scenarios = merged_df[(merged_df['Status_old'] == 'FAILED') & (merged_df['Status_new'] == 'PASSED')]
43
 
44
+ # Get counts
45
+ fail_count = len(fail_to_fail_scenarios)
 
 
46
  pass_fail_count = len(pass_to_fail_scenarios)
47
+ pass_count = len(fail_to_pass_scenarios)
 
 
 
 
 
 
 
48
 
49
+ # Display summary chart
50
+ status_counts = {
51
+ 'Consistent Failures': fail_count,
52
+ 'New Failures': pass_fail_count,
53
+ 'New Passes': pass_count
54
+ }
55
+ status_df = pd.DataFrame.from_dict(status_counts, orient='index', columns=['Count'])
56
 
57
+ st.subheader("Summary of Scenario Status Changes")
58
+
59
+ # Create a bar chart using Plotly
60
+ fig = go.Figure(data=[
61
+ go.Bar(
62
+ x=status_df.index,
63
+ y=status_df['Count'],
64
+ text=status_df['Count'],
65
+ textposition='outside',
66
+ textfont=dict(size=14),
67
+ marker_color=['#1f77b4', '#ff7f0e', '#2ca02c'], # Custom colors for each bar
68
+ width=0.6 # Adjust bar width
69
+ )
70
+ ])
71
+
72
+ # Customize the layout
73
+ fig.update_layout(
74
+ yaxis=dict(
75
+ title='Count',
76
+ range=[0, max(status_df['Count']) * 1.1] # Extend y-axis range by 10% to fit labels
77
+ ),
78
+ xaxis_title="Status",
79
+ hoverlabel=dict(bgcolor="white", font_size=16),
80
+ margin=dict(l=20, r=20, t=40, b=20),
81
+ uniformtext_minsize=8,
82
+ uniformtext_mode='hide'
83
+ )
84
+
85
+ # Ensure all bars are visible
86
+ fig.update_traces(marker_line_width=1, marker_line_color="black", selector=dict(type="bar"))
87
+
88
+ # Add hover text
89
+ fig.update_traces(
90
+ hovertemplate="<b>%{x}</b><br>Count: %{y}<extra></extra>"
91
+ )
92
 
93
+ # Display the chart
94
+ st.plotly_chart(fig, use_container_width=True)
95
+
96
+ # Use tabs to display data
97
+ tab1, tab2, tab3 = st.tabs(["Consistent Failures", "New Failures", "New Passes"])
98
+
99
+ with tab1:
100
+ st.write(f"Failing scenarios Count: {fail_count}")
101
+ columns_to_display1 = ['Functional area', 'Scenario name', 'Error message_old', 'Error message_new']
102
+ st.dataframe(fail_to_fail_scenarios[columns_to_display1])
103
+ csv = convert_df(fail_to_fail_scenarios[columns_to_display1])
104
+ st.download_button("Download Consistent Failures as CSV", data=csv, file_name='consistent_failures.csv', mime='text/csv')
105
+
106
+ with tab2:
107
+ st.write(f"Failing scenarios Count: {pass_fail_count}")
108
+ columns_to_display2 = ['Functional area', 'Scenario name', 'Error message_new', 'Time spent_old', 'Time spent_new']
109
+ st.dataframe(pass_to_fail_scenarios[columns_to_display2])
110
+ csv = convert_df(pass_to_fail_scenarios[columns_to_display2])
111
+ st.download_button("Download New Failures as CSV", data=csv, file_name='new_failures.csv', mime='text/csv')
112
+
113
+ with tab3:
114
+ st.write(f"Passing scenarios Count: {pass_count}")
115
+ columns_to_display3 = ['Functional area', 'Scenario name', 'Error message_old', 'Time spent_old', 'Time spent_new']
116
+ st.dataframe(fail_to_pass_scenarios[columns_to_display3])
117
+ csv = convert_df(fail_to_pass_scenarios[columns_to_display3])
118
+ st.download_button("Download New Passes as CSV", data=csv, file_name='new_passes.csv', mime='text/csv')
119
+
120
+ def main():
121
+ st.title("CSV Comparison Tool")
122
+
123
+ st.markdown("""
124
+ This tool compares two CSV files and highlights the differences in the scenarios.
125
+ Please upload the older and newer CSV files below.
126
+ """)
127
+
128
+ col1, col2 = st.columns(2)
129
+
130
+ with col1:
131
+ uploaded_file1 = st.file_uploader("Upload the older CSV file", type='csv', key='uploader1')
132
+
133
+ with col2:
134
+ uploaded_file2 = st.file_uploader("Upload the newer CSV file", type='csv', key='uploader2')
135
+
136
+ if uploaded_file1 is not None and uploaded_file2 is not None:
137
+ with st.spinner('Processing...'):
138
+ double_main(uploaded_file1, uploaded_file2)
139
+ st.success('Comparison Complete!')
140
+
141
+ if __name__ == "__main__":
142
+ main()