File size: 3,800 Bytes
a95b240
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
be26c88
 
 
 
 
 
 
 
 
 
 
 
 
 
d5b6ab2
 
be26c88
 
13df6fc
 
 
 
 
 
 
eb4dec8
 
 
bdb15d5
 
ea0509b
e24c1ad
eb4dec8
 
 
 
 
 
 
 
 
ab3ed36
eb4dec8
 
 
 
 
 
 
e24c1ad
 
 
 
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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)