forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadvisor.lib.php
69 lines (63 loc) · 1.58 KB
/
advisor.lib.php
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
<?php
/* vim: set expandtab sw=4 ts=4 sts=4: */
/**
* Contains Advisor functions
*
* @package PhpMyAdmin
*/
/**
* Formats interval like 10 per hour
*
* @param integer $num number to format
* @param integer $precision required precision
*
* @return string formatted string
*/
function ADVISOR_bytime($num, $precision)
{
if ($num >= 1) { // per second
$per = __('per second');
} elseif ($num * 60 >= 1) { // per minute
$num = $num * 60;
$per = __('per minute');
} elseif ($num * 60 * 60 >= 1 ) { // per hour
$num = $num * 60 * 60;
$per = __('per hour');
} else {
$num = $num * 60 * 60 * 24;
$per = __('per day');
}
$num = round($num, $precision);
if ($num == 0) {
$num = '<' . pow(10, -$precision);
}
return "$num $per";
}
/**
* Wrapper for PMA\libraries\Util::timespanFormat
*
* This function is used when evaluating advisory_rules.txt
*
* @param int $seconds the timespan
*
* @return string the formatted value
*/
function ADVISOR_timespanFormat($seconds)
{
return PMA\libraries\Util::timespanFormat($seconds);
}
/**
* Wrapper around PMA\libraries\Util::formatByteDown
*
* This function is used when evaluating advisory_rules.txt
*
* @param double $value the value to format
* @param int $limes the sensitiveness
* @param int $comma the number of decimals to retain
*
* @return string the formatted value with unit
*/
function ADVISOR_formatByteDown($value, $limes = 6, $comma = 0)
{
return implode(' ', PMA\libraries\Util::formatByteDown($value, $limes, $comma));
}