File size: 1,792 Bytes
a95b240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be26c88
 
 
 
 
 
 
 
 
 
 
 
 
 
d5b6ab2
 
be26c88
 
a95b240
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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')
    return data