Passed
Push — master ( 38a638...9c837b )
by Tony
08:34
created

get95thIn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 3
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
use LibreNMS\Config;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Config. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
6
function format_bytes_billing($value)
7
{
8
    return format_number($value, Config::get('billing.base')).'B';
9
}//end format_bytes_billing()
10
11
12
function format_bytes_billing_short($value)
13
{
14
    return format_number($value, Config::get('billing.base'), 2, 3);
15
}//end format_bytes_billing_short()
16
17
18
function getDates($dayofmonth, $months = 0)
19
{
20
    $dayofmonth = zeropad($dayofmonth);
21
    $year       = date('Y');
22
    $month      = date('m');
23
24
    if (date('d') > $dayofmonth) {
25
        // Billing day is past, so it is next month
26
        $date_end   = date_create($year.'-'.$month.'-'.$dayofmonth);
27
        $date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
28
        date_add($date_end, date_interval_create_from_date_string('1 month'));
0 ignored issues
show
Bug introduced by
It seems like $date_end can also be of type false; however, parameter $object of date_add() does only seem to accept DateTime, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
        date_add(/** @scrutinizer ignore-type */ $date_end, date_interval_create_from_date_string('1 month'));
Loading history...
29
    } else {
30
        // Billing day will happen this month, therefore started last month
31
        $date_end   = date_create($year.'-'.$month.'-'.$dayofmonth);
32
        $date_start = date_create($year.'-'.$month.'-'.$dayofmonth);
33
        date_sub($date_start, date_interval_create_from_date_string('1 month'));
0 ignored issues
show
Bug introduced by
It seems like $date_start can also be of type false; however, parameter $object of date_sub() does only seem to accept DateTime, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        date_sub(/** @scrutinizer ignore-type */ $date_start, date_interval_create_from_date_string('1 month'));
Loading history...
34
    }
35
36
    if ($months > 0) {
37
        date_sub($date_start, date_interval_create_from_date_string($months.' month'));
38
        date_sub($date_end, date_interval_create_from_date_string($months.' month'));
39
    }
40
41
    // date_sub($date_start, date_interval_create_from_date_string('1 month'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
    date_sub($date_end, date_interval_create_from_date_string('1 day'));
43
44
    $date_from = date_format($date_start, 'Ymd').'000000';
45
    $date_to   = date_format($date_end, 'Ymd').'235959';
46
47
    date_sub($date_start, date_interval_create_from_date_string('1 month'));
48
    date_sub($date_end, date_interval_create_from_date_string('1 month'));
49
50
    $last_from = date_format($date_start, 'Ymd').'000000';
51
    $last_to   = date_format($date_end, 'Ymd').'235959';
52
53
    $return      = array();
54
    $return['0'] = $date_from;
55
    $return['1'] = $date_to;
56
    $return['2'] = $last_from;
57
    $return['3'] = $last_to;
58
59
    return ($return);
60
}//end getDates()
61
62
function getPredictedUsage($bill_day, $cur_used)
63
{
64
65
    $tmp = getDates($bill_day, 0);
66
    $start = new DateTime($tmp[0], new DateTimeZone(date_default_timezone_get()));
67
    $end   = new DateTime($tmp[1], new DateTimeZone(date_default_timezone_get()));
68
    $now   = new DateTime(date("Y-m-d"), new DateTimeZone(date_default_timezone_get()));
69
    $total = $end->diff($start)->format("%a");
70
    $since = $now->diff($start)->format("%a");
71
    return($cur_used/$since*$total);
72
}
73
74
function getValue($host, $port, $id, $inout)
75
{
76
    $oid    = 'IF-MIB::ifHC'.$inout.'Octets.'.$id;
77
    $device = dbFetchRow("SELECT * from `devices` WHERE `hostname` = ? LIMIT 1", array($host));
78
    $value  = snmp_get($device, $oid, '-Oqv');
79
80
    if (!is_numeric($value)) {
81
        $oid   = 'IF-MIB::if'.$inout.'Octets.'.$id;
82
        $value = snmp_get($device, $oid, '-Oqv');
83
    }
84
85
    return $value;
86
}//end getValue()
87
88
function getLastPortCounter($port_id, $bill_id)
89
{
90
    $return = array();
91
    $row    = dbFetchRow("SELECT timestamp, in_counter, in_delta, out_counter, out_delta FROM bill_port_counters WHERE `port_id` = ? AND `bill_id` = ?", array($port_id, $bill_id));
92
    if (!is_null($row)) {
93
        $return['timestamp']   = $row['timestamp'];
94
        $return['in_counter']  = $row['in_counter'];
95
        $return['in_delta']    = $row['in_delta'];
96
        $return['out_counter'] = $row['out_counter'];
97
        $return['out_delta']   = $row['out_delta'];
98
        $return['state']       = 'ok';
99
    } else {
100
        $return['state']       = 'failed';
101
    }
102
    return $return;
103
}//end getLastPortCounter()
104
105
106
function getLastMeasurement($bill_id)
107
{
108
    $return = array();
109
    $row    = dbFetchRow("SELECT timestamp,delta,in_delta,out_delta FROM bill_data WHERE bill_id = ? ORDER BY timestamp DESC LIMIT 1", array($bill_id));
110
    if (!is_null($row)) {
111
        $return['delta']     = $row['delta'];
112
        $return['delta_in']  = $row['delta_in'];
113
        $return['delta_out'] = $row['delta_out'];
114
        $return['timestamp'] = $row['timestamp'];
115
        $return['state']     = 'ok';
116
    } else {
117
        $return['state'] = 'failed';
118
    }
119
    return ($return);
120
}//end getLastMeasurement()
121
122
function get95thagg($bill_id, $datefrom, $dateto)
123
{
124
    $mq_sql           = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
125
    $mq_sql          .= " AND timestamp > ? AND timestamp <= ?";
126
    $measurements     = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
127
    $measurement_95th = (round(($measurements / 100 * 95)) - 1);
128
129
    $q_95_sql  = "SELECT (delta / period * 8) AS rate FROM bill_data  WHERE bill_id = ?";
130
    $q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
131
    $a_95th    = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
132
    $m_95th    = $a_95th[$measurement_95th];
133
134
    return (round($m_95th, 2));
135
}//end get95thagg()
136
137
138
function get95thIn($bill_id, $datefrom, $dateto)
139
{
140
    $mq_sql           = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
141
    $mq_sql          .= " AND timestamp > ? AND timestamp <= ?";
142
    $measurements     = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
143
    $measurement_95th = (round(($measurements / 100 * 95)) - 1);
144
145
    $q_95_sql  = "SELECT (in_delta / period * 8) AS rate FROM bill_data  WHERE bill_id = ?";
146
    $q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
147
    $a_95th    = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
148
    $m_95th    = $a_95th[$measurement_95th];
149
150
    return (round($m_95th, 2));
151
}//end get95thIn()
152
153
154
function get95thout($bill_id, $datefrom, $dateto)
155
{
156
    $mq_sql           = "SELECT count(delta) FROM bill_data WHERE bill_id = ?";
157
    $mq_sql          .= " AND timestamp > ? AND timestamp <= ?";
158
    $measurements     = dbFetchCell($mq_sql, array($bill_id, $datefrom, $dateto));
159
    $measurement_95th = (round(($measurements / 100 * 95)) - 1);
160
161
    $q_95_sql  = "SELECT (out_delta / period * 8) AS rate FROM bill_data  WHERE bill_id = ?";
162
    $q_95_sql .= " AND timestamp > ? AND timestamp <= ? ORDER BY rate ASC";
163
    $a_95th    = dbFetchColumn($q_95_sql, array($bill_id, $datefrom, $dateto));
164
    $m_95th    = $a_95th[$measurement_95th];
165
166
    return (round($m_95th, 2));
167
}//end get95thout()
168
169
170
function getRates($bill_id, $datefrom, $dateto, $dir_95th)
171
{
172
    $data = [];
173
174
    $sum_data = getSum($bill_id, $datefrom, $dateto);
175
    $mtot     = $sum_data['total'];
176
    $mtot_in  = $sum_data['inbound'];
177
    $mtot_out = $sum_data['outbound'];
178
    $ptot     = $sum_data['period'];
179
180
    $data['rate_95th_in']  = get95thIn($bill_id, $datefrom, $dateto);
181
    $data['rate_95th_out'] = get95thout($bill_id, $datefrom, $dateto);
182
183
    if ($dir_95th == 'agg') {
184
        $data['rate_95th'] = get95thagg($bill_id, $datefrom, $dateto);
185
        $data['dir_95th'] = 'agg';
186
    } else {
187
        if ($data['rate_95th_out'] > $data['rate_95th_in']) {
188
            $data['rate_95th'] = $data['rate_95th_out'];
189
            $data['dir_95th']  = 'out';
190
        } else {
191
            $data['rate_95th'] = $data['rate_95th_in'];
192
            $data['dir_95th']  = 'in';
193
        }
194
    }
195
196
    $data['total_data']     = $mtot;
197
    $data['total_data_in']  = $mtot_in;
198
    $data['total_data_out'] = $mtot_out;
199
    $data['rate_average']   = ($mtot / $ptot * 8);
200
    $data['rate_average_in']   = ($mtot_in / $ptot * 8);
201
    $data['rate_average_out']  = ($mtot_out / $ptot * 8);
202
203
    // print_r($data);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
204
    return ($data);
205
}//end getRates()
206
207
208
function getTotal($bill_id, $datefrom, $dateto)
209
{
210
    $mtot = dbFetchCell("SELECT SUM(delta) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
211
    return ($mtot);
212
}//end getTotal()
213
214
215
function getSum($bill_id, $datefrom, $dateto)
216
{
217
    $sum = dbFetchRow("SELECT SUM(period) as period, SUM(delta) as total, SUM(in_delta) as inbound, SUM(out_delta) as outbound FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
218
    return ($sum);
219
}//end getSum()
220
221
222
function getPeriod($bill_id, $datefrom, $dateto)
223
{
224
    $ptot = dbFetchCell("SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?", array($bill_id, $datefrom, $dateto));
225
    return ($ptot);
226
}//end getPeriod()
227
228
function getBillingHistoryBitsGraphData($bill_id, $bill_hist_id, $reducefactor)
229
{
230
    $histrow = dbFetchRow('SELECT UNIX_TIMESTAMP(bill_datefrom) as `from`, UNIX_TIMESTAMP(bill_dateto) AS `to`, rate_95th, rate_average, bill_type FROM bill_history WHERE bill_id = ? AND bill_hist_id = ?', array($bill_id, $bill_hist_id));
231
232
    if (is_null($histrow)) {
233
        return null;
234
    }
235
236
    $graph_data = getBillingBitsGraphData($bill_id, $histrow['from'], $histrow['to'], $reducefactor);
237
238
    // Overwrite the rate data with the historical version
239
    $graph_data['rate_95th']    = $histrow['rate_95th'];
240
    $graph_data['rate_average'] = $histrow['rate_average'];
241
    $graph_data['bill_type']    = $histrow['bill_type'];
242
243
    return $graph_data;
244
}
245
246
function getBillingBitsGraphData($bill_id, $from, $to, $reducefactor)
247
{
248
    $i          = '0';
249
    $iter       = 0;
250
    $first      = null;
251
    $last       = null;
252
    $iter_in    = 0;
253
    $iter_out   = 0;
254
    $iter_period = 0;
255
    $max_in     = 0;
256
    $max_out    = 0;
257
    $tot_in     = 0;
258
    $tot_out    = 0;
259
    $tot_period = 0;
260
    $in_delta   = null;
261
    $out_delta  = null;
262
    $period     = null;
263
    $in_data    = array();
264
    $out_data   = array();
265
    $tot_data   = array();
266
    $ticks      = array();
267
268
    if (!isset($reducefactor) || !is_numeric($reducefactor) || $reducefactor < 1) {
269
        // Auto calculate reduce factor
270
        $expectedpoints = ceil(($to - $from) / 300);
271
        $desiredpoints = 400;
272
        $reducefactor = max(1, floor($expectedpoints / $desiredpoints));
273
    }
274
275
    $bill_data    = dbFetchRow('SELECT * from `bills` WHERE `bill_id`= ? LIMIT 1', array($bill_id));
276
277
    foreach (dbFetch('SELECT *, UNIX_TIMESTAMP(timestamp) AS formatted_date FROM bill_data WHERE bill_id = ? AND `timestamp` >= FROM_UNIXTIME( ? ) AND `timestamp` <= FROM_UNIXTIME( ? ) ORDER BY timestamp ASC', array($bill_id, $from, $to)) as $row) {
278
        $timestamp = $row['formatted_date'];
279
        if (!$first) {
280
            $first = $timestamp;
281
        }
282
283
        $period    = $row['period'];
284
        $in_delta  = $row['in_delta'] * 8;
285
        $out_delta = $row['out_delta'] * 8;
286
        $last      = $timestamp;
287
288
        $iter_in     += $in_delta;
289
        $iter_out    += $out_delta;
290
        $iter_period += $period;
291
292
        if ($period > 0) {
293
            $max_in    = max($max_in, $in_delta / $period);
294
            $max_out   = max($max_out, $out_delta / $period);
295
            $tot_in    += $in_delta;
296
            $tot_out   += $out_delta;
297
            $tot_period+= $period;
298
299
            if (++$iter >= $reducefactor) {
300
                $out_data[$i] = round(($iter_out / $iter_period), 2);
301
                $in_data[$i]  = round(($iter_in / $iter_period), 2);
302
                $tot_data[$i] = ($out_data[$i] + $in_data[$i]);
303
                $ticks[$i]    = $timestamp;
304
                $i++;
305
                $iter         = 0;
306
                unset($iter_out, $iter_in, $iter_period);
307
            }
308
        }
309
    }//end foreach
310
311
    if (!empty($iter_in)) {  // Write last element
0 ignored issues
show
introduced by
The condition empty($iter_in) is always true.
Loading history...
312
        $out_data[$i] = round(($iter_out / $iter_period), 2);
313
        $in_data[$i]  = round(($iter_in / $iter_period), 2);
314
        $tot_data[$i] = ($out_data[$i] + $in_data[$i]);
315
        $ticks[$i]    = $timestamp;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $timestamp seems to be defined by a foreach iteration on line 277. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
316
        $i++;
317
    }
318
    $result = array(
319
        'from'          => $from,
320
        'to'            => $to,
321
        'first'         => $first,
322
        'last'          => $last,
323
324
        'in_data'       => $in_data,
325
        'out_data'      => $out_data,
326
        'tot_data'      => $tot_data,
327
        'ticks'         => $ticks,
328
329
        'rate_95th'     => $bill_data['rate_95th'],
330
        'rate_average'  => $bill_data['rate_average'],
331
        'bill_type'     => $bill_data['bill_type']
332
    );
333
334
    if ($period) {
335
        $result['max_in']   = $max_in;
336
        $result['max_out']  = $max_out;
337
        $result['ave_in']   = $tot_in / $tot_period;
338
        $result['ave_out']  = $tot_out / $tot_period;
339
        $result['last_in']  = $in_delta / $period;
340
        $result['last_out'] = $out_delta / $period;
341
    }
342
    return $result;
343
}//end getBillingBitsGraphData
344
345
function getHistoricTransferGraphData($bill_id)
346
{
347
    $i = '0';
348
349
    $in_data      = array();
350
    $out_data     = array();
351
    $tot_data     = array();
352
    $allow_data   = array();
353
    $ave_data     = array();
354
    $overuse_data = array();
355
    $ticklabels   = array();
356
    $allowed_val  = null;
357
358
    foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY `bill_datefrom` DESC LIMIT 12', array($bill_id)) as $data) {
359
        $datefrom          = strftime('%Y-%m-%d', strtotime($data['bill_datefrom']));
360
        $dateto        = strftime('%Y-%m-%d', strtotime($data['bill_dateto']));
361
        $datelabel     = $datefrom." - ".$dateto;
362
363
        array_push($ticklabels, $datelabel);
364
        array_push($in_data, $data['traf_in']);
365
        array_push($out_data, $data['traf_out']);
366
        array_push($tot_data, $data['traf_total']);
367
        array_push($allow_data, $allowed_val = ($data['bill_type'] == 'Quota' ? $data['bill_allowed'] : 0));
368
        array_push($overuse_data, $data['bill_type'] == 'Quota' ? $data['bill_overuse'] : 0);
369
        $i++;
370
    }//end foreach
371
372
    if ($i < 12) {
373
        $y = (12 - $i);
374
        for ($x = 0; $x < $y; $x++) {
375
            $allowed = (($x == '0') ? $allowed_val : '0' );
376
            array_push($in_data, '0');
377
            array_push($out_data, '0');
378
            array_push($tot_data, '0');
379
            array_push($allow_data, $allowed);
380
            array_push($overuse_data, '0');
381
            array_push($ticklabels, '');
382
        }
383
    }
384
385
    $graph_name = 'Historical bandwidth over the last 12 billing periods';
386
387
    return array(
388
        'graph_name'        => $graph_name,
389
        'in_data'           => $in_data,
390
        'out_data'          => $out_data,
391
        'tot_data'          => $tot_data,
392
        'allow_data'        => $allow_data,
393
        'ave_data'          => $ave_data,
394
        'overuse_data'      => $overuse_data,
395
        'ticklabels'        => $ticklabels
396
    );
397
}
398
399
function getBillingBandwidthGraphData($bill_id, $bill_hist_id, $from, $to, $imgtype)
400
{
401
    if (is_numeric($bill_hist_id)) {
402
        $histrow = dbFetchRow('SELECT UNIX_TIMESTAMP(bill_datefrom) as `from`, UNIX_TIMESTAMP(bill_dateto) AS `to`, rate_95th, rate_average FROM bill_history WHERE bill_id = ? AND bill_hist_id = ?', array($bill_id, $bill_hist_id));
403
404
        if (is_null($histrow)) {
405
            return null;
406
        }
407
        $from  = $histrow['from'];
408
        $to    = $histrow['to'];
409
    } else {
410
        if (!is_numeric($from) || !is_numeric($to)) {
411
            die('Must supply from and to if bill_hist_id is not supplied');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
412
        }
413
    }
414
415
    $in_data      = array();
416
    $out_data     = array();
417
    $tot_data     = array();
418
    $allow_data   = array();
419
    $ave_data     = array();
420
    $overuse_data = array();
421
    $ticklabels   = array();
422
423
    $data    = array();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
424
    $average = 0;
425
    if ($imgtype == 'day') {
426
        foreach (dbFetch('SELECT DISTINCT UNIX_TIMESTAMP(timestamp) as timestamp, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY DATE(timestamp) ORDER BY timestamp ASC', array($bill_id, $from, $to)) as $data) {
427
            array_push($ticklabels, strftime("%Y-%m-%d", $data['timestamp']));
428
            array_push($in_data, isset($data['traf_in']) ? $data['traf_in'] : 0);
429
            array_push($out_data, isset($data['traf_out']) ? $data['traf_out'] : 0);
430
            array_push($tot_data, isset($data['traf_total']) ? $data['traf_total'] : 0);
431
            $average += $data['traf_total'];
432
        }
433
434
        $ave_count = count($tot_data);
435
436
        // Add empty items for the days not yet passed
437
        $days = (strftime('%e', date($to - $from)) - $ave_count - 1);
0 ignored issues
show
Bug introduced by
date($to - $from) of type string is incompatible with the type integer expected by parameter $timestamp of strftime(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

437
        $days = (strftime('%e', /** @scrutinizer ignore-type */ date($to - $from)) - $ave_count - 1);
Loading history...
438
        for ($x = 0; $x < $days; $x++) {
439
            array_push($ticklabels, '');
440
            array_push($in_data, 0);
441
            array_push($out_data, 0);
442
            array_push($tot_data, 0);
443
        }
444
    } elseif ($imgtype == 'hour') {
445
        foreach (dbFetch('SELECT DISTINCT HOUR(timestamp) as hour, SUM(delta) as traf_total, SUM(in_delta) as traf_in, SUM(out_delta) as traf_out FROM bill_data WHERE `bill_id` = ? AND `timestamp` >= FROM_UNIXTIME(?) AND `timestamp` <= FROM_UNIXTIME(?) GROUP BY HOUR(timestamp) ORDER BY HOUR(timestamp) ASC', array($bill_id, $from, $to)) as $data) {
446
            array_push($ticklabels, sprintf('%02d', $data['hour']) . ":00");
447
            array_push($in_data, isset($data['traf_in']) ? $data['traf_in'] : 0);
448
            array_push($out_data, isset($data['traf_out']) ? $data['traf_out'] : 0);
449
            array_push($tot_data, isset($data['traf_total']) ? $data['traf_total'] : 0);
450
            $average += $data['traf_total'];
451
        }
452
453
        $ave_count = count($tot_data);
454
    } else {
455
        die("Unknown graph type $imgtype");
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
456
    }//end if
457
458
    $average = ($average / $ave_count);
459
    $tot_data_size = count($tot_data);
460
    for ($x = 0; $x <= $tot_data_size; $x++) {
461
        array_push($ave_data, $average);
462
    }
463
464
    $graph_name = date('M j g:ia', $from).' - '.date('M j g:ia', $to);
465
466
    return array(
467
        'graph_name'        => $graph_name,
468
        'in_data'           => $in_data,
469
        'out_data'          => $out_data,
470
        'tot_data'          => $tot_data,
471
        'allow_data'        => $allow_data,
472
        'ave_data'          => $ave_data,
473
        'overuse_data'      => $overuse_data,
474
        'ticklabels'        => $ticklabels
475
    );
476
}
477
//end getBillingBandwidthGraphData
478