-
Notifications
You must be signed in to change notification settings - Fork 1
/
charts.cpp
1707 lines (1571 loc) · 59.5 KB
/
charts.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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "charts.h"
#include "calltable.h"
extern int opt_nocdr;
extern int opt_id_sensor;
extern MySqlStore *sqlStore;
static sChartTypeDef ChartTypeDef[] = {
{ _chartType_total, 1, 1, _chartPercType_NA, 0, _chartSubType_count },
{ _chartType_count, 1, 1, _chartPercType_NA, 0, _chartSubType_count },
{ _chartType_cps, 1, 1, _chartPercType_NA, 0, _chartSubType_count },
{ _chartType_minutes, 1, 1, _chartPercType_NA, 0, _chartSubType_count },
{ _chartType_count_perc_short, 0, 1, _chartPercType_NA, 0, _chartSubType_perc },
{ _chartType_mos, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_caller, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_called, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_xr_avg, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_xr_avg_caller, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_xr_avg_called, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_xr_min, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_xr_min_caller, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_xr_min_called, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_silence_avg, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_silence_avg_caller, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_silence_avg_called, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_silence_min, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_silence_min_caller, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_silence_min_called, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_lqo_caller, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_mos_lqo_called, 0, 0, _chartPercType_Desc, 0, _chartSubType_value },
{ _chartType_packet_lost, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_packet_lost_caller, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_packet_lost_called, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_jitter, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_delay, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_rtcp_avgjitter, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_rtcp_maxjitter, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_rtcp_avgfr, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_rtcp_maxfr, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_silence, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_silence_caller, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_silence_called, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_silence_end, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_silence_end_caller, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_silence_end_called, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_clipping, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_clipping_caller, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_clipping_called, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_pdd, 0, 1, _chartPercType_Asc, 0, _chartSubType_value },
{ _chartType_acd_avg, 0, 1, _chartPercType_NA, 0, _chartSubType_acd_asr },
{ _chartType_acd, 0, 1, _chartPercType_NA, 0, _chartSubType_acd_asr },
{ _chartType_asr_avg, 0, 1, _chartPercType_NA, 0, _chartSubType_acd_asr },
{ _chartType_asr, 0, 1, _chartPercType_NA, 0, _chartSubType_acd_asr },
{ _chartType_ner_avg, 0, 1, _chartPercType_NA, 0, _chartSubType_acd_asr },
{ _chartType_ner, 0, 1, _chartPercType_NA, 0, _chartSubType_acd_asr },
{ _chartType_sipResp, 0, 1, _chartPercType_NA, 1, _chartSubType_count },
{ _chartType_sipResponse, 0, 1, _chartPercType_NA, 0, _chartSubType_area },
{ _chartType_sipResponse_base, 0, 1, _chartPercType_NA, 0, _chartSubType_area },
{ _chartType_codecs, 0, 1, _chartPercType_NA, 0, _chartSubType_area },
{ _chartType_IP_src, 0, 1, _chartPercType_NA, 0, _chartSubType_area },
{ _chartType_IP_dst, 0, 1, _chartPercType_NA, 0, _chartSubType_area },
{ _chartType_domain_src, 0, 1, _chartPercType_NA, 0, _chartSubType_area },
{ _chartType_domain_dst, 0, 1, _chartPercType_NA, 0, _chartSubType_area }
};
static cCharts *chartsCache;
static eChartType chartTypeFromString(string chartType);
static sChartTypeDef getChartTypeDef(eChartType chartType);
static bool cmpValCondEqLeft(const char *val1, const char *val2);
cChartDataItem::cChartDataItem() {
this->max = 0;
this->min = -1;
this->sum = 0;
this->count = 0;
this->countAll = 0;
this->countConected = 0;
this->sumDuration = 0;
this->countShort = 0;
}
void cChartDataItem::add(sChartsCallData *call,
unsigned call_interval, bool firstInterval, bool lastInterval, bool beginInInterval,
cChartSeries *series, cChartIntervalSeriesData *intervalSeries,
u_int32_t calldate_from, u_int32_t calldate_to) {
if(series->isArea() ||
series->isIntervals() ||
series->def.subType == _chartSubType_count) {
++this->count;
if(call_interval >= 0) {
++this->count_intervals[call_interval];
}
return;
}
if(!(beginInInterval && firstInterval)) {
return;
}
switch(series->def.subType) {
case _chartSubType_value:
{
double value;
bool value_null;
if(call->type == sChartsCallData::_call) {
call->call()->getChartCacheValue(series->def.chartType, &value, NULL, &value_null, chartsCache);
} else {
Call::getChartCacheValue(call->tables_content(), series->def.chartType, &value, NULL, &value_null, chartsCache);
}
if(!value_null && (value || series->def.enableZero)) {
if(series->def.percType != _chartPercType_NA) {
this->values.push_back(value);
}
if(value > this->max) {
this->max = value;
}
if(this->min == -1 || value < this->min) {
this->min = value;
}
this->sum += value;
++this->count;
}
}
break;
case _chartSubType_acd_asr:
switch(series->def.chartType) {
case _chartType_acd_avg:
case _chartType_acd:
case _chartType_asr_avg:
case _chartType_asr:
if(series->def.chartType == _chartType_acd ||
series->def.chartType == _chartType_asr ||
(firstInterval && beginInInterval)) {
++this->countAll;
if(call->type == sChartsCallData::_call) {
if(call->call()->connect_time_us) {
++this->countConected;
this->sumDuration += call->call()->connect_duration_s();
}
} else {
double connect_duration = call->tables_content()->getValue_float(Call::_t_cdr, "connect_duration");
if(connect_duration > 0) {
++this->countConected;
this->sumDuration += connect_duration;
}
}
}
break;
case _chartType_ner:
case _chartType_ner_avg:
if(series->def.chartType == _chartType_ner ||
(firstInterval && beginInInterval)) {
++this->countAll;
double lsr;
bool lsr_null;
if(call->type == sChartsCallData::_call) {
call->call()->getChartCacheValue(_chartType_sipResp, &lsr, NULL, &lsr_null, chartsCache);
if(call->call()->connect_time_us ||
series->ner_lsr_filter->check((unsigned)lsr)) {
++this->count;
}
} else {
Call::getChartCacheValue(call->tables_content(), _chartType_sipResp, &lsr, NULL, &lsr_null, chartsCache);
double connect_duration = call->tables_content()->getValue_float(Call::_t_cdr, "connect_duration");
if(connect_duration > 0 ||
series->ner_lsr_filter->check((unsigned)lsr)) {
++this->count;
}
}
}
break;
}
break;
case _chartSubType_perc:
switch(series->def.chartType) {
case _chartType_count_perc_short:
if(call->type == sChartsCallData::_call) {
if(call->call()->connect_time_us) {
unsigned int connect_duration = call->call()->connect_duration_s();
++this->countConected;
if(intervalSeries->param.size() &&
connect_duration < (unsigned)atoi(intervalSeries->param[0].c_str())) {
++this->countShort;
}
}
} else {
double connect_duration = call->tables_content()->getValue_float(Call::_t_cdr, "connect_duration");
if(connect_duration > 0) {
++this->countConected;
if(intervalSeries->param.size() &&
connect_duration < (unsigned)atoi(intervalSeries->param[0].c_str())) {
++this->countShort;
}
}
}
break;
}
break;
default:
break;
}
}
string cChartDataItem::json(cChartSeries *series) {
unsigned precision_base = 15;
unsigned precision_vm = 6;
if(series->isArea() ||
series->isIntervals() ||
series->def.subType == _chartSubType_count) {
if(this->count_intervals.size()) {
stringstream ci_stream;
ci_stream << '{';
unsigned counter = 0;
for(map<unsigned int, unsigned int>::iterator iter = this->count_intervals.begin(); iter != this->count_intervals.end(); iter++) {
if(counter) {
ci_stream << ',';
}
ci_stream << '"' << iter->first << "\":" << iter->second;
++counter;
}
ci_stream << '}';
return(ci_stream.str());
} else if(this->count > 0) {
return(intToString(this->count));
} else {
return("");
}
}
switch(series->def.subType) {
case _chartSubType_value:
if(this->count > 0) {
std::sort(this->values.begin(), this->values.end());
JsonExport exp;
exp.add("_", "vcomb");
exp.add("m", floatToString(this->max, precision_base, true), JsonExport::_number);
exp.add("i", floatToString(this->min, precision_base, true), JsonExport::_number);
exp.add("s", floatToString(this->sum, precision_base, true), JsonExport::_number);
exp.add("c", this->count);
if(this->values.size()) {
for(unsigned i = 0; i < 2; i++) {
int perc = i == 0 ? 95 : 99;
size_t percIndex = ::min((size_t)round((double)this->values.size() * perc / 100), this->values.size() - 1);
if(series->def.percType == _chartPercType_Desc) {
percIndex = this->values.size() - 1 - percIndex;
}
exp.add(i == 0 ? "p5" : "p9", floatToString(this->values[percIndex], precision_base, true), JsonExport::_number);
}
map<double, unsigned> valuesCount;
map<double, unsigned> valuesCountReduk;
for(unsigned i = 0; i < this->values.size(); i++) {
++valuesCount[this->values[i]];
}
map<double, unsigned> *valuesCountRslt;
if(valuesCount.size() > chartsCache->maxValuesPartsForPercentile &&
(valuesCount.size() / chartsCache->maxValuesPartsForPercentile) > 1) {
unsigned counter = 0;
double s_v = 0;
unsigned s_c = 0;
for(map<double, unsigned>::iterator iter = valuesCount.begin(); iter != valuesCount.end(); iter++) {
double v_v = iter->first;
unsigned v_c = iter->second;
if(counter && !(counter % (valuesCount.size() / chartsCache->maxValuesPartsForPercentile))) {
double new_v = s_v / s_c;
valuesCountReduk[new_v] += s_c;
s_v = 0;
s_c = 0;
}
s_v += v_v * v_c;
s_c += v_c;
++counter;
}
if(s_c) {
double new_v = s_v / s_c;
valuesCountReduk[new_v] += s_c;
}
valuesCountRslt = &valuesCountReduk;
} else {
valuesCountRslt = &valuesCount;
}
stringstream vm_stream;
vm_stream << setprecision(precision_vm);
vm_stream << '{';
unsigned counter = 0;
for(map<double, unsigned>::iterator iter = valuesCountRslt->begin(); iter != valuesCountRslt->end(); iter++) {
if(counter) {
vm_stream << ',';
}
vm_stream << '"' << iter->first << "\":" << iter->second;
++counter;
}
vm_stream << '}';
exp.addJson("vm", vm_stream.str());
}
return(exp.getJson());
}
break;
case _chartSubType_acd_asr:
switch(series->def.chartType) {
case _chartType_acd_avg:
case _chartType_acd:
if(this->countConected) {
JsonExport exp;
exp.add("_", "cmp2");
exp.add("v1", this->sumDuration);
exp.add("v2", this->countConected);
return(exp.getJson());
}
break;
case _chartType_asr_avg:
case _chartType_asr:
if(this->countConected) {
JsonExport exp;
exp.add("_", "cmp2");
exp.add("v1", this->countConected);
exp.add("v2", this->countAll);
return(exp.getJson());
}
break;
case _chartType_ner_avg:
case _chartType_ner:
if(this->count) {
JsonExport exp;
exp.add("_", "cmp2");
exp.add("v1", this->count);
exp.add("v2", this->countAll);
return(exp.getJson());
}
break;
}
break;
case _chartSubType_perc:
switch(series->def.chartType) {
case _chartType_count_perc_short:
if(this->countShort) {
JsonExport exp;
exp.add("_", "cmp2");
exp.add("v1", this->countShort);
exp.add("v2", this->countConected);
return(exp.getJson());
}
break;
}
break;
default:
break;
}
return("");
}
cChartDataMultiseriesItem::cChartDataMultiseriesItem() {
}
cChartDataMultiseriesItem::~cChartDataMultiseriesItem() {
for(map<int, cChartDataItem*>::iterator iter = data.begin(); iter != data.end(); iter++) {
delete iter->second;
}
}
string cChartDataMultiseriesItem::json(cChartSeries *series, cChartIntervalSeriesData *intervalSeries) {
if(series->isIntervals()) {
if(data.size()) {
stringstream json_stream;
json_stream << "{\"_\":\"array\",\"a\":[";
unsigned counter = 0;
unsigned intervalIndex = 0;
for(map<int, cChartDataItem*>::iterator iter = data.begin(); iter != data.end(); iter++) {
while((int)intervalIndex < iter->first) {
if(counter) {
json_stream << ",";
}
json_stream << 0;
++intervalIndex;
++counter;
}
if(counter) {
json_stream << ",";
}
string json_str = iter->second->json(series);
if(!json_str.empty()) {
json_stream << json_str;
} else {
json_stream << 0;
}
intervalIndex = iter->first + 1;
++counter;
}
json_stream << "]}";
return(json_stream.str());
}
} else if(series->isArea()) {
if(data.size()) {
stringstream json_stream;
json_stream << "{\"_\":\"area\",";
unsigned counter = 0;
for(map<int, cChartDataItem*>::iterator iter = data.begin(); iter != data.end(); iter++) {
if(counter) {
json_stream << ",";
}
json_stream << '"' << json_string_escape(intervalSeries->param[iter->first].c_str()) << '"' << ':';
string json_str = iter->second->json(series);
if(!json_str.empty()) {
json_stream << json_str;
} else {
json_stream << 0;
}
++counter;
}
json_stream << "}";
return(json_stream.str());
}
} else {
if(data.size()) {
stringstream json_stream;
json_stream << "[";
unsigned counter = 0;
for(map<int, cChartDataItem*>::iterator iter = data.begin(); iter != data.end(); iter++) {
if(counter) {
json_stream << ",";
}
string json_str = iter->second->json(series);
if(!json_str.empty()) {
json_stream << json_str;
} else {
json_stream << 0;
}
++counter;
}
json_stream << "]";
return(json_stream.str());
}
}
return("");
}
cChartDataPool::cChartDataPool() {
this->all = 0;
this->all_fi = 0;
this->all_li = 0;
this->pool = NULL;
}
cChartDataPool::~cChartDataPool() {
if(this->pool) {
delete [] this->pool;
}
}
void cChartDataPool::createPool(u_int32_t timeFrom, u_int32_t timeTo) {
this->pool = new FILE_LINE(0) u_int32_t[timeTo - timeFrom];
memset((void*)this->pool, 0, (timeTo - timeFrom) * sizeof(u_int32_t));
}
void cChartDataPool::add(sChartsCallData *call, unsigned call_interval, bool firstInterval, bool lastInterval, bool beginInInterval,
cChartSeries *series, cChartInterval *interval,
u_int32_t calldate_from, u_int32_t calldate_to) {
unsigned int from, to;
switch(series->def.chartType) {
case _chartType_total:
case _chartType_count:
from = ::max(calldate_from, interval->timeFrom);
to = ::min(calldate_to, interval->timeTo - 1);
++this->all;
if(call_interval >= 0) {
++this->all_intervals[call_interval];
}
if(beginInInterval && firstInterval) {
++this->all_fi;
}
if(lastInterval) {
++this->all_li;
}
for(unsigned int i = from; i <= to; i++) {
++this->pool[i - interval->timeFrom];
}
break;
case _chartType_cps:
from = ::max(calldate_from, interval->timeFrom);
to = ::min(calldate_to, interval->timeTo - 1);
++this->all;
if(beginInInterval && firstInterval) {
++this->all_fi;
++this->pool[from - interval->timeFrom];
}
break;
case _chartType_minutes:
unsigned int connect_duration;
if(call->type == sChartsCallData::_call) {
connect_duration = call->call()->connect_duration_s();
} else {
connect_duration = call->tables_content()->getValue_int(Call::_t_cdr, "connect_duration");
}
unsigned int duration = calldate_to - calldate_from;
unsigned int calldate_from_connected = calldate_from + (duration - connect_duration);
from = ::max(calldate_from_connected, interval->timeFrom);
to = ::min(calldate_to, interval->timeTo);
//int secondsConnected = to - calldate_from_connected + 1;
int secondsConnected = to - from;
if(secondsConnected > 0) {
this->all += secondsConnected;
/*
for(unsigned int i = from; i <= to; i++) {
this->pool[i - interval->timeFrom] += i - calldate_from_connected + 1;
}
*/
}
break;
}
}
string cChartDataPool::json(class cChartSeries *series, cChartInterval *interval) {
unsigned int max = 0;
unsigned int min = UINT_MAX;
unsigned int sum = 0;
unsigned int count = 0;
string pool_str = "[";
for(unsigned int i = 0; i < interval->timeTo - interval->timeFrom; i++) {
if(i) {
pool_str += ',';
}
pool_str += intToString(this->pool[i]);
if(this->pool[i]) {
min = min == UINT_MAX ?
this->pool[i] :
((unsigned int)this->pool[i] < min ? this->pool[i] : min);
max = ((unsigned int)this->pool[i] > max ? this->pool[i] : max);
sum += this->pool[i];
++count;
}
}
pool_str += "]";
if(min == UINT_MAX) {
min = 0;
}
switch(series->def.chartType) {
case _chartType_total:
if(this->all_intervals.size() || this->all > 0) {
JsonExport exp;
exp.add("_", "sum");
if(this->all_intervals.size()) {
string sum = "{";
unsigned counter = 0;
for(map<unsigned int, unsigned int>::iterator iter = this->all_intervals.begin(); iter != this->all_intervals.end(); iter++) {
if(counter) {
sum += ',';
}
sum += '"' + intToString(iter->first) + "\":" + intToString(iter->second);
++counter;
}
sum += "}";
return(sum);
} else if(this->all > 0) {
return(intToString(this->all));
}
}
break;
case _chartType_count:
case _chartType_cps:
if(count > 0) {
JsonExport exp;
exp.add("_", "mia");
exp.add("m", max);
exp.add("i", min);
exp.add("s", sum);
exp.add("c", count);
exp.addJson("p", pool_str);
return(exp.getJson());
}
break;
case _chartType_minutes:
if(this->all > 0) {
return(floatToString(this->all / 60., 6, true));
}
break;
}
return("");
}
cChartIntervalSeriesData::cChartIntervalSeriesData(cChartSeries *series, cChartInterval *interval) {
this->series = series;
this->interval = interval;
this->dataItem = NULL;
this->dataPool = NULL;
this->dataMultiseriesItem = NULL;
this->sync_data = 0;
__SYNC_INC(series->used_counter);
}
cChartIntervalSeriesData::~cChartIntervalSeriesData() {
if(dataItem) {
delete dataItem;
}
if(dataPool) {
delete dataPool;
}
if(dataMultiseriesItem) {
delete dataMultiseriesItem;
}
__SYNC_DEC(series->used_counter);
}
void cChartIntervalSeriesData::prepareData() {
if(!series || !interval) {
return;
}
if(series->def.pool) {
this->dataPool = new FILE_LINE(0) cChartDataPool();
this->dataPool->createPool(interval->timeFrom, interval->timeTo);
this->dataItem = NULL;
this->dataMultiseriesItem = NULL;
} else {
if(series->isArea() || series->isIntervals()) {
this->dataMultiseriesItem = new FILE_LINE(0) cChartDataMultiseriesItem();
this->dataItem = NULL;
this->dataPool = NULL;
} else {
this->dataItem = new FILE_LINE(0) cChartDataItem();
this->dataPool = NULL;
this->dataMultiseriesItem = NULL;
}
}
param = series->param;
param_map = series->param_map;
}
void cChartIntervalSeriesData::add(sChartsCallData *call, unsigned call_interval, bool firstInterval, bool lastInterval, bool beginInInterval,
u_int32_t calldate_from, u_int32_t calldate_to) {
lock_data();
double value;
string value_str;
bool value_null;
if(call->type == sChartsCallData::_call) {
call->call()->getChartCacheValue(series->def.chartType, &value, &value_str, &value_null, chartsCache);
} else {
Call::getChartCacheValue(call->tables_content(), series->def.chartType, &value, &value_str, &value_null, chartsCache);
}
if(this->series->isIntervals()) {
if(value_null) {
unlock_data();
return;
}
unsigned intervalIndex;
for(intervalIndex = 0; intervalIndex < this->series->intervals.size(); intervalIndex++) {
if(value < this->series->intervals[intervalIndex]) {
break;
}
}
if(!this->dataMultiseriesItem->data[intervalIndex]) {
this->dataMultiseriesItem->data[intervalIndex] = new FILE_LINE(0) cChartDataItem();
}
this->dataMultiseriesItem->data[intervalIndex]->add(call, call_interval, firstInterval, lastInterval, beginInInterval,
this->series, this,
calldate_from, calldate_to);
unlock_data();
return;
} else if(this->series->isArea()) {
if(value_null) {
unlock_data();
return;
}
if(value_str.empty()) {
if(value - floor(value) < 1e-10) {
value_str = intToString((int)value);
} else {
value_str = floatToString(value, 6, true);
}
}
transform(value_str.begin(), value_str.end(), value_str.begin(), ::tolower);
map<string_icase, int>::iterator iter = this->param_map.find(value_str);
if(iter == this->param_map.end()) {
this->param.push_back(value_str);
this->param_map[value_str] = this->param.size() - 1;
iter = this->param_map.find(value_str);
}
if(iter != this->param_map.end()) {
int valIndex = iter->second;
if(!this->dataMultiseriesItem->data[valIndex]) {
this->dataMultiseriesItem->data[valIndex] = new FILE_LINE(0) cChartDataItem();
}
this->dataMultiseriesItem->data[valIndex]->add(call, call_interval, firstInterval, lastInterval, beginInInterval,
this->series, this,
calldate_from, calldate_to);
}
unlock_data();
return;
}
if(this->series->def.chartType != _chartType_count_perc_short &&
this->param.size()) {
if(value_null) {
unlock_data();
return;
}
if(value_str.empty()) {
if(value - floor(value) < 1e-10) {
value_str = intToString((int)value);
} else {
value_str = floatToString(value, 6, true);
}
}
if(value_str.empty()) {
unlock_data();
return;
}
bool ok = false;
for(size_t i = 0; !ok && (i < this->param.size()); i++) {
if(this->series->def.condEqLeft) {
if(cmpValCondEqLeft(value_str.c_str(), this->param[i].c_str())) {
ok = true;
}
} else {
if(value_str == this->param[i]) {
ok = true;
}
}
}
if(!ok) {
unlock_data();
return;
}
}
if(this->dataPool) {
this->dataPool->add(call, call_interval, firstInterval, lastInterval, beginInInterval,
this->series, this->interval,
calldate_from, calldate_to);
}
if(this->dataItem) {
this->dataItem->add(call, call_interval, firstInterval, lastInterval, beginInInterval,
this->series, this,
calldate_from, calldate_to);
}
unlock_data();
}
void cChartIntervalSeriesData::store(cChartInterval *interval, SqlDb *sqlDb) {
string chart_data;
if(this->dataItem) {
chart_data = this->dataItem->json(this->series);
}
if(this->dataPool) {
chart_data = this->dataPool->json(this->series, interval);
}
if(this->dataMultiseriesItem) {
chart_data = this->dataMultiseriesItem->json(this->series, this);
}
if(chart_data.empty()) {
return;
}
SqlDb_row cache_row;
cache_row.add(this->series->id, "series_id");
cache_row.add("TA_MINUTES", "type");
cache_row.add(sqlDateTimeString(interval->timeFrom), "from_time");
cache_row.add(chart_data, "chart_data");
if(opt_id_sensor > 0) {
cache_row.add(opt_id_sensor, "sensor_id");
}
string insert_str = MYSQL_ADD_QUERY_END(MYSQL_MAIN_INSERT_GROUP +
sqlDb->insertQuery("chart_sniffer_series_cache", cache_row, false, false, true));
sqlStore->query_lock(insert_str.c_str(), STORE_PROC_ID_CDR_1);
}
cChartInterval::cChartInterval() {
last_store_at = 0;
last_store_at_real = getTimeS();
counter_add = 0;
}
cChartInterval::~cChartInterval() {
clear();
}
void cChartInterval::setInterval(u_int32_t timeFrom, u_int32_t timeTo) {
this->timeFrom = timeFrom;
this->timeTo = timeTo;
init();
}
void cChartInterval::add(sChartsCallData *call, unsigned call_interval, bool firstInterval, bool lastInterval, bool beginInInterval,
u_int32_t calldate_from, u_int32_t calldate_to,
map<cChartFilter*, bool> *filters_map) {
for(map<string, cChartIntervalSeriesData*>::iterator iter = this->seriesData.begin(); iter != this->seriesData.end(); iter++) {
if(iter->second->series->checkFilters(filters_map)) {
iter->second->add(call, call_interval, firstInterval, lastInterval, beginInInterval,
calldate_from, calldate_to);
}
}
++counter_add;
}
void cChartInterval::store(u_int32_t act_time, u_int32_t real_time, SqlDb *sqlDb) {
if(counter_add) {
for(map<string, cChartIntervalSeriesData*>::iterator iter = this->seriesData.begin(); iter != this->seriesData.end(); iter++) {
iter->second->store(this, sqlDb);
}
counter_add = 0;
}
this->last_store_at = act_time;
this->last_store_at_real = real_time;
}
void cChartInterval::init() {
for(map<string, cChartSeries*>::iterator iter = chartsCache->series.begin(); iter != chartsCache->series.end(); iter++) {
this->seriesData[iter->second->config_id] = new FILE_LINE(0) cChartIntervalSeriesData(iter->second, this);
this->seriesData[iter->second->config_id]->prepareData();
}
}
void cChartInterval::clear() {
for(map<string, cChartIntervalSeriesData*>::iterator iter = this->seriesData.begin(); iter != this->seriesData.end(); iter++) {
delete iter->second;
}
seriesData.clear();
counter_add = 0;
}
cChartFilter::cChartFilter(const char *filter, const char *filter_only_sip_ip, const char *filter_without_sip_ip) {
this->filter = filter;
this->filter_only_sip_ip = filter_only_sip_ip;
this->filter_without_sip_ip = filter_without_sip_ip;
this->filter_s = NULL;
this->filter_only_sip_ip_s = NULL;
this->filter_without_sip_ip_s = NULL;
ip_filter_contain_sipcallerip = strcasestr(filter_only_sip_ip, "sipcallerip") != NULL;
ip_filter_contain_sipcalledip = strcasestr(filter_only_sip_ip, "sipcalledip") != NULL;
used_counter = 0;
}
cChartFilter::~cChartFilter() {
if(filter_s) {
delete filter_s;
}
if(filter_only_sip_ip_s) {
delete filter_only_sip_ip_s;
}
if(filter_without_sip_ip_s) {
delete filter_without_sip_ip_s;
}
}
#define TEST_CHECK_FILTER 0
#define TEST_FILTER 1
#if TEST_CHECK_FILTER == 1
u_int64_t __cc;
u_int64_t __ss;
u_int64_t __cc2;
u_int64_t __ss2;
#endif
bool cChartFilter::check(sChartsCallData *call, void *callData, cFiltersCache *filtersCache) {
#if TEST_CHECK_FILTER == 1
#if TEST_FILTER == 1
string filter =
"(1=1) AND ((( ( ( ((cdr.called LIKE '114200%' OR cdr.called LIKE '114260%' OR cdr.called LIKE '14200%' OR cdr.called LIKE '14209%' OR cdr.called LIKE '14260%' OR cdr.called LIKE '14269%' OR cdr.called LIKE '14310%' OR cdr.called LIKE '14319%' OR cdr.called LIKE '131200%' OR cdr.called LIKE '131260%' OR cdr.called LIKE '31200%' OR cdr.called LIKE '31209%' OR cdr.called LIKE '31260%' OR cdr.called LIKE '31269%' OR cdr.called LIKE '31310%' OR cdr.called LIKE '31319%')) ) ) "
"AND"
" ( (((cdr.sipcalledip = inet_aton('200.170.204.162')) OR (cdr.sipcalledip = inet_aton('200.170.204.164')) OR (cdr.sipcalledip = inet_aton('200.170.204.166')))) ) AND ( ( (((cdr.sipcallerip = inet_aton('10.1.0.203')) OR (cdr.sipcallerip = inet_aton('10.1.0.185')) OR (cdr.sipcallerip = inet_aton('10.1.0.170')) OR (cdr.sipcallerip = inet_aton('10.1.0.205')) OR (cdr.sipcallerip = inet_aton('10.1.0.204')) OR (cdr.sipcallerip = inet_aton('10.1.0.206')) OR (cdr.sipcallerip = inet_aton('10.1.0.162')) OR (cdr.sipcallerip = inet_aton('10.1.0.202')) OR (cdr.sipcallerip = inet_aton('10.1.0.163')) OR (cdr.sipcallerip = inet_aton('10.1.0.207')) OR (cdr.sipcallerip = inet_aton('10.1.0.208')) OR (cdr.sipcallerip = inet_aton('10.1.0.45')) OR (cdr.sipcallerip = inet_aton('10.1.0.51')) OR (cdr.sipcallerip = inet_aton('10.1.0.164')) OR (cdr.sipcallerip = inet_aton('10.1.0.165')) OR (cdr.sipcallerip = inet_aton('10.1.0.210')) OR (cdr.sipcallerip = inet_aton('10.1.0.201')) OR (cdr.sipcallerip = inet_aton('10.1.0.209')) OR (cdr.sipcallerip = inet_aton('10.0.0.201')) OR (cdr.sipcallerip = inet_aton('10.0.0.74')) OR (cdr.sipcallerip = inet_aton('10.0.0.134')) OR (cdr.sipcallerip = inet_aton('10.0.0.197')) OR (cdr.sipcallerip = inet_aton('10.0.0.77')) OR (cdr.sipcallerip = inet_aton('10.0.0.32')) OR (cdr.sipcallerip = inet_aton('10.0.0.31')) OR (cdr.sipcallerip = inet_aton('10.0.0.82')) OR (cdr.sipcallerip = inet_aton('10.0.0.120')) OR (cdr.sipcallerip = inet_aton('10.0.0.84')) OR (cdr.sipcallerip = inet_aton('10.0.0.40')) OR (cdr.sipcallerip = inet_aton('10.0.0.41')) OR (cdr.sipcallerip = inet_aton('10.0.0.39')) OR (cdr.sipcallerip = inet_aton('10.0.0.36')) OR (cdr.sipcallerip = inet_aton('10.2.0.31')) OR (cdr.sipcallerip = inet_aton('10.1.0.64')) OR (cdr.sipcallerip = inet_aton('10.1.0.65')) OR (cdr.sipcallerip = inet_aton('10.1.0.66')) OR (cdr.sipcallerip = inet_aton('10.1.0.67')) OR (cdr.sipcallerip = inet_aton('10.1.0.63')) OR (cdr.sipcallerip = inet_aton('10.1.0.68')) OR (cdr.sipcallerip = inet_aton('10.1.0.139')) OR (cdr.sipcallerip = inet_aton('10.1.0.140')) OR (cdr.sipcallerip = inet_aton('10.1.0.141')) OR (cdr.sipcallerip = inet_aton('10.1.0.62')) OR (cdr.sipcallerip = inet_aton('10.1.0.142')))) ) ) )) OR (( ( ( ((cdr.called LIKE '64200%' OR cdr.called LIKE '64209%' OR cdr.called LIKE '64260%' OR cdr.called LIKE '64269%')) ) ) AND ( (((cdr.sipcallerip = inet_aton('200.170.204.162')) OR (cdr.sipcallerip = inet_aton('200.170.204.164')) OR (cdr.sipcallerip = inet_aton('200.170.204.166')))) ) AND ( ( (((cdr.sipcalledip = inet_aton('10.1.0.203')) OR (cdr.sipcalledip = inet_aton('10.1.0.185')) OR (cdr.sipcalledip = inet_aton('10.1.0.170')) OR (cdr.sipcalledip = inet_aton('10.1.0.205')) OR (cdr.sipcalledip = inet_aton('10.1.0.204')) OR (cdr.sipcalledip = inet_aton('10.1.0.206')) OR (cdr.sipcalledip = inet_aton('10.1.0.162')) OR (cdr.sipcalledip = inet_aton('10.1.0.202')) OR (cdr.sipcalledip = inet_aton('10.1.0.163')) OR (cdr.sipcalledip = inet_aton('10.1.0.207')) OR (cdr.sipcalledip = inet_aton('10.1.0.208')) OR (cdr.sipcalledip = inet_aton('10.1.0.45')) OR (cdr.sipcalledip = inet_aton('10.1.0.51')) OR (cdr.sipcalledip = inet_aton('10.1.0.164')) OR (cdr.sipcalledip = inet_aton('10.1.0.165')) OR (cdr.sipcalledip = inet_aton('10.1.0.210')) OR (cdr.sipcalledip = inet_aton('10.1.0.201')) OR (cdr.sipcalledip = inet_aton('10.1.0.209')) OR (cdr.sipcalledip = inet_aton('10.0.0.201')) OR (cdr.sipcalledip = inet_aton('10.0.0.74')) OR (cdr.sipcalledip = inet_aton('10.0.0.134')) OR (cdr.sipcalledip = inet_aton('10.0.0.197')) OR (cdr.sipcalledip = inet_aton('10.0.0.77')) OR (cdr.sipcalledip = inet_aton('10.0.0.32')) OR (cdr.sipcalledip = inet_aton('10.0.0.31')) OR (cdr.sipcalledip = inet_aton('10.0.0.82')) OR (cdr.sipcalledip = inet_aton('10.0.0.120')) OR (cdr.sipcalledip = inet_aton('10.0.0.84')) OR (cdr.sipcalledip = inet_aton('10.0.0.40')) OR (cdr.sipcalledip = inet_aton('10.0.0.41')) OR (cdr.sipcalledip = inet_aton('10.0.0.39')) OR (cdr.sipcalledip = inet_aton('10.0.0.36')) OR (cdr.sipcalledip = inet_aton('10.2.0.31')) OR (cdr.sipcalledip = inet_aton('10.1.0.64')) OR (cdr.sipcalledip = inet_aton('10.1.0.65')) OR (cdr.sipcalledip = inet_aton('10.1.0.66')) OR (cdr.sipcalledip = inet_aton('10.1.0.67')) OR (cdr.sipcalledip = inet_aton('10.1.0.63')) OR (cdr.sipcalledip = inet_aton('10.1.0.68')) OR (cdr.sipcalledip = inet_aton('10.1.0.139')) OR (cdr.sipcalledip = inet_aton('10.1.0.140')) OR (cdr.sipcalledip = inet_aton('10.1.0.141')) OR (cdr.sipcalledip = inet_aton('10.1.0.62')) OR (cdr.sipcalledip = inet_aton('10.1.0.142')))) ) ) )))";
/*filter =
"( ( (((cdr.sipcallerip = inet_aton('10.1.0.203')) OR (cdr.sipcallerip = inet_aton('10.1.0.185')) OR (cdr.sipcallerip = inet_aton('10.1.0.170')) OR (cdr.sipcallerip = inet_aton('10.1.0.205')) OR (cdr.sipcallerip = inet_aton('10.1.0.204')) OR (cdr.sipcallerip = inet_aton('10.1.0.206')) OR (cdr.sipcallerip = inet_aton('10.1.0.162')) OR (cdr.sipcallerip = inet_aton('10.1.0.202')) OR (cdr.sipcallerip = inet_aton('10.1.0.163')) OR (cdr.sipcallerip = inet_aton('10.1.0.207')) OR (cdr.sipcallerip = inet_aton('10.1.0.208')) OR (cdr.sipcallerip = inet_aton('10.1.0.45')) OR (cdr.sipcallerip = inet_aton('10.1.0.51')) OR (cdr.sipcallerip = inet_aton('10.1.0.164')) OR (cdr.sipcallerip = inet_aton('10.1.0.165')) OR (cdr.sipcallerip = inet_aton('10.1.0.210')) OR (cdr.sipcallerip = inet_aton('10.1.0.201')) OR (cdr.sipcallerip = inet_aton('10.1.0.209')) OR (cdr.sipcallerip = inet_aton('10.0.0.201')) OR (cdr.sipcallerip = inet_aton('10.0.0.74')) OR (cdr.sipcallerip = inet_aton('10.0.0.134')) OR (cdr.sipcallerip = inet_aton('10.0.0.197')) OR (cdr.sipcallerip = inet_aton('10.0.0.77')) OR (cdr.sipcallerip = inet_aton('10.0.0.32')) OR (cdr.sipcallerip = inet_aton('10.0.0.31')) OR (cdr.sipcallerip = inet_aton('10.0.0.82')) OR (cdr.sipcallerip = inet_aton('10.0.0.120')) OR (cdr.sipcallerip = inet_aton('10.0.0.84')) OR (cdr.sipcallerip = inet_aton('10.0.0.40')) OR (cdr.sipcallerip = inet_aton('10.0.0.41')) OR (cdr.sipcallerip = inet_aton('10.0.0.39')) OR (cdr.sipcallerip = inet_aton('10.0.0.36')) OR (cdr.sipcallerip = inet_aton('10.2.0.31')) OR (cdr.sipcallerip = inet_aton('10.1.0.64')) OR (cdr.sipcallerip = inet_aton('10.1.0.65')) OR (cdr.sipcallerip = inet_aton('10.1.0.66')) OR (cdr.sipcallerip = inet_aton('10.1.0.67')) OR (cdr.sipcallerip = inet_aton('10.1.0.63')) OR (cdr.sipcallerip = inet_aton('10.1.0.68')) OR (cdr.sipcallerip = inet_aton('10.1.0.139')) OR (cdr.sipcallerip = inet_aton('10.1.0.140')) OR (cdr.sipcallerip = inet_aton('10.1.0.141')) OR (cdr.sipcallerip = inet_aton('10.1.0.62')) OR (cdr.sipcallerip = inet_aton('10.1.0.142')))) ) )";*/
/*filter =
"(cdr.sipcallerip = inet_aton('10.1.0.203')) OR (cdr.sipcallerip = inet_aton('10.1.0.185'))";
filter =
"(cdr.sipcallerip = inet_aton('10.1.0.203'))";*/
cEvalFormula f(cEvalFormula::_est_sql, sverb.charts_cache_filters_eval);
f.setSqlData(cEvalFormula::_estd_call, call, callData);
u_int64_t s,e;
/*s = getTimeUS();
for(unsigned i = 0; i < 10000; i++) {
f.e(filter.c_str()).getBool();
}
e = getTimeUS();
cout << "0: " << floatToString((e - s) / 10000., 3) << endl;*/
bool rslt;
if(!filter_s) {
filter_s = new FILE_LINE(0) cEvalFormula::sSplitOperands(0);
rslt = f.e(filter.c_str(), 0, 0, 0, filter_s).getBool();
unsigned c = 0;
while(f.e_opt(filter_s)) {
++c;
}
cout << "opt " << c << endl;
} else {
rslt = f.e(filter_s).getBool();
}
s = getTimeUS();
unsigned l = 1000000;
for(unsigned i = 0; i < l; i++) {
f.e(filter_s).getBool();
}
e = getTimeUS();
cout << "1: " << floatToString((e - s) / (double)l, 3) << endl;
f.e(filter_s).getBool();
return(rslt);
#else
cout << " filter : " << filter << endl;
cEvalFormula f(cEvalFormula::_est_sql, sverb.charts_cache_filters_eval);
f.setSqlData(cEvalFormula::_estd_call, call, callData);
u_int64_t s = getTimeUS();
for(unsigned i = 0; i < 10000; i++) {
f.e(filter.c_str()).getBool();
}
u_int64_t e = getTimeUS();
cout << "0: " << floatToString((e - s) / 10000., 3) << endl;
__ss += e - s;
++__cc;
cout << __cc << " / " << __ss << endl;
bool rslt;
if(!filter_s) {
filter_s = new FILE_LINE(0) cEvalFormula::sSplitOperands(0);
rslt = f.e(filter.c_str(), 0, 0, 0, filter_s).getBool();
while(f.e_opt(filter_s));
} else {
rslt = f.e(filter_s).getBool();
}
s = getTimeUS();
for(unsigned i = 0; i < 10000; i++) {
f.e(filter_s).getBool();
}
e = getTimeUS();
cout << "1: " << floatToString((e - s) / 10000., 3) << endl;
__ss2 += e - s;
++__cc2;
cout << __cc2 << " / " << __ss2 << endl;
return(rslt);
#endif
#else
/*
string f1 = "(1 + 2 * 3) * (1 + 2 * 3)";
//string f1 = "cdr.duration > 10";
cEvalFormula::sSplitOperands so;
cEvalSqlFormula f2(true);
f2.setData(call, callData);
cEvalFormula::sValue rslt1 = f2.e(f1.c_str(), 0, 0, 0, &so);
cout << rslt1.getString() << endl;
cEvalFormula::sValue rslt2 = f2.e(&so);
cout << rslt2.getString() << endl;
cout << "---" << endl;
*/
//string filter = "((((cdr.sipcallerip = inet_aton('192.168.1.12')) OR (cdr.sipcalledip = inet_aton('192.168.1.12')))))";
//string filter = "(( ( ( (((cdr.sipcalledip = inet_aton('187.60.52.104')))) ) ) OR cdr.id in (select cdr_id from cdr_proxy where ( ( (((dst = inet_aton('187.60.52.104')))) ) ) ))) AND ( (wvch_sip_response.lastSIPresponse LIKE '%Call Throttled') ) AND cdr.id_sensor = 72";
//string filter = "(cdr.sipcalledip = inet_aton('187.60.52.104') OR cdr.id in (select cdr_id from cdr_proxy where dst = inet_aton('187.60.52.104'))) AND wvch_sip_response.lastSIPresponse LIKE '%Call Throttled' AND cdr.id_sensor = 72";
//string filter = "cdr.sipcalledip = inet_aton('187.60.52.104') AND wvch_sip_response.lastSIPresponse LIKE '%Call Throttled' AND cdr.id_sensor = 72";
//string filter = "cdr.sipcalledip = inet_aton('187.60.52.104') AND wvch_sip_response.lastSIPresponse LIKE '%Call Throttled'";
//string filter = "cdr.sipcalledip = inet_aton('187.60.52.104')";
//string filter = "wvch_sip_response.lastSIPresponse LIKE '%Call Throttled'";
//cout << filter << endl;
if(filtersCache) {
vmIP ip1, ip2;
int useIP = ip_filter_contain_sipcallerip && ip_filter_contain_sipcalledip ? 2 :
ip_filter_contain_sipcallerip || ip_filter_contain_sipcalledip ? 1 : 0;
int rsltCache = -2;
if(useIP == 2) {
if(call->type == sChartsCallData::_call) {
ip1 = call->call()->sipcallerip[0];
ip2 = call->call()->sipcalledip_rslt;
} else {
ip1 = call->tables_content()->getValue_ip(Call::_t_cdr, "sipcallerip");
ip2 = call->tables_content()->getValue_ip(Call::_t_cdr, "sipcalledip");
}
rsltCache = filtersCache->get(this, &ip1, &ip2);
} else if(useIP == 1) {
if(call->type == sChartsCallData::_call) {
ip1 = ip_filter_contain_sipcallerip ? call->call()->sipcallerip[0] : call->call()->sipcalledip_rslt;
} else {
ip1 = call->tables_content()->getValue_ip(Call::_t_cdr, ip_filter_contain_sipcallerip ? "sipcallerip" : "sipcalledip");
}
rsltCache = filtersCache->get(this, &ip1);