improve awk_quote and move it into a datautils library
This commit is contained in:
Родитель
5fc31eb662
Коммит
e24c50ec63
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
// This script contains utility functions used by multiple other scripts.
|
||||
|
||||
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\/\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
// Function to calculate square of value - mean
|
||||
function arr_mean($array) { return array_sum($array) / count($array); }
|
||||
|
||||
// Function to calculate square of value - mean
|
||||
function dist_square($x, $mean) { return pow($x - $mean, 2); }
|
||||
|
||||
// Function to calculate standard deviation (uses sist_square)
|
||||
function arr_stddev($array, $mean = null) {
|
||||
// square root of sum of squares devided by N-1
|
||||
if (is_null($mean)) { $mean = arr_mean($array); }
|
||||
return sqrt(array_sum(array_map("dist_square", $array,
|
||||
array_fill(0, count($array), $mean))) /
|
||||
(count($array) - 1));
|
||||
}
|
||||
|
||||
?>
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -397,10 +399,4 @@ for ($daysback = $backlog_days + 1; $daysback > 0; $daysback--) {
|
|||
|
||||
// *** helper functions ***
|
||||
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -582,12 +584,6 @@ function count_compare($a, $b) {
|
|||
return ($a['.count'] > $b['.count']) ? -1 : 1;
|
||||
}
|
||||
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
// Function to bump the counter of an element or initialize it
|
||||
function addCount(&$basevar, $sub, $addnum = 1) {
|
||||
if (array_key_exists($sub, $basevar)) {
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -429,7 +431,6 @@ function getPeriodBugURL($scheme, $date_start, $date_end = null) {
|
|||
}
|
||||
|
||||
function getBugCount($listurl) {
|
||||
if ($GLOBALS['fake_counts']) { return mt_rand(0, 30); } // for testing where https crashes
|
||||
if (preg_match('/buglist\.cgi(\?.*)$/', $listurl, $regs)) {
|
||||
$list_json = file_get_contents('https://api-dev.bugzilla.mozilla.org/latest/count'.$regs[1]);
|
||||
if ($list_json) {
|
||||
|
@ -440,5 +441,4 @@ function getBugCount($listurl) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -441,9 +443,5 @@ foreach ($reports as $rep) {
|
|||
}
|
||||
|
||||
// *** helper functions ***
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -559,31 +561,10 @@ function get_explosiveness($dataset, $aduset, $exp_vars) {
|
|||
return $exp_out;
|
||||
}
|
||||
|
||||
// Function to calculate square of value - mean
|
||||
function arr_mean($array) { return array_sum($array) / count($array); }
|
||||
|
||||
// Function to calculate square of value - mean
|
||||
function dist_square($x, $mean) { return pow($x - $mean, 2); }
|
||||
|
||||
// Function to calculate standard deviation (uses sist_square)
|
||||
function arr_stddev($array, $mean = null) {
|
||||
// square root of sum of squares devided by N-1
|
||||
if (is_null($mean)) { $mean = arr_mean($array); }
|
||||
return sqrt(array_sum(array_map("dist_square", $array,
|
||||
array_fill(0, count($array), $mean))) /
|
||||
(count($array) - 1));
|
||||
}
|
||||
|
||||
// Comparison function using ex_max member (reverse sort!)
|
||||
function expmax_compare($a, $b) {
|
||||
if ($a['exp_max'] == $b['exp_max']) { return 0; }
|
||||
return ($a['exp_max'] > $b['exp_max']) ? -1 : 1;
|
||||
}
|
||||
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -348,10 +350,4 @@ function count_compare($a, $b) {
|
|||
return ($a['count'] > $b['count']) ? -1 : 1;
|
||||
}
|
||||
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -387,10 +389,4 @@ foreach ($reports as $rep) {
|
|||
|
||||
// *** helper functions ***
|
||||
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -397,7 +399,6 @@ function getPeriodBugURL($scheme, $date_start, $date_end = null) {
|
|||
}
|
||||
|
||||
function getBugCount($listurl) {
|
||||
if ($GLOBALS['fake_counts']) { return mt_rand(0, 30); } // for testing where https crashes
|
||||
if (preg_match('/buglist\.cgi(\?.*)$/', $listurl, $regs)) {
|
||||
$list_json = file_get_contents('https://api-dev.bugzilla.mozilla.org/latest/count'.$regs[1]);
|
||||
if ($list_json) {
|
||||
|
|
|
@ -15,6 +15,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
|
|
@ -25,6 +25,8 @@ if (php_sapi_name() != 'cli') {
|
|||
exit;
|
||||
}
|
||||
|
||||
include_once('datautils.php');
|
||||
|
||||
// *** script settings ***
|
||||
|
||||
// turn on error reporting in the script output
|
||||
|
@ -405,9 +407,5 @@ foreach ($reports as $rep) {
|
|||
}
|
||||
|
||||
// *** helper functions ***
|
||||
// Function to safely escape variables handed to awk
|
||||
function awk_quote($string) {
|
||||
return strtr(preg_replace("/([\]\[^$.*?+{}\\\\()|])/", '\\\\$1', $string),
|
||||
array('`'=>'\140',"'"=>'\047'));
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Загрузка…
Ссылка в новой задаче