-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
382 lines (381 loc) · 16.3 KB
/
main.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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/**
* @file main.cpp
* @author Thomas Saquet, Florent Poinsaut
* @date
* @brief File containing example of doxygen usage for quick reference.
*
* Alert - Dbo is the database objects library, part of the Alert software
* Copyright (C) 2013-2017
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
//#include <Wt/WLogger>
//#include "tools/MainIncludeFile.h"
//#include <tools/Session.h>
//
//using namespace std;
//
//
//int main(int argc, char** argv)
//{
// Session session("hostaddr=172.16.3.202 port=5432 dbname=echoes user=echoes password=toto");
// Echoes::Dbo::Session session("hostaddr=127.0.0.1 port=5432 dbname=echoes user=echoes password=toto");
//
// try
// {
// Wt::Dbo::Transaction transaction(session);
//
// Wt::log("info") << "Tables Creation";
// session.createTables();
//
// transaction.commit();
// }
// catch (Wt::Dbo::Exception e)
// {
// Wt::log("error") << e.what();
// }
//
// try
// {
// Wt::Dbo::Transaction transaction(session);
//
// Wt::log("info") << "Calculate AVG IVA Function Creation";
//
// session.execute
// (
//" CREATE OR REPLACE FUNCTION calculate_avg_iva(integer, integer, integer, integer, integer, integer, integer, integer, integer, integer, integer)\n"
//" RETURNS void AS\n"
//" $BODY$\n"
//" INSERT INTO \"T_INFORMATION_VALUE_IVA\"\n"
//" (\n"
//" \"version\",\n"
//" \"IVA_VALUE\",\n"
//" \"IVA_CREA_DATE\",\n"
//" \"IVA_LINE_NUM\",\n"
//" \"IVA_LOT_NUM\",\n"
//" \"IVA_STATE\",\n"
//" \"IVA_AST_AST_ID\",\n"
//" \"IVA_SLO_SLO_ID\",\n"
//" \"SEA_ID\",\n"
//" \"SRC_ID\",\n"
//" \"PLG_ID_PLG_ID\",\n"
//" \"INF_VALUE_NUM\",\n"
//" \"INU_ID_INU_ID\"\n"
//" )\n"
//" SELECT\n"
//" 0 \"version\",\n"
//" (diff_value / diff_sec) \"IVA_VALUE\",\n"
//" now() \"IVA_CREA_DATE\",\n"
//" \"IVA_LINE_NUM\",\n"
//" \"IVA_LOT_NUM\",\n"
//" 0 \"IVA_STATE\",\n"
//" \"IVA_AST_AST_ID\",\n"
//" \"IVA_SLO_SLO_ID\",\n"
//" \"SEA_ID\",\n"
//" \"SRC_ID\",\n"
//" \"PLG_ID_PLG_ID\",\n"
//" \"INF_VALUE_NUM\",\n"
//" \"INU_ID_INU_ID\"\n"
//" FROM\n"
//" (\n"
//" SELECT\n"
//" \"IVA_ID\",\n"
//" \"IVA_VALUE\",\n"
//" \"SEA_ID\",\n"
//" \"SRC_ID\",\n"
//" \"PLG_ID_PLG_ID\",\n"
//" \"INF_VALUE_NUM\",\n"
//" \"INU_ID_INU_ID\",\n"
//" \"IVA_AST_AST_ID\",\n"
//" \"IVA_SLO_SLO_ID\",\n"
//" \"IVA_LINE_NUM\",\n"
//" \"IVA_LOT_NUM\",\n"
//" --first_value(\"IVA_CREA_DATE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" DESC ) max_date,\n"
//" --first_value(\"IVA_CREA_DATE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" ASC ) min_date,\n"
//" extract(epoch from (first_value(\"IVA_CREA_DATE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" DESC ) - first_value(\"IVA_CREA_DATE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" ASC ))) diff_sec,\n"
//" (CAST(first_value(\"IVA_VALUE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" DESC ) as float) - CAST(first_value(\"IVA_VALUE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" ASC ) as float)) diff_value\n"
//" --first_value(\"IVA_VALUE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" DESC ) max_value,\n"
//" --first_value(\"IVA_VALUE\") over(partition by \"SEA_ID\",\"SRC_ID\",\"PLG_ID_PLG_ID\",\"INF_VALUE_NUM\",\"INU_ID_INU_ID\",\"IVA_LINE_NUM\" order by \"IVA_CREA_DATE\" ASC ) min_value\n"
//" FROM\n"
//" (\n"
//" SELECT\n"
//" iva.\"IVA_ID\",\n"
//" iva.\"IVA_LINE_NUM\",\n"
//" iva.\"IVA_CREA_DATE\",\n"
//" iva.\"IVA_AST_AST_ID\",\n"
//" iva.\"SEA_ID\",\n"
//" iva.\"SRC_ID\",\n"
//" iva.\"PLG_ID_PLG_ID\",\n"
//" iva.\"INF_VALUE_NUM\",\n"
//" iva.\"IVA_VALUE\",\n"
//" iva.\"INU_ID_INU_ID\",\n"
//" iva.\"IVA_SLO_SLO_ID\",\n"
//" \"IVA_LOT_NUM\"\n"
//" FROM \"T_INFORMATION_VALUE_IVA\" iva\n"
//" WHERE\n"
//" \"SEA_ID\" = $1\n"
//" AND \"SRC_ID\" = $2\n"
//" AND \"PLG_ID_PLG_ID\" = $3\n"
//" AND \"INF_VALUE_NUM\" = $4\n"
//" AND \"INU_ID_INU_ID\" = $5\n"
//" AND \"IVA_STATE\" = 1 /* $6 lot number : aucun sens pour le calcul de moyenne */\n"
//" AND \"IVA_LINE_NUM\" = $8 /* on a besoin de savoir à quelle ligne ça appartient sinon on mélange tout, ici eth0 */\n"
//" /*AND (\"IVA_VALUE\" ~ '^[0-9]+$')*/\n"
//" AND \"IVA_AST_AST_ID\" = $9\n"
//" AND \"IVA_CREA_DATE\" <= (SELECT \"IVA_CREA_DATE\" FROM \"T_INFORMATION_VALUE_IVA\" WHERE \"IVA_ID\" = $11)\n"
//" ORDER BY \"IVA_ID\" DESC\n"
//" LIMIT $10\n"
//" ) sr\n"
//" ) sr_sr\n"
//" WHERE diff_sec != 0\n"
//" ORDER BY \"IVA_ID\" DESC\n"
//" LIMIT 1;\n"
//" $BODY$\n"
//" LANGUAGE sql VOLATILE\n"
//" COST 100;"
// );
//
// transaction.commit();
// }
// catch (Wt::Dbo::Exception e)
// {
// Wt::log("error") << e.what();
// }
//
// try
// {
// Wt::Dbo::Transaction transaction(session);
//
// Wt::log("info") << "Calculate CPU IVA Function Creation";
//
// session.execute
// (
//" CREATE OR REPLACE FUNCTION calculate_cpu_iva(integer, integer, integer, integer, integer, integer, integer, integer, integer, integer, integer)\n"
//" RETURNS void AS\n"
//" $BODY$\n"
//" INSERT INTO \"T_INFORMATION_VALUE_IVA\"\n"
//" (\n"
//" \"version\",\n"
//" \"IVA_VALUE\",\n"
//" \"IVA_CREA_DATE\",\n"
//" \"IVA_LINE_NUM\",\n"
//" \"IVA_LOT_NUM\",\n"
//" \"IVA_STATE\",\n"
//" \"IVA_AST_AST_ID\",\n"
//" \"IVA_SLO_SLO_ID\",\n"
//" \"SEA_ID\",\n"
//" \"SRC_ID\",\n"
//" \"PLG_ID_PLG_ID\",\n"
//" \"INF_VALUE_NUM\",\n"
//" \"INU_ID_INU_ID\"\n"
//" )\n"
//" SELECT\n"
//" 0 \"version\",\n"
//" (\n"
//" CAST ((\"WORK_JIFFIES\" - \"WORK_LAG_JIFFIES\") AS FLOAT)\n"
//" /\n"
//" CAST ((\"TOTAL_JIFFIES\" - \"TOTAL_LAG_JIFFIES\") AS FLOAT)\n"
//" *\n"
//" 100\n"
//" )\n"
//" \"IVA_VALUE\", -- CPU Usage\n"
//" \"IVA_CREA_DATE\",\n"
//" $8 \"IVA_LINE_NUM\",\n"
//" $6 \"IVA_LOT_NUM\",\n"
//" 0 \"IVA_STATE\",\n"
//" $9 \"IVA_AST_AST_ID\",\n"
//" \"IVA_SLO_SLO_ID\",\n"
//" $1 \"SEA_ID\",\n"
//" $2 \"SRC_ID\",\n"
//" $3 \"PLG_ID_PLG_ID\",\n"
//" -1 \"INF_VALUE_NUM\",\n"
//" 7 \"INU_ID_INU_ID\"\n"
//" FROM\n"
//" (\n"
//" SELECT\n"
//" (\n"
//" CAST(\"USER\" as bigint)\n"
//" + CAST(\"NICE\" as bigint)\n"
//" + CAST(\"SYSTEM\" as bigint)\n"
//" + CAST(\"IDLE\" as bigint)\n"
//" + CAST(\"IOWAIT\" as bigint)\n"
//" + CAST(\"IRQ\" as bigint)\n"
//" + CAST(\"SOFT_IRQ\" as bigint)\n"
//" ) \"TOTAL_JIFFIES\",\n"
//" (\n"
//" CAST(\"USER\" as bigint)\n"
//" + CAST(\"NICE\" as bigint)\n"
//" + CAST(\"SYSTEM\" as bigint)\n"
//" ) \"WORK_JIFFIES\",\n"
//" \"IVA_CREA_DATE\",\n"
//" (\n"
//" CAST(\"LAG_USER\" as bigint)\n"
//" + CAST(\"LAG_NICE\" as bigint)\n"
//" + CAST(\"LAG_SYSTEM\" as bigint)\n"
//" + CAST(\"LAG_IDLE\" as bigint)\n"
//" + CAST(\"LAG_IOWAIT\" as bigint)\n"
//" + CAST(\"LAG_IRQ\" as bigint)\n"
//" + CAST(\"LAG_SOFT_IRQ\" as bigint)\n"
//" ) \"TOTAL_LAG_JIFFIES\",\n"
//" (\n"
//" CAST(\"LAG_USER\" as bigint)\n"
//" + CAST(\"LAG_NICE\" as bigint)\n"
//" + CAST(\"LAG_SYSTEM\" as bigint)\n"
//" ) \"WORK_LAG_JIFFIES\",\n"
//" \"LAG_DATE\",\n"
//" \"IVA_SLO_SLO_ID\"\n"
//" FROM\n"
//" (\n"
//" SELECT\n"
//" \"IVA_AST_AST_ID\",\n"
//" \"IVA_CREA_DATE\",\n"
//" \"LAG_DATE\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 1) THEN \"IVA_VALUE\" END) AS \"INTERFACE_NAME\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 2) THEN \"IVA_VALUE\" END) AS \"USER\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 3) THEN \"IVA_VALUE\" END) AS \"NICE\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 4) THEN \"IVA_VALUE\" END) AS \"SYSTEM\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 5) THEN \"IVA_VALUE\" END) AS \"IDLE\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 6) THEN \"IVA_VALUE\" END) AS \"IOWAIT\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 7) THEN \"IVA_VALUE\" END) AS \"IRQ\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 8) THEN \"IVA_VALUE\" END) AS \"SOFT_IRQ\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 1) THEN \"LAG_VALUE\" END) AS \"LAG_INTERFACE_NAME\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 2) THEN \"LAG_VALUE\" END) AS \"LAG_USER\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 3) THEN \"LAG_VALUE\" END) AS \"LAG_NICE\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 4) THEN \"LAG_VALUE\" END) AS \"LAG_SYSTEM\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 5) THEN \"LAG_VALUE\" END) AS \"LAG_IDLE\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 6) THEN \"LAG_VALUE\" END) AS \"LAG_IOWAIT\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 7) THEN \"LAG_VALUE\" END) AS \"LAG_IRQ\",\n"
//" max (CASE WHEN (sr_sr.\"INF_VALUE_NUM\" = 8) THEN \"LAG_VALUE\" END) AS \"LAG_SOFT_IRQ\",\n"
//" min (\"IVA_SLO_SLO_ID\") \"IVA_SLO_SLO_ID\"\n"
//" FROM\n"
//" (\n"
//" SELECT\n"
//" \"IVA_ID\",\n"
//" \"IVA_CREA_DATE\",\n"
//" lag (\"IVA_CREA_DATE\") OVER (PARTITION BY \"IVA_AST_AST_ID\", \"SEA_ID\", \"SRC_ID\", \"PLG_ID_PLG_ID\", \"INF_VALUE_NUM\" ORDER BY \"IVA_ID\") \"LAG_DATE\",\n"
//" \"IVA_VALUE\",\n"
//" lag (\"IVA_VALUE\") OVER (PARTITION BY \"IVA_AST_AST_ID\", \"SEA_ID\", \"SRC_ID\", \"PLG_ID_PLG_ID\", \"INF_VALUE_NUM\" ORDER BY \"IVA_ID\") \"LAG_VALUE\",\n"
//" \"SEA_ID\",\n"
//" \"SRC_ID\",\n"
//" \"PLG_ID_PLG_ID\",\n"
//" \"INF_VALUE_NUM\",\n"
//" \"IVA_AST_AST_ID\",\n"
//" \"IVA_LINE_NUM\",\n"
//" \"IVA_LOT_NUM\",\n"
//" \"IVA_SLO_SLO_ID\"\n"
//" FROM \"T_INFORMATION_VALUE_IVA\" iva\n"
//" WHERE\n"
//" \"SEA_ID\" = $1\n"
//" AND \"SRC_ID\" = $2\n"
//" AND \"IVA_LOT_NUM\" IN\n"
//" (\n"
//" $6,\n"
//" (\n"
//" SELECT \"IVA_LOT_NUM\"\n"
//" FROM \"T_INFORMATION_VALUE_IVA\"\n"
//" WHERE\n"
//" \"SEA_ID\" = $1\n"
//" AND \"SRC_ID\" = $2\n"
//" AND \"IVA_LINE_NUM\" = $8\n"
//" AND \"PLG_ID_PLG_ID\" = $3\n"
//" AND \"INF_VALUE_NUM\" = $4\n"
//" /*AND \"INU_ID_INU_ID\" = 0*/\n"
//" AND \"IVA_AST_AST_ID\" = $9\n"
//" AND \"IVA_CREA_DATE\" <= (SELECT \"IVA_CREA_DATE\" FROM \"T_INFORMATION_VALUE_IVA\" WHERE \"IVA_ID\" = $11)\n"
//" ORDER BY \"IVA_ID\" DESC\n"
//" LIMIT 1\n"
//" OFFSET 1\n"
//" )\n"
//" )\n"
//" AND \"IVA_CREA_DATE\" <= (SELECT \"IVA_CREA_DATE\" FROM \"T_INFORMATION_VALUE_IVA\" WHERE \"IVA_ID\" = $11)\n"
//" AND \"IVA_LINE_NUM\" = $8\n"
//" AND \"PLG_ID_PLG_ID\" = $3\n"
//" AND \"IVA_AST_AST_ID\" = $9\n"
//" ORDER BY \"IVA_ID\" DESC\n"
//" LIMIT 8\n"
//" ) sr_sr\n"
//" WHERE \"IVA_LOT_NUM\" = $6\n"
//" GROUP BY \"IVA_AST_AST_ID\", \"IVA_CREA_DATE\", \"LAG_DATE\"\n"
//" ) sr_sr_sr\n"
//" ) sr_sr_sr_sr;\n"
//" $BODY$\n"
//" LANGUAGE sql VOLATILE\n"
//" COST 100;"
//
// );
//
// transaction.commit();
// }
// catch (Wt::Dbo::Exception e)
// {
// Wt::log("error") << e.what();
// }
//
//
// try
// {
// Wt::Dbo::Transaction transaction(session);
//
// Wt::log("info") << "Trigger IVA to IVH Creation";
//
// session.execute
// (
//" CREATE OR REPLACE FUNCTION trg_iva_ihv()\n"
//" RETURNS trigger AS\n"
//" $BODY$\n"
//" BEGIN\n"
//" INSERT INTO \"T_INFORMATION_HISTORICAL_VALUE_IHV\" VALUES \n"
//" (\n"
//" NEW.\"IVA_ID\",\n"
//" 0,\n"
//" NEW.\"IVA_VALUE\",\n"
//" NEW.\"IVA_CREA_DATE\",\n"
//" NEW.\"IVA_DELETE\",\n"
//" NEW.\"IVA_LINE_NUM\",\n"
//" NEW.\"IVA_LOT_NUM\",\n"
//" NEW.\"IVA_STATE\",\n"
//" NEW.\"IVA_AST_AST_ID\",\n"
//" NEW.\"IVA_SLO_SLO_ID\",\n"
//" NEW.\"SEA_ID\",\n"
//" NEW.\"SRC_ID\",\n"
//" NEW.\"PLG_ID_PLG_ID\",\n"
//" NEW.\"INF_VALUE_NUM\",\n"
//" NEW.\"INU_ID_INU_ID\"\n"
//" );\n"
//" RETURN NULL;\n"
//" END;\n"
//" $BODY$\n"
//" LANGUAGE plpgsql VOLATILE;"
// );
//
// session.execute
// (
//" CREATE TRIGGER insert_iva\n"
//" AFTER INSERT\n"
//" ON \"T_INFORMATION_VALUE_IVA\"\n"
//" FOR EACH ROW\n"
//" EXECUTE PROCEDURE trg_iva_ihv();"
// );
//
// transaction.commit();
// }
// catch (std::exception& e)
// {
// Wt::log("error") << e.what();
// }
//
// return EXIT_SUCCESS;
//}