Billing: add peak in and out (#13006)

* feat(api): added max in/out per bill_history period

* chore(Docs): updated docs to include in/out max values

* chore(formatting): style-ci

* chore(db): update db-schema

* fix(db): reverted wrong changes in schema

* fix: wrong table name in migration

* feat(billing-history-frontend): added max in/out values to frontend bill-history

* chore: renamed to peak instead of min/max
This commit is contained in:
Bennet Gallein 2021-07-26 17:37:52 +02:00 committed by GitHub
parent e873768845
commit 574eb1f0f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 6 deletions

View File

@ -42,7 +42,7 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
// Send the current dir_95th to the getRates function so it knows to aggregate or return the max in/out value and highest direction
$dir_95th = $bill['dir_95th'];
if ($period > 0 && $dateto > $date_updated) {
if ($period['period'] > 0 && $dateto > $date_updated) {
$rate_data = getRates($bill['bill_id'], $datefrom, $dateto, $dir_95th);
$rate_95th = $rate_data['rate_95th'];
$dir_95th = $rate_data['dir_95th'];
@ -102,6 +102,8 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
'traf_total' => $rate_data['total_data'],
'traf_in' => $rate_data['total_data_in'],
'traf_out' => $rate_data['total_data_out'],
'bill_peak_out' => $period['peak_out'],
'bill_peak_in' => $period['peak_in'],
'bill_used' => $used,
'bill_overuse' => $overuse,
'bill_percent' => $percent,
@ -133,10 +135,10 @@ foreach (dbFetchRows('SELECT * FROM `bills` ORDER BY `bill_id`') as $bill) {
];
dbInsert($update, 'bill_history');
echo ' Generated history! ';
}//end if
} //end if
echo "\n\n";
}//end if
} //end if
$i++;
}//end while
} //end while
}//end foreach

View File

@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterBillHistoryMaxMin extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('bill_history', function (Blueprint $table) {
$table->bigInteger('bill_peak_out')->nullable()->after('traf_total');
$table->bigInteger('bill_peak_in')->nullable()->after('bill_peak_out');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('bill_history', function (Blueprint $table) {
$table->dropColumn(['bill_peak_in', 'bill_peak_out']);
});
}
}

View File

@ -260,6 +260,8 @@ Output:
"traf_in": "3235123452544",
"traf_out": "33608406566",
"traf_total": "3268731859110",
"bill_peak_out": "2782349290",
"bill_peak_in": "10161119",
"pdf": null
}
],

View File

@ -216,7 +216,7 @@ function getSum($bill_id, $datefrom, $dateto)
function getPeriod($bill_id, $datefrom, $dateto)
{
$ptot = dbFetchCell('SELECT SUM(period) FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?', [$bill_id, $datefrom, $dateto]);
$ptot = dbFetchRow('SELECT SUM(period) as `period`, MAX(in_delta) as `peak_in`, MAX(out_delta) as `peak_out` FROM bill_data WHERE bill_id = ? AND timestamp > ? AND timestamp <= ?', [$bill_id, $datefrom, $dateto]);
return $ptot;
}//end getPeriod()

View File

@ -55,6 +55,8 @@ echo '<table class="table table-striped">
<th>Allowed</th>
<th>Inbound</th>
<th>Outbound</th>
<th>Peak Out</th>
<th>Peak In</th>
<th>Total</th>
<th>95th %ile</th>
<th style="text-align: center;">Overusage</th>
@ -91,6 +93,8 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY
$out = Number::formatBase($history['traf_out'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
$overuse = (($history['bill_overuse'] <= 0) ? '-' : '<span style="color: #' . $background['left'] . '; font-weight: bold;">' . Number::formatBase($history['bill_overuse'], \LibreNMS\Config::get('billing.base')) . '</span>');
}
$peakOut = Number::formatBase($history['bill_peak_out'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
$peakIn = Number::formatBase($history['bill_peak_in'], \LibreNMS\Config::get('billing.base'), 2, 3, '');
$total_data = (($type == 'Quota') ? '<b>' . $total_data . '</b>' : $total_data);
$rate_95th = (($type == 'CDR') ? '<b>' . $rate_95th . '</b>' : $rate_95th);
@ -105,6 +109,8 @@ foreach (dbFetchRows('SELECT * FROM `bill_history` WHERE `bill_id` = ? ORDER BY
<td>$allowed</td>
<td>$in</td>
<td>$out</td>
<td>$peakOut</td>
<td>$peakIn</td>
<td>$total_data</td>
<td>$rate_95th</td>
<td style=\"text-align: center;\">$overuse</td>

View File

@ -313,6 +313,8 @@ bill_history:
- { Field: traf_in, Type: bigint, 'Null': false, Extra: '' }
- { Field: traf_out, Type: bigint, 'Null': false, Extra: '' }
- { Field: traf_total, Type: bigint, 'Null': false, Extra: '' }
- { Field: bill_peak_out, Type: bigint, 'Null': true, Extra: '' }
- { Field: bill_peak_in, Type: bigint, 'Null': true, Extra: '' }
- { Field: pdf, Type: longblob, 'Null': true, Extra: '' }
Indexes:
PRIMARY: { Name: PRIMARY, Columns: [bill_hist_id], Unique: true, Type: BTREE }
@ -2131,4 +2133,4 @@ wireless_sensors:
wireless_sensors_sensor_class_index: { Name: wireless_sensors_sensor_class_index, Columns: [sensor_class], Unique: false, Type: BTREE }
wireless_sensors_sensor_type_index: { Name: wireless_sensors_sensor_type_index, Columns: [sensor_type], Unique: false, Type: BTREE }
Constraints:
wireless_sensors_device_id_foreign: { name: wireless_sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' }
wireless_sensors_device_id_foreign: { name: wireless_sensors_device_id_foreign, foreign_key: device_id, table: devices, key: device_id, extra: 'ON DELETE CASCADE' }