Spaces:
Sleeping
Sleeping
Updated ui look for second.py compare
Browse files
second.py
CHANGED
|
@@ -1,18 +1,15 @@
|
|
| 1 |
-
# Import necessary libraries
|
| 2 |
import pandas as pd
|
| 3 |
import streamlit as st
|
| 4 |
-
import
|
| 5 |
-
import io
|
| 6 |
-
import matplotlib.pyplot as plt
|
| 7 |
-
import numpy as np
|
| 8 |
from pre import preprocess_uploaded_file
|
| 9 |
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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 |
-
|
| 24 |
-
newer_df = data_2
|
| 25 |
else:
|
| 26 |
-
|
| 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
|
| 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 |
-
#
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
# Get failing scenarios count
|
| 65 |
pass_fail_count = len(pass_to_fail_scenarios)
|
| 66 |
-
|
| 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
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|