-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_logs.cpp
More file actions
361 lines (274 loc) · 10 KB
/
Copy pathread_logs.cpp
File metadata and controls
361 lines (274 loc) · 10 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include <iostream>
#include <fstream>
#include <filesystem>
#include <string>
#include <optional>
#include <vector>
#include "parse_output.hpp"
#include "read_logs.hpp"
namespace fs = std::filesystem;
// --------------------------------------------------
// find_expected_states_file
// --------------------------------------------------
std::optional<fs::path> find_expected_states_file() {
const std::vector<fs::path> candidates = {
fs::current_path() / "expected_DEVS_states.csv",
fs::current_path() / "oracle" / "expected_DEVS_states.csv"
};
for (const auto& p : candidates) {
if (fs::exists(p)) {
return p;
}
}
return std::nullopt;
}
// ==================================================
// UPDATED CLI VERSION
// ==================================================
void read_logs() {
SigmaTolerance sigmaTol;
sigmaTol.absolute = 1e-6;
sigmaTol.accept_inf = true;
int choice = 0;
std::cout << "Select sigma fault tolerance:\n";
std::cout << "1) 0%\n";
std::cout << "2) 5%\n";
std::cout << "3) 10%\n";
std::cout << "4) 20%\n";
std::cout << "> ";
std::cin >> choice;
switch (choice) {
case 1: sigmaTol.relative = 0.0; break;
case 2: sigmaTol.relative = 0.05; break;
case 3: sigmaTol.relative = 0.10; break;
case 4: sigmaTol.relative = 0.20; break;
default:
std::cerr << "Invalid selection. Defaulting to 10%.\n";
sigmaTol.relative = 0.10;
break;
}
std::cout << "Using sigma fault tolerance: "
<< (sigmaTol.relative * 100) << "%\n\n";
// -----------------------------
// Mode selection
// -----------------------------
int mode = 0;
std::cout << "Select validation mode:\n";
std::cout << "1) Single file\n";
std::cout << "2) Folder\n";
std::cout << "> ";
std::cin >> mode;
std::string folderPath;
std::string singleFilePath;
if (mode == 1) {
std::cout << "Enter full path to CSV file:\n> ";
std::cin >> singleFilePath;
} else if (mode == 2) {
std::cout << "Enter folder path:\n> ";
std::cin >> folderPath;
} else {
std::cout << "Invalid selection. Defaulting to folder.\n";
folderPath = "simulation_results";
mode = 2;
}
// -----------------------------
// Load expected DB
// -----------------------------
auto expectedPath = find_expected_states_file();
if (!expectedPath) {
std::cerr << "ERROR: Could not locate expected_states file.\n";
return;
}
std::cout << "Loaded expected states from: "
<< expectedPath->string() << "\n";
auto expectedDatabase = loadExpectedDatabase(expectedPath->string());
if (expectedDatabase.empty()) {
std::cerr << "ERROR: Expected database is empty or missing.\n";
return;
}
try {
// -----------------------------
// SINGLE FILE MODE
// -----------------------------
if (mode == 1) {
if (!fs::exists(singleFilePath)) {
std::cerr << "File not found: "
<< singleFilePath << std::endl;
return;
}
std::cout << "Parsing "
<< fs::path(singleFilePath).filename().string()
<< "...\n";
std::string result =
parseFile(singleFilePath, expectedDatabase, sigmaTol);
std::cout << fs::path(singleFilePath).filename().string()
<< ": " << result << std::endl;
}
// -----------------------------
// FOLDER MODE
// -----------------------------
else {
if (!fs::exists(folderPath)) {
std::cerr << "Folder not found: "
<< folderPath << std::endl;
return;
}
for (const auto& entry : fs::directory_iterator(folderPath)) {
if (entry.path().extension() == ".csv") {
std::string filename = entry.path().string();
std::cout << "Parsing "
<< entry.path().filename().string()
<< "...\n";
std::string result =
parseFile(filename, expectedDatabase, sigmaTol);
std::cout << entry.path().filename().string()
<< ": " << result << std::endl;
}
}
}
// -----------------------------
// NOT TESTED FILES
// -----------------------------
if (!not_tested_files.empty()) {
std::cout << "\n=====================================\n";
std::cout << "FILES NOT TESTED (missing expected states)\n";
std::cout << "=====================================\n";
for (const auto& f : not_tested_files) {
std::cout << " - " << f << "\n";
}
std::cout << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
}
// ==================================================
// GUI VERSION (unchanged)
// ==================================================
void read_logs(double relativeTol, std::ostream& out) {
SigmaTolerance sigmaTol;
sigmaTol.absolute = 1e-6;
sigmaTol.accept_inf = true;
sigmaTol.relative = relativeTol;
out << "Using sigma fault tolerance: "
<< (sigmaTol.relative * 100) << "%\n\n";
auto expectedPath = find_expected_states_file();
if (!expectedPath) {
out << "ERROR: Could not locate expected_states file.\n";
return;
}
out << "Loaded expected states from: "
<< expectedPath->string() << "\n\n";
auto expectedDatabase = loadExpectedDatabase(expectedPath->string());
if (expectedDatabase.empty()) {
out << "ERROR: Expected database is empty or missing.\n";
return;
}
std::string folderPath = "simulation_results";
try {
if (!fs::exists(folderPath)) {
out << "Folder not found: " << folderPath << "\n";
return;
}
for (const auto& entry : fs::directory_iterator(folderPath)) {
if (entry.path().extension() == ".csv") {
std::string filename = entry.path().string();
out << "Parsing "
<< entry.path().filename().string()
<< "...\n";
std::string result =
parseFile(filename, expectedDatabase, sigmaTol);
out << entry.path().filename().string()
<< ": " << result << "\n\n";
}
}
if (!not_tested_files.empty()) {
out << "\n=====================================\n";
out << "FILES NOT TESTED (missing expected states)\n";
out << "=====================================\n";
for (const auto& f : not_tested_files) {
out << " - " << f << "\n";
}
out << "\n";
}
} catch (const std::exception& e) {
out << "Error: " << e.what() << "\n";
}
}
void run_validation(double relativeTol,
const std::string& mode,
const std::string& path,
std::ostream& out) {
SigmaTolerance sigmaTol;
sigmaTol.absolute = 1e-6;
sigmaTol.accept_inf = true;
sigmaTol.relative = relativeTol;
out << "Using sigma fault tolerance: "
<< (sigmaTol.relative * 100) << "%\n\n";
auto expectedPath = find_expected_states_file();
if (!expectedPath) {
out << "ERROR: Could not locate expected_states file.\n";
return;
}
out << "Loaded expected states from: "
<< expectedPath->string() << "\n\n";
auto expectedDatabase = loadExpectedDatabase(expectedPath->string());
if (expectedDatabase.empty()) {
out << "ERROR: Expected database is empty or missing.\n";
return;
}
try {
// -----------------------------
// SINGLE FILE
// -----------------------------
if (mode == "file") {
if (!fs::exists(path)) {
out << "File not found: " << path << "\n";
return;
}
out << "Parsing "
<< fs::path(path).filename().string()
<< "...\n";
std::string result =
parseFile(path, expectedDatabase, sigmaTol);
out << fs::path(path).filename().string()
<< ": " << result << "\n";
}
// -----------------------------
// FOLDER
// -----------------------------
else if (mode == "folder") {
if (!fs::exists(path)) {
out << "Folder not found: " << path << "\n";
return;
}
for (const auto& entry : fs::directory_iterator(path)) {
if (entry.path().extension() == ".csv") {
std::string filename = entry.path().string();
out << "Parsing "
<< entry.path().filename().string()
<< "...\n";
std::string result =
parseFile(filename, expectedDatabase, sigmaTol);
out << entry.path().filename().string()
<< ": " << result << "\n\n";
}
}
}
else {
out << "Invalid mode. Use 'file' or 'folder'\n";
return;
}
if (!not_tested_files.empty()) {
out << "\n=====================================\n";
out << "FILES NOT TESTED (missing expected states)\n";
out << "=====================================\n";
for (const auto& f : not_tested_files) {
out << " - " << f << "\n";
}
out << "\n";
}
} catch (const std::exception& e) {
out << "Error: " << e.what() << "\n";
}
}