|
import pandas as pd |
|
import streamlit as st |
|
import csv |
|
import io |
|
|
|
def preprocess_csv(input_bytes): |
|
text = input_bytes.decode() |
|
output = io.StringIO() |
|
writer = csv.writer(output) |
|
|
|
for row in csv.reader(io.StringIO(text)): |
|
if len(row) > 5: |
|
row = row[0:5] + [','.join(row[5:])] |
|
writer.writerow(row) |
|
|
|
output.seek(0) |
|
return output |
|
|
|
def load_data(file): |
|
column_names = [ |
|
'Functional area', |
|
'Scenario name', |
|
'Start datetime', |
|
'End datetime', |
|
'Status', |
|
'Error message' |
|
] |
|
data = pd.read_csv(file, header=None, names=column_names) |
|
return data |
|
|
|
def fill_missing_data(data, column_index, value): |
|
data.iloc[:, column_index] = data.iloc[:, column_index].fillna(value) |
|
return data |
|
|
|
|
|
def to_camel_case(s): |
|
parts = s.split('_') |
|
return ''.join([part.capitalize() for part in parts]) |
|
|
|
|
|
def preprocess_uploaded_file(uploaded_file): |
|
file_content = uploaded_file.read() |
|
processed_output = preprocess_csv(file_content) |
|
processed_file = io.StringIO(processed_output.getvalue()) |
|
data = load_data(processed_file) |
|
data = fill_missing_data(data, 4, 0) |
|
data['Start datetime'] = pd.to_datetime(data['Start datetime'], dayfirst=True, errors='coerce') |
|
data['End datetime'] = pd.to_datetime(data['End datetime'], dayfirst=True, errors='coerce') |
|
data['Time spent'] = (data['End datetime'] - data['Start datetime']).dt.total_seconds() |
|
data['Time spent(m:s)'] = pd.to_datetime(data['Time spent'], unit='s').dt.strftime('%M:%S') |
|
|
|
filename = uploaded_file.name |
|
environment = filename.split('_Puppeteer')[0] |
|
|
|
|
|
data['Environment'] = environment |
|
|
|
return data |
|
|
|
def add_app_description(): |
|
app_title = '<p style="font-family:Roboto, sans-serif; color:#004E7C; font-size: 42px;">DataLink Compare</p>' |
|
st.markdown(app_title, unsafe_allow_html=True) |
|
|
|
is_selected = st.sidebar.checkbox('Show App Description', value=False) |
|
|
|
if is_selected: |
|
with st.expander('Show App Description'): |
|
st.markdown("Welcome to DataLink Compare. This tool allows you to analyze CSV files containing scenarios' data and provides insights into their statuses, processing times, and more. You can also compare two CSV files to identify differences and similarities between them.") |
|
|
|
st.markdown("### Instructions:") |
|
st.write("1. Upload your CSV file using the file uploader on the sidebar.") |
|
st.write("2. Choose between 'Multi' and 'Compare' mode using the button on the sidebar.") |
|
st.write("3. In 'Multi' mode, you can upload and analyze multiple CSV files for individual environments.") |
|
st.write("4. In 'Compare' mode, you can upload two CSV files to compare them.") |
|
|
|
st.markdown("### Features:") |
|
st.write("- View statistics of passing and failing scenarios.") |
|
st.write("- Filter scenarios by functional area and status.") |
|
st.write("- Calculate average time spent for each functional area.") |
|
st.write("- Display bar graphs showing the number of failed scenarios.") |
|
st.write("- Identify consistent failures, new failures, and changes in passing scenarios.") |