ENERGY MONITOR 0.2
Loading...
Searching...
No Matches
energy_monitor_cli.cpp
Go to the documentation of this file.
2#include <iostream>
4
5/*
6 SUBSIGNAL IMPLEMENTATION TEST FOR SIGNAL ANALYSIS FOR DIFFERENT STATES FOR A SIGNAL
7 DIVIDE AND CONQUER LIKISH APPROACH WHERE EACH TIME A PERIOD WITH DIFFERENT PERIODIC TIME BREAKS A SET
8 THE SET THAT WAS BROKEN BECOMES A UNIQUE SIGNAL THAT DESERVES AN ANALYSIS FOR IT ONLY
9
10
11*/
12
13
20
21
22void analyticBlock(signal *dummySignal, bool show_peaks_troughs = false);
23
24int main(){
25 std::string user_input;
26 v_container dataContainer;
27 file_IO file_manipulation;
28
29 cout << "EXTRACTING DATA FROM THE FILE.........." << endl;
30 file_manipulation.data_import("Load1.csv",dataContainer,csv);
31
32
33 cout << "COLUMNS NUMBER OF CURRENT TABLE IS :::" << dataContainer.get_col_num() << endl;
34 cout << "ROWS NUMBER OF CURRENT TABLE IS :::" << dataContainer.get_row_num() << endl;
35
36 /*I HAD TO EXTRACT COLUMNS AND MANIPULATE THEM SINCE THE EXPECTED FORMAT WAS NOT PROVIDED*/
37
38
39 cout << "REARRANGING DATA.........." << endl;
40 std::vector<double> time;
41 dataContainer.extractColumn(0,time);
42 std::vector<double> current;
43 dataContainer.extractColumn(2,current);
44 std::vector<double> voltage;
45 dataContainer.extractColumn(1,voltage);
46
47
48
49 v_container currentTable;
50 currentTable.insertColumn(_time,time);
51 currentTable.insertColumn(_val,current);
52 currentTable.sub_table(currentTable, 0, 500000, 0, 1);
53
54
55 v_container voltageTable;
56 voltageTable.insertColumn(_time,time);
57 voltageTable.insertColumn(_val,voltage);
58 voltageTable.sub_table(voltageTable, 0, 500000, 0, 1);
59 /*NOW I HAVE THE EXPECTED FORMAT*/
60
61 _voltage voltage_input;
62 _current current_input;
63 voltage_input.set_hysteresis(0, -100);
64 current_input.set_hysteresis(0, -3);
65 voltage_input.loadData(voltageTable);
66 current_input.loadData(currentTable);
67
68
69 _power result_power = _power(voltage_input,current_input);
70
71
72
73 cout << "ANALYSING UNFILTERED SIGNALS .....\n\n" << endl;
74 cout << "\n***********VOLTAGE ANALYSIS******\n" << endl;
75 analyticBlock(&voltage_input);
76 for(int i = 0; i < voltage_input.subSignal_periodBased()->subSignals.size(); i++){
77 cout << "----------------------------------" << endl;
78 cout << "SUBSIGNAL : " << i << endl;
79 cout << "----------------------------------" << endl;
80 analyticBlock( &(voltage_input.subSignal_periodBased()->subSignals.at(i)) );
81 }
82 cout << "\n***********CURRENT ANALYSIS******\n" << endl;
83 analyticBlock(&current_input);
84 for(int i = 0; i < current_input.subSignal_periodBased()->subSignals.size(); i++){
85 cout << "----------------------------------" << endl;
86 cout << "SUBSIGNAL : " << i << endl;
87 cout << "----------------------------------" << endl;
88 analyticBlock( &(current_input.subSignal_periodBased()->subSignals.at(i)) );
89 }
90 cout << "\n***********POWER ANALYSIS******\n" << endl;
91 analyticBlock(&result_power);
92 for(int i = 0; i < result_power.subSignal_periodBased()->subSignals.size(); i++){
93 cout << "----------------------------------" << endl;
94 cout << "SUBSIGNAL : " << i << endl;
95 cout << "----------------------------------" << endl;
96 analyticBlock( &(result_power.subSignal_periodBased()->subSignals.at(i)) );
97 }
98
99
100 cout << "POWER FACTOR :::" << result_power.get_PF() << endl;
101 cout << "active :::" << result_power.get_active() << endl;
102 cout << "apparent :::" << result_power.get_apparent() << endl;
103
104
105 cout << "TYPE \"EXPORT\" TO EXPORT UNFILTERED else to pass" << endl;
106 cin >> user_input;
107
108 if (user_input == "EXPORT") {
109 cout << "EXPORTING UNFILTERED .....\n\n" << endl;
110
111 voltage_input.exportSignal("voltage_output.csv",true , sig_exp::csv);
112 current_input.exportSignal("current_output.csv",false, sig_exp::csv);
113 result_power.exportSignal("power_output.csv",false , sig_exp::csv);
114 }
115
116
117 cout << "Filtering .....\n\n" << endl;
118
119
120 signal_operation_global.firstO_lowPass_filter(voltage_input,voltage_input,500,2);
121 signal_operation_global.firstO_lowPass_filter(current_input,current_input,500,2);
122 result_power = _power(voltage_input,current_input);
123
124 cout << "\n***********FILTERED VOLTAGE ANALYSIS******\n" << endl;
125 analyticBlock(&voltage_input);
126 for(int i = 0; i < voltage_input.subSignal_periodBased()->subSignals.size(); i++){
127 cout << "----------------------------------" << endl;
128 cout << "SUBSIGNAL : " << i << endl;
129 cout << "----------------------------------" << endl;
130 analyticBlock( &(voltage_input.subSignal_periodBased()->subSignals.at(i)) );
131 }
132 cout << "\n***********FILTERED CURRENT ANALYSIS******\n" << endl;
133 analyticBlock(&current_input);
134 for(int i = 0; i < current_input.subSignal_periodBased()->subSignals.size(); i++){
135 cout << "----------------------------------" << endl;
136 cout << "SUBSIGNAL : " << i << endl;
137 cout << "----------------------------------" << endl;
138 analyticBlock( &(current_input.subSignal_periodBased()->subSignals.at(i)) );
139 }
140 cout << "\n***********FILTERED POWER ANALYSIS******\n" << endl;
141 analyticBlock(&result_power);
142 for(int i = 0; i < result_power.subSignal_periodBased()->subSignals.size(); i++){
143 cout << "----------------------------------" << endl;
144 cout << "SUBSIGNAL : " << i << endl;
145 cout << "----------------------------------" << endl;
146 analyticBlock( &(result_power.subSignal_periodBased()->subSignals.at(i)) );
147 }
148
149 cout << "POWER FACTOR :::" << result_power.get_PF() << endl;
150 cout << "active :::" << result_power.get_active() << endl;
151 cout << "apparent :::" << result_power.get_apparent() << endl;
152
153 cout << "TYPE \"EXPORT\" TO EXPORT FILTERED else to pass" << endl;
154 cin >> user_input;
155 if (user_input == "EXPORT") {
156 cout << "EXPORTING FILTERED .....\n\n" << endl;
157 voltage_input.exportSignal("voltage_output_filtered.csv");
158 current_input.exportSignal("current_output_filtered.csv");
159 result_power.exportSignal("power_output_filtered.csv");
160 }
161
162 current_input.pdf_export("current_input.pdf");
163 voltage_input.pdf_export("voltage_input.pdf");
164 cout << "NOW SIMULATING THE APPLIANCE MODEL USING FILTERED CURRENT AND VOLTAGE.........." << endl;
165
166
167 cout << "SIMULATING APPLIANCE WITH FILTERED CURRENT&VOLTAGE .....\n\n" << endl;
168 appliance modelAppliance = appliance(voltage_input,current_input,"refrigerator");
169 unsigned int steps_number = modelAppliance.get_power()->get_analytics()->samples_num;
170 for(unsigned int step = 0; step < steps_number ; step++)modelAppliance.readStep();
171
172 cout << "SIMULATION RESULTS\n\n" << endl;
173 cout << "VOLTAGE TRIPPED : " << bool_to_string(modelAppliance.voltage_tripped()) << endl;
174 if(modelAppliance.voltage_tripped()){
175 cout << "AT :::" << modelAppliance.voltage_tripTime() << endl;
176 }
177 cout << "CURRENT TRIPPED : " << bool_to_string(modelAppliance.current_tripped()) << endl;
178 if(modelAppliance.current_tripped()){
179 cout << "AT :::" << modelAppliance.current_tripTime() << endl;
180 }
181
182 //GET ENERGY CONSUMED FROM TIME OF START TILL A VERY LONG TIMEE
183 double energy = modelAppliance.get_power()->get_energy(0,100000);
184 //NOW WE HAVE ENERY IN WATT.SECOND
185 energy = ((energy/1000)/ (3600) );
186
187 cout << "ENERGY COST :::" << tarrif_calc(energy) << " EGP" <<endl;
188
189 cout << "TYPE QUIT TO EXIT" << endl;
190 while (1) {
191 cin >> user_input;
192 if (user_input == "QUIT")break;
193 }
194
195
196 return 1;
197}
198
199
200
201void analyticBlock(signal *dummySignal, bool show_peaks_troughs){
202 if(!dummySignal->isTimeAnalysed())dummySignal->analyse();
203 std::cout << "TIME_START :: " << dummySignal->get_analytics()->timeStart << endl;
204 std::cout << "TIME_END :: " << dummySignal->get_analytics()->timeEnd << endl;
205 std::cout << "MAX::"<<dummySignal->get_analytics()->max_val << " at " << dummySignal->get_analytics()->max_val_time << endl;
206 std::cout << "MIN::"<<dummySignal->get_analytics()->min_val << " at " << dummySignal->get_analytics()->min_val_time << endl;
207 std::cout << "AVG::"<<dummySignal->get_analytics()->avg << endl;
208 std::cout << "RMS::"<<dummySignal->get_analytics()->rms << endl;
209 std::cout << "SAMPLING_RATE::"<<dummySignal->get_analytics()->avg_sample_time << endl;
210 std::cout << "NUM_OF_SAMPLES::"<<dummySignal->get_analytics()->samples_num << endl;
211 std::cout << "DATA VIABLE ::" << dummySignal->dataViable() << endl;
212 std::cout << "FREQUENCY ::" << dummySignal->get_analytics()->base_frequency << endl;
213}
214
215
double get_apparent() const
Definition electric.h:133
double get_active() const
Definition electric.h:129
double get_energy(double time_start, double time_end)
get the energy over the coarse of a certain time period
Definition electric.h:99
double get_PF() const
Definition electric.h:145
void firstO_lowPass_filter(signal &base_sig, signal &resultant, double cutOff_freq, int order=1, double avg_sample_time=-1)
first order IIR(INFINITE IMPULSE RESPONSE) low pass filter output = (1 - filter_parameter)*last_out...
bool voltage_tripped()
Definition appliances.h:185
double voltage_tripTime()
Definition appliances.h:194
_power * get_power()
Definition appliances.h:197
void readStep()
Definition appliances.h:96
double current_tripTime()
Definition appliances.h:191
bool current_tripped()
Definition appliances.h:188
bool insertColumn(unsigned int columnNumber, const std::vector< HELD_DATA > &putArray)
inserts a column in the table replacing existing if they exist or adds them
Definition dataTable.h:153
bool sub_table(dataTable &subTable, int rowStart, int rowEnd, int columnStart, int columnEnd)
EXTRACT A SUBSET OF THE BIGGER TABLE.
Definition dataTable.h:172
unsigned int get_col_num()
Definition dataTable.h:41
unsigned int get_row_num()
Definition dataTable.h:38
bool extractColumn(unsigned int columnNumber, std::vector< HELD_DATA > &returnArray)
Extracts a row from the dataTable in a vector.
Definition dataTable.h:129
signal class the parent class for every other signal or any form of time-sorted (time,...
Definition signal.h:39
bool dataViable()
Definition signal.cpp:52
bool exportSignal(std::string name, bool export_all=false, sig_exp expType=sig_exp::csv, std::string fileLocation=settings.get_setting("signal","export_path"))
export the signal data to a specific file
Definition signal.cpp:725
const bool isTimeAnalysed()
check if the signal was analysed in the time domain
Definition signal.h:276
const _analytics * get_analytics() const
get analytics of the time_domain analysed signal
Definition signal.cpp:691
bool pdf_export(std::string name, std::string file_address=settings.get_setting("signal","export_path"))
export valuable signal report (images and text)//in the pdf format
Definition signal.cpp:842
_subSignals * subSignal_periodBased()
get the subSignals generated from this signal based on their periodic times pattern
Definition signal.cpp:712
void set_hysteresis(double upThreshold, double lowThreshold)
sets the hysteresis parameters for the hysteresis trigger frequency calculations
Definition signal.cpp:837
bool loadData(std::string name, std::string fileLocation=settings.get_setting("signal","import_path"))
load data from a file directly if it has the following format (time,value)
bool analyse()
generalized huge analysis in the time domain fetches basic data
Definition signal.cpp:674
std::string bool_to_string(int v)
Definition core.h:175
@ csv
Definition data_IO.h:23
double tarrif_calc(double energy_in_month)
calculate energy cost based on how much energy was consumed in a month according to egyptian tarrif
Definition electric.h:197
void analyticBlock(signal *dummySignal, bool show_peaks_troughs=false)
int main()
this file includes the base class "signal" for signals modeling and analysing thier time-domain / fre...
@ _val
Definition signal.h:30
@ _time
Definition signal.h:29
_signal_operation signal_operation_global
bool data_import(string file_address, dataTable< double > &data, int type)
a function that imports files with supported file formats
Definition data_IO.cpp:84
double avg_sample_time
average sampling time of the signal
Definition signal.h:89
double max_val
absolute maximum value
Definition signal.h:62
double base_frequency
base frequency of the signal
Definition signal.h:101
unsigned int samples_num
number of samples that the signal holds
Definition signal.h:95
double timeStart
the start time of the signal
Definition signal.h:91
double max_val_time
absolute maximum value time
Definition signal.h:64
double timeEnd
the time end of the signal
Definition signal.h:93
double rms
rms for the signal
Definition signal.h:81
double min_val_time
absolute minimum value time
Definition signal.h:68
double min_val
absolute minimum value
Definition signal.h:66
double avg
avg of the signal
Definition signal.h:83
std::vector< signal > subSignals
Definition signal.h:186