Spaces:
Sleeping
Sleeping
import pandas as pd | |
import streamlit as st | |
import csv | |
import io | |
def preprocess_csv(input_bytes): | |
text = input_bytes.decode() # Decode bytes to text | |
output = io.StringIO() | |
writer = csv.writer(output) | |
for row in csv.reader(io.StringIO(text)): # Read text as csv | |
if len(row) > 5: | |
row = row[0:5] + [','.join(row[5:])] # Combine extra fields into one | |
writer.writerow(row) | |
output.seek(0) # go to the start of the StringIO object | |
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 | |
# Define a function to convert a string to camel case | |
def to_camel_case(s): | |
parts = s.split('_') | |
return ''.join([part.capitalize() for part in parts]) | |
# Define the function to preprocess a CSV file | |
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') | |
# Extract environment name from filename | |
filename = uploaded_file.name | |
environment = filename.split('_Puppeteer')[0] | |
# Add environment column to the dataframe | |
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.") | |
# Add the new link here | |
link_html = '<p style="font-size: 14px;"><a href="https://scenarioswitcher.negadan77.workers.dev/" target="_blank">Open Scenario Processor</a></p>' | |
st.markdown(link_html, unsafe_allow_html=True) | |