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'], errors='coerce') data['End datetime'] = pd.to_datetime(data['End datetime'], 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') return data