Spaces:
Sleeping
Sleeping
Commit
·
94c0fea
1
Parent(s):
a95b240
Update app.py
Browse files
app.py
CHANGED
@@ -4,35 +4,10 @@ import csv
|
|
4 |
import io
|
5 |
import matplotlib.pyplot as plt
|
6 |
import numpy as np
|
|
|
|
|
7 |
|
8 |
-
def preprocess_csv(input_bytes):
|
9 |
-
text = input_bytes.decode() # Decode bytes to text
|
10 |
-
output = io.StringIO()
|
11 |
-
writer = csv.writer(output)
|
12 |
|
13 |
-
for row in csv.reader(io.StringIO(text)): # Read text as csv
|
14 |
-
if len(row) > 5:
|
15 |
-
row = row[0:5] + [','.join(row[5:])] # Combine extra fields into one
|
16 |
-
writer.writerow(row)
|
17 |
-
|
18 |
-
output.seek(0) # go to the start of the StringIO object
|
19 |
-
return output
|
20 |
-
|
21 |
-
def load_data(file):
|
22 |
-
column_names = [
|
23 |
-
'Functional area',
|
24 |
-
'Scenario name',
|
25 |
-
'Start datetime',
|
26 |
-
'End datetime',
|
27 |
-
'Status',
|
28 |
-
'Error message'
|
29 |
-
]
|
30 |
-
data = pd.read_csv(file, header=None, names=column_names)
|
31 |
-
return data
|
32 |
-
|
33 |
-
def fill_missing_data(data, column_index, value):
|
34 |
-
data.iloc[:, column_index] = data.iloc[:, column_index].fillna(value)
|
35 |
-
return data
|
36 |
|
37 |
|
38 |
def single_main(uploaded_file):
|
@@ -41,9 +16,7 @@ def single_main(uploaded_file):
|
|
41 |
# uploaded_file = st.file_uploader("Upload CSV file", type="csv")
|
42 |
|
43 |
if uploaded_file is not None:
|
44 |
-
|
45 |
-
column_names = ["Functional area", "Scenario name", "Start datetime", "End datetime", "Status", "Error message"]
|
46 |
-
|
47 |
filet = uploaded_file.read()
|
48 |
processed_output = preprocess_csv(filet)
|
49 |
processed_file = io.StringIO(processed_output.getvalue())
|
@@ -135,12 +108,33 @@ def single_main(uploaded_file):
|
|
135 |
pass
|
136 |
|
137 |
def main():
|
138 |
-
st.title('CSV Analyser')
|
139 |
-
|
140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
|
142 |
-
if uploaded_file is not None:
|
143 |
-
single_main(uploaded_file) # Load the main app when the file is uploaded
|
144 |
-
|
145 |
if __name__ == "__main__":
|
146 |
main()
|
|
|
4 |
import io
|
5 |
import matplotlib.pyplot as plt
|
6 |
import numpy as np
|
7 |
+
from second import double_main
|
8 |
+
from pre import preprocess_csv, load_data, fill_missing_data
|
9 |
|
|
|
|
|
|
|
|
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
def single_main(uploaded_file):
|
|
|
16 |
# uploaded_file = st.file_uploader("Upload CSV file", type="csv")
|
17 |
|
18 |
if uploaded_file is not None:
|
19 |
+
# Process the csv files with header
|
|
|
|
|
20 |
filet = uploaded_file.read()
|
21 |
processed_output = preprocess_csv(filet)
|
22 |
processed_file = io.StringIO(processed_output.getvalue())
|
|
|
108 |
pass
|
109 |
|
110 |
def main():
|
111 |
+
st.title('Batch Run CSV Analyser')
|
112 |
+
|
113 |
+
# Initially we are in single file processing mode
|
114 |
+
if "mode" not in st.session_state:
|
115 |
+
st.session_state["mode"] = "single"
|
116 |
+
|
117 |
+
mode_display = f'## Current mode: {st.session_state["mode"].title()} mode'
|
118 |
+
st.sidebar.markdown(mode_display)
|
119 |
+
|
120 |
+
# Add a button to switch between modes
|
121 |
+
btn_label = "Switch to Compare mode" if st.session_state["mode"] == "single" else "Switch to Single mode"
|
122 |
+
if st.sidebar.button(btn_label):
|
123 |
+
if st.session_state["mode"] == "single":
|
124 |
+
st.session_state["mode"] = "compare"
|
125 |
+
else:
|
126 |
+
st.session_state["mode"] = "single"
|
127 |
+
|
128 |
+
# Only show the second file uploader in compare mode
|
129 |
+
if st.session_state["mode"] == "single":
|
130 |
+
uploaded_file_1 = st.sidebar.file_uploader("Upload CSV file", type="csv")
|
131 |
+
if uploaded_file_1 is not None:
|
132 |
+
single_main(uploaded_file_1)
|
133 |
+
else:
|
134 |
+
uploaded_file_1 = st.sidebar.file_uploader("Upload CSV file 1", type="csv")
|
135 |
+
uploaded_file_2 = st.sidebar.file_uploader("Upload CSV file 2", type="csv")
|
136 |
+
if uploaded_file_1 is not None and uploaded_file_2 is not None:
|
137 |
+
double_main(uploaded_file_1, uploaded_file_2)
|
138 |
|
|
|
|
|
|
|
139 |
if __name__ == "__main__":
|
140 |
main()
|