-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStats.cpp
325 lines (293 loc) · 12.2 KB
/
Stats.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
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
//
// Created by Michael Kinc on 28/11/2020.
//
#include "Stats.h"
#include <iomanip>
Stats::Stats() = default;
/**
* Staticky atribut tridy Stats, ktery reprezentuje mnozstvi vody vypustene do kanalu z jimky.
*/
int Stats::totalDroppedWater = 0;
int Stats::totalWaterSupply = 0;
int Stats::roofWater = 0;
int Stats::totalWaterUsed = 0;
int Stats::dinTankVolume = 0;
int Stats::enTankVolume = 0;
double Stats::totalRain = 0;
int Stats::totalContainedWater = 0;
vector<Stats::yearStats> Stats::years;
int Stats::observedDays = 0;
int Stats::roofArea = 0;
float Stats::roofCoef = 0.0;
bool Stats::shouldPrintYears = false;
float Stats::priceForCubicMeter = 0;
int Stats::tankPrice = 0;
/**
* Vypise na standardni vystup hodnoty pro jednotlive roky.
*/
void Stats::printYears() {
#define YEARLEN 9
cout <<left<<setw(YEARLEN)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(YEARLEN -3 )<<setfill(' ')<<"ROK";
cout<<"| "<<left<<setw(20)<<setfill(' ')<<"ZACHYCENA VODA [l]";
cout<<"| "<<left<<setw(20)<<setfill(' ')<<"PREPAD VODY [l]";
cout<<"| "<<left<<setw(20)<<setfill(' ')<<"DOPUSTENA VODA [l]";
cout<<"| "<<left<<setw(20)<<setfill(' ')<<"VYUZITA VODA [l]";
cout<<"| "<<left<<setw(20)<<setfill(' ')<<"SRAZEK CELKEM [mm]"<<"|"<<endl;
cout <<left<<setw(YEARLEN)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
for (int i = 0; i < years.size(); i++) {
//cout << "|\t" << years[i].year << "\t\t|\t" << years[i].containedWater << "\t\t\t|\t" << years[i].droppedWater << "\t\t|\t" << years[i].waterSupply << "\t\t\t|\t" << years[i].waterUsed << "\t\t\t|\t" << years[i].rain << "\t\t|"<<endl;
cout<<"| "<<left<<setw(YEARLEN-3)<<setfill(' ')<<years[i].year;
cout<<"| "<<left<<setw(20)<<setfill(' ')<<years[i].containedWater;
cout<<"| "<<left<<setw(20)<<setfill(' ')<<years[i].droppedWater;
cout<<"| "<<left<<setw(20)<<setfill(' ')<<years[i].waterSupply;
cout<<"| "<<left<<setw(20)<<setfill(' ')<<years[i].waterUsed;
cout<<"| "<<left<<setw(20)<<setfill(' ')<<years[i].rain<<"|"<<endl;
cout <<left<<setw(YEARLEN)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<left<<setw(23)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
}
cout<<endl;
}
/**
* Vypise na standardni vystup zakladni ekonomicke hodnoty
*/
void Stats::money() {
/*cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Prumerna rocni cena za dopusteni [Kc]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< ((float)totalWaterSupply*(Stats::priceForCubicMeter/1000))/years.size() << "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Prumerna rocni ztrata v prepadu [Kc]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< ((float)totalDroppedWater*(Stats::priceForCubicMeter/1000))/years.size() << "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Realne usetreno v prumeru za rok [Kc]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< ((float)(totalContainedWater)*(Stats::priceForCubicMeter/1000))/years.size() << "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;*/
cout <<left<<setw(54)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(51)<<setfill(' ')<< "Cena za uchovani jednoho m3 do nadrze [Kc]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< ((float)Stats::tankPrice/((float)Stats::totalContainedWater))*1000 << "|" << endl;
cout <<left<<setw(54)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
}
/**
* Vypise na standardni vystup zachycene statistiky.
*/
void Stats::generateStats() {
bool areYearsContinuous = true;
for (auto it = years.begin(); it != years.end(); ++it) {
if (it != years.begin()) {
if (it->year - 1 != prev(it)->year) {
areYearsContinuous = false;
break;
}
}
}
if (areYearsContinuous) {
if (years.size() == 1) {
cout << "Simulace probihala pro rok ";
cout << years.front().year << endl;
}
else {
cout << "Simulace probihala pro roky ";
cout << years.front().year << " - " << years.back().year << "." << endl;
}
}
else {
cout << "Simulace probihala pro roky ";
for (auto it = years.begin(); it != years.end(); ++it) {
if (next(it) != years.end()) {
cout << it->year << ", ";
}
else {
cout << it->year << "." << endl;
}
}
}
if (shouldPrintYears) {
printYears();
}
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Celkove mnozstvi zachycene vody [l]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::totalContainedWater << "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Celkove mnozstvi prepadle vody [l]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::totalDroppedWater << "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Celkove mnozstvi docerpane vody [l]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::totalWaterSupply << "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(41)<<setfill(' ')<< "Celkove mnozstvi srazek [mm]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::totalRain<< "|" << endl;
cout <<left<<setw(44)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<endl;
cout <<left<<setw(54)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(51)<<setfill(' ')<< "Prumerna rocni spotreba vody pro zalivku [l]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::totalWaterUsed/years.size() << "|" << endl;
cout <<left<<setw(54)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(51)<<setfill(' ')<< "Prumerny rocni uhrn srazek [mm]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::totalRain/years.size()<< "|" << endl;
cout <<left<<setw(54)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
//cout << "Průměrné roční zavlažování: " << Stats::totalWaterUsed/years.size() << endl;
//cout << "Průměrný roční úhrn srážek: " << Stats::totalRain/years.size() << endl;
Stats::din(Stats::roofArea, Stats::roofCoef, 0.95);
Stats::en(Stats::roofArea, Stats::roofCoef, 0.95);
cout<<endl;
cout <<left<<setw(64)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(61)<<setfill(' ')<< "Navrh akumulacni jimky podle normy EN 16941-1 [l]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::enTankVolume << "|" << endl;
cout <<left<<setw(64)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout<<"| "<<left<<setw(61)<<setfill(' ')<< "Navrh akumulacni jimky podle normy DIN 1989 - 1:2001 [l]: ";
cout<<"| "<<left<<setw(10)<<setfill(' ')<< Stats::dinTankVolume<< "|" << endl;
cout <<left<<setw(64)<<setfill('-')<< "+";
cout <<left<<setw(13)<<setfill('-')<< "+";
cout <<right<< "+"<<endl;
cout << endl;
money();
//cout << "DIN: " << Stats::dinTankVolume << endl;
//cout << "EN: " << Stats::enTankVolume << endl;
//cout << "Celkove srazky za rok: " << Stats::rainTotalInYear << endl;
}
/**
* Nastaví nový rok - vytvoří novou proměnnou typu yearStats a uloží ji do vektoru roků.
* @param year rok
*/
void Stats::newYear(int year) {
yearStats y;
y.year = year;
years.push_back(y);
}
/**
* Metoda, ktera počítá velikost akumulační nádrže pro normu EN 16941-1
* @param roofArea velikost strechy
* @param coeficient pritokovy koeficient strechy
* @param hydraulicFilterEff efektivita hydraulickeho filtru
*/
void Stats::en(int roofArea, float coeficient, double hydraulicFilterEff) {
int annualPrecInflow = roofArea * coeficient * totalRain/29 * hydraulicFilterEff;
int annualWaterConsump = totalWaterUsed/years.size();
int dayWaterConsump = annualWaterConsump / years.back().numberOfDays;
enTankVolume = dayWaterConsump * 21;
}
/**
* Metoda, ktera počítá velikost akumulační nádrže pro normu DIN 1989 - 1:2001
* @param roofArea velikost strechy
* @param coeficient pritokovy koeficient strechy
* @param hydraulicFilterEff efektivita hydraulickeho filtru
*/
void Stats::din(int roofArea, float coeficient, double hydraulicFilterEff) {
float rainlessPeriodCoeff = 21.0/(float)years.back().numberOfDays; //prumerny rocni srazkovy uhrn v mm
int annualPrecInflow = roofArea * coeficient * totalRain/years.size() * hydraulicFilterEff;//0.95
int annualWaterConsump = totalWaterUsed/years.size();// deleno rokama
int res = (float)min(annualPrecInflow, annualWaterConsump) * rainlessPeriodCoeff;
dinTankVolume = res;
}
/**
* Metoda, která přičítá zachycenou vodu pro aktuální rok i celkově,
* @param amount množství
*/
void Stats::containedWater(int amount) {
years.back().containedWater += amount;
totalContainedWater += amount;
}
/**
* Metoda, která přičítá přepadlou vodu pro aktuální rok i celkově,
* @param amount množství
*/
void Stats::droppedWater(int amount) {
years.back().droppedWater += amount;
totalDroppedWater += amount;
}
/**
* Metoda, která přičítá dočerpanou vodu pro aktuální rok i celkově,
* @param amount množství
*/
void Stats::waterSupply(int amount) {
years.back().waterSupply += amount;
totalWaterSupply += amount;
}
/**
* Metoda, která přičítá využitou vodu pro aktuální rok i celkově,
* @param amount množství
*/
void Stats::usedWater(int amount) {
years.back().waterUsed += amount;
totalWaterUsed += amount;
}
/**
* Metoda, která přičítá srazkovy urh pro aktuální rok i celkově,
* @param amount množství
*/
void Stats::incrementRain(double amount) {
years.back().rain += amount;
totalRain += amount;
}
/**
* Metoda, která počíta, s kolik dny v roce pracujeme
* @param months množina měsíců, se kterými pracujeme
*/
void Stats::setMonths(set<int> months) {
for (auto elem : months) {
if (elem == 4 or elem == 6 or elem == 9 or elem == 11) {
observedDays += 30;
}
else if (elem == 2) {
observedDays += 28;
}
else {
observedDays += 31;
}
}
}
/**
* Metoda, ktera nastavi novy den.
*/
void Stats::newDay() {
years.back().numberOfDays += 1;
}