-
Notifications
You must be signed in to change notification settings - Fork 0
/
Performance Analyser.cpp
289 lines (265 loc) · 10.4 KB
/
Performance Analyser.cpp
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
#include "stdafx.h"
#include <iostream>
#include "csv.h"
#include <iomanip>
#include "ConsoleColor.h"
using namespace std;
long long int all_error_time[1000]; // these two array contains
int all_error_codes[1000]; // error code and time of occurance
std::string path_to_file;
float temperature_maximum, temperature_minimum, voltage_maximum, voltage_minimum, current_maximum, current_minimum, speed_maximum, speed_minimum;
int temperature_error, voltage_error, current_error, speed_error, error_count = 0, no_error_count = 0;
float csv_tmax, csv_tmin, csv_vmax, csv_vmin, csv_cmax, csv_cmin, csv_smax, csv_smin;
void updateScreen(std::string);
void getStandardPara(void);
void getCSV_max_min(void);
int single_error_code(float, float, float);
void errorCodeClubber(long long int, int, int, int, int);
void generate_brief_report(void);
std::string analysePerformance(int);
void printTimeStamp(long long int);
std::string tomonth(int);
void printAll_Fluctuations(void);
int main()
{
updateScreen("Welcome");
std::cout << endl << "Please drag and drop the error free DATA.CSV here: ";
std::cin >> path_to_file;
//Switch to fullscreen
::SendMessage(::GetConsoleWindow(), WM_SYSKEYDOWN, VK_RETURN, 0x20000000);
updateScreen("Welcome");
getCSV_max_min();
// Do Main calculation
io::CSVReader<5> in(path_to_file);
in.read_header(io::ignore_extra_column, "Time", "Temperature", "Voltage", "Current", "Speed");
long long int time_csv;
float temperature_csv, voltage_csv, current_csv, speed_csv;
updateScreen("Welcome");
getStandardPara(); //it fetches Form data as in PHP code written
updateScreen("Welcome");
updateScreen("GettingErrorCode");
while (in.read_row(time_csv, temperature_csv, voltage_csv, current_csv, speed_csv))
{
// get error codes
temperature_error = single_error_code(temperature_csv, temperature_maximum, temperature_minimum);
voltage_error = single_error_code(voltage_csv, voltage_maximum, voltage_minimum);
current_error = single_error_code(current_csv, current_maximum, current_minimum);
speed_error = single_error_code(speed_csv, speed_maximum, speed_minimum);
// verify and store error codes
errorCodeClubber(time_csv, temperature_error, voltage_error, current_error, speed_error);
}
updateScreen("Welcome");
std::cout << endl << "I found " << yellow << no_error_count << white << " data inside the limits you gave me and " << red << error_count << white << " fluctuated." << endl;
if (error_count > 0)
{
generate_brief_report();
printAll_Fluctuations();
}
std::cout << endl << endl << endl << endl << endl << endl << endl << endl << green << setfill('-') << setw(25) << "-" << "End of Program" << setfill('-') << setw(25) << "-" << white << endl;
//Ask whether to exit or not
std::string any_key_to_exit;
do
{
std::cout << "Would you like to exit? ";
std::cin >> any_key_to_exit;
if (any_key_to_exit == "yes" || any_key_to_exit == "y") exit(0);
} while (1);
}
void getCSV_max_min(void)
{
io::CSVReader<5> inn(path_to_file);
inn.read_header(io::ignore_extra_column, "Time", "Temperature", "Voltage", "Current", "Speed");
long long int time;
float temperature, voltage, current, speed;
bool one_time_count = 0;
updateScreen("Welcome");
updateScreen("GettingCSV_max_min");
while (inn.read_row(time, temperature, voltage, current, speed))
{
if (temperature == 0 || voltage == 0 || current == 0 || speed == 0) continue;
if (one_time_count == 0)
{
csv_tmax = csv_tmin = temperature;
csv_vmax = csv_vmin = voltage;
csv_cmax = csv_cmin = current;
csv_smax = csv_smin = speed;
one_time_count++;
}
else
{
if (temperature > csv_tmax) csv_tmax = temperature;
else if (temperature < csv_tmin) csv_tmin = temperature;
if (voltage > csv_vmax) csv_vmax = voltage;
else if (voltage < csv_vmin) csv_vmin = voltage;
if (current > csv_cmax) csv_cmax = current;
else if (current < csv_cmin) csv_cmin = current;
if (speed > csv_smax) csv_smax = speed;
else if (speed < csv_smin) csv_smin = speed;
}
}
}
void getStandardPara(void)
{
float temp_swap;
std::cout << endl << "What are the maximum and minimum limits I should check for?\n(Bracket values are Maximum and Minimum value in CSV file)" << endl << endl;
std::cout << setw(25) << left << "Maximum Temperature" << "(" << csv_tmax << ")" << ": ";
std::cin >> temperature_maximum;
std::cout << setw(25) << "Minimum Temperature" << "(" << csv_tmin << ")" << ": ";
std::cin >> temperature_minimum;
if (temperature_maximum < temperature_minimum)
{
temp_swap = temperature_maximum;
temperature_maximum = temperature_minimum;
temperature_minimum = temp_swap;
cout << blue << "I found value of Max Temperature greater than Min Temperature, so I swapped them..." << white << endl;
}
std::cout << endl << setw(25) << left << "Maximum Voltage" << "(" << csv_vmax << ")" << ": ";
std::cin >> voltage_maximum;
std::cout << setw(25) << left << "Minimum Voltage" << "(" << csv_vmin << ")" << ": ";
std::cin >> voltage_minimum;
if (voltage_maximum < voltage_minimum)
{
temp_swap = voltage_maximum;
voltage_maximum = voltage_minimum;
voltage_minimum = temp_swap;
cout << blue << "I found value of Max Voltage greater than Min Voltage, so I swapped them..." << white << endl;
}
std::cout << endl << setw(25) << left << "Maximum Current" << "(" << csv_cmax << ")" << ": ";
std::cin >> current_maximum;
std::cout << setw(25) << left << "Minimum Current" << "(" << csv_cmin << ")" << ": ";
std::cin >> current_minimum;
if (current_maximum < current_minimum)
{
temp_swap = current_maximum;
current_maximum = current_minimum;
current_minimum = temp_swap;
cout << blue << "I found value of Max Minimum greater than Min Minimum, so I swapped them..." << white << endl;
}
std::cout << endl << setw(25) << left << "Maximum Speed" << "(" << csv_smax << ")" << ": ";
std::cin >> speed_maximum;
std::cout << setw(25) << left << "Minimum Speed" << "(" << csv_smin << ")" << ": ";
std::cin >> speed_minimum;
if (speed_maximum < speed_minimum)
{
temp_swap = speed_maximum;
speed_maximum = speed_minimum;
speed_minimum = temp_swap;
cout << blue << "I found value of Max Speed greater than Min Speed, so I swapped them..." << white << endl;
}
}
int single_error_code(float analyser, float maxi, float mini)
{
if (analyser == 0) return 0;
else if (analyser > maxi) return 3;
else if (analyser < mini) return 1;
else return 2;
}
void updateScreen(std::string region)
{
if (region == "Welcome")
{
system("CLS");
std::cout << green << setw(45) << right << "Electrical Performance Analyser" << white << endl;
}
else if (region == "GettingErrorCode")
{
std::cout << endl << "Could you please wait until I read the CSV file and generate report...";
}
else if (region == "GettingCSV_max_min")
{
std::cout << endl << "I am searching for maximum and minimum values in the CSV file...";
}
}
void errorCodeClubber(long long int timeStamp, int t, int v, int c, int s)
{
if (t == 2 && v == 2 && c == 2 && s == 2)
{
no_error_count++;
}
else
{
error_count++;
all_error_time[error_count] = timeStamp;
all_error_codes[error_count] = t * 1000 + v * 100 + c * 10 + s; //Future bug, in case t gets 0... ONLY t
}
}
void generate_brief_report(void)
{
int last_error_code = 2222; // 2222 isn't error, in such case this function will never be called
for (int i = 1; i <= error_count; i++)
{
if (all_error_codes[i] == last_error_code) continue;
printTimeStamp(all_error_time[i]);
std::cout << analysePerformance(all_error_codes[i]);
last_error_code = all_error_codes[i];
}
}
void printTimeStamp(long long int raw)
{
//Formmatting date and time
int seconds = raw % 100;
raw = raw / 100;
int minutes = raw % 100;
raw = raw / 100;
int hours = raw % 100;
raw = raw / 100;
int date = raw % 100;
raw = raw / 100;
int month = raw % 100;
raw = raw / 100;
cout << endl << blue << date << tomonth(month) << raw << " at " << hours << ":" << minutes << ":" << seconds << white;
}
std::string tomonth(int mnth)
{
if (mnth == 1) return " January ";
else if (mnth == 2) return " February ";
else if (mnth == 3) return " March ";
else if (mnth == 4) return " April ";
else if (mnth == 5) return " May ";
else if (mnth == 6) return " June ";
else if (mnth == 7) return " July ";
else if (mnth == 8) return " August ";
else if (mnth == 9) return " September ";
else if (mnth == 10) return " Octuber ";
else if (mnth == 11) return " November ";
else if (mnth == 12) return " December ";
else return " Something fissy! ";
}
void printAll_Fluctuations(void)
{
std::cout << endl << yellow << "Below are all the fluctuations I found during analysis" << endl << "Error code is in the order of Temperature, Voltage, Current and speed\nwhere,\n3 is HIGH\n2 is NORMAL\n1 is LOW\n0 is OFF" << white << endl;
std::cout << "---------------------------------------------" << endl;
std::cout << "| Error Code | Timestamp |" << endl;
std::cout << "---------------------------------------------" << endl;
for (int i = 1; i <= error_count; i++)
{
std::cout << "| " << setw(8) << left << all_error_codes[i] << setw(5) << "| " << all_error_time[i] << " |" << endl;
}
std::cout << "---------------------------------------------" << endl;
}
std::string analysePerformance(int dataCode)
{
std::string result = "\n";
int eachCode_s = dataCode % 10;
dataCode = dataCode / 10;
int eachCode_c = dataCode % 10;
dataCode = dataCode / 10;
int eachCode_v = dataCode % 10;
dataCode = dataCode / 10;
int eachCode_t = dataCode;
// Check if supply is given?
if (eachCode_v == 0) result = result + "Motor is turned off. We did not find any supply voltage.\n";
else
{
// Checking Temperature
if (eachCode_t == 1) result = result + "The motor might be running in a colder environment, better performance will be seen once it heats up.\n";
else if (eachCode_t == 3) result = result + "The motor got overheat at this moment, please use a better cooling system.\n";
// Checking Voltage
if (eachCode_v == 1) result = result + "There is a dip in supply voltage, please use voltage booster unit.\n";
else if (eachCode_v == 3) result = result + "The supply is higher than permitted limit, please use a stabilizer.\n";
// Checking Current and Speed
if (eachCode_c == 3 && eachCode_s == 1) result = result + "We found high current with low speed, probably due to overload or insufficient lubricant.\n";
else if (eachCode_c == 3 && eachCode_s == 0) result = result + "We found high current with zero speed due to blocked rotor.\n";
}
return result;
}