1
|
|
|
<?php |
2
|
|
|
namespace HuasoFoundries\Histogram\Printer; |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class to print text representations of a Math_Histogram object |
6
|
|
|
* |
7
|
|
|
* @author Jesus M. Castagnetto <[email protected]> |
8
|
|
|
* @version 0.9.1beta |
9
|
|
|
* @access public |
10
|
|
|
* @package Math_Histogram |
11
|
|
|
*/ |
12
|
|
|
class Text extends Common |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Returns a string representation of a Histogram plot |
17
|
|
|
* |
18
|
|
|
* @access public |
19
|
|
|
* @return string|PEAR_Error A string on succcess, a \PEAR_Error otherwise |
|
|
|
|
20
|
|
|
*/ |
21
|
|
|
public function generateOutput() |
22
|
|
|
{ |
23
|
|
|
if (is_null($this->_hist)) { |
24
|
|
|
throw new \PEAR_Exception('Math_Histogram object has not been set'); |
25
|
|
|
} |
26
|
|
|
if (!$this->_hist->isCalculated()) { |
27
|
|
|
if (isset($this->_options['histogramStatsMode'])) { |
28
|
|
|
$this->_hist->calculate($this->_options['histogramStatsMode']); |
29
|
|
|
} else { |
30
|
|
|
$this->_hist->calculate(); |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if (isset($this->_options['histogramBinMode'])) { |
35
|
|
|
$binmode = $this->_options['histogramBinMode']; |
36
|
|
|
} else { |
37
|
|
|
$binmode = \HuasoFoundries\Histogram\Histogram::HISTOGRAM_HI_BINS; |
38
|
|
|
} |
39
|
|
|
$bins = $this->_hist->getBins($binmode); |
40
|
|
|
$binopts = $this->_hist->getBinOptions(); |
41
|
|
|
$hdata = $this->_hist->getHistogramData(); |
42
|
|
|
$data = $this->_hist->getData(); |
43
|
|
|
$fmt = "%-4.3f (%-4d) |%s\n"; |
44
|
|
|
$maxfreq = max(array_values($bins)); |
45
|
|
|
$total = count($hdata); |
46
|
|
|
$out = ($this->_hist->_type == \HuasoFoundries\Histogram\Histogram::HISTOGRAM_CUMMULATIVE) ? "Cummulative Frequency" : "Histogram"; |
47
|
|
|
$out .= "\n\tNumber of bins: {$binopts['nbins']}\n"; |
48
|
|
|
$out .= "\tPlot range: [{$binopts['rangeLow']}, {$binopts['rangeHigh']}]\n"; |
49
|
|
|
$out .= "\tData range: [" . min($hdata) . ", " . max($hdata) . "]\n"; |
50
|
|
|
$out .= "\tOriginal data range: [" . min($data) . ", " . max($data) . "]\n"; |
51
|
|
|
$out .= "BIN (FREQUENCY) ASCII_BAR (%)\n"; |
52
|
|
|
foreach ($bins as $bin => $freq) { |
53
|
|
|
$out .= sprintf($fmt, $bin, $freq, $this->_bar($freq, $maxfreq, $total)); |
54
|
|
|
} |
55
|
|
|
if ($this->_options['outputStats']) { |
56
|
|
|
$out .= "\n --- Histogram Statistics ---\n"; |
57
|
|
|
$out .= $this->_printStats($this->_hist->getHistogramDataStats()); |
58
|
|
|
} |
59
|
|
|
return $out; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Prints out a graphic representation of a Histogram |
64
|
|
|
* |
65
|
|
|
* @access public |
66
|
|
|
* @return boolean|PEAR_Error TRUE on success, a \PEAR_Error otherwise |
67
|
|
|
*/ |
68
|
|
|
public function printOutput() |
69
|
|
|
{ |
70
|
|
|
$plot = $this->generateOutput($hist); |
|
|
|
|
71
|
|
|
if (\PEAR::isError($plot)) { |
72
|
|
|
return $plot; |
|
|
|
|
73
|
|
|
} else { |
74
|
|
|
if ($this->_options['useHTTPHeaders']) { |
75
|
|
|
header('Content-type: text/plain'); |
76
|
|
|
} |
77
|
|
|
echo $plot; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Static method to print out a graphic representation of a Histogram |
83
|
|
|
* |
84
|
|
|
* @static |
85
|
|
|
* @access public |
86
|
|
|
* @param object Math_Histogram $hist A Math_Histogram instance |
|
|
|
|
87
|
|
|
* @param array $options An array of options for the printer object |
88
|
|
|
* @return boolean|PEAR_Error TRUE on success, a \PEAR_Error otherwise |
89
|
|
|
*/ |
90
|
|
|
public function printHistogram(&$hist, $options = array()) |
91
|
|
|
{ |
92
|
|
|
$printer = new \HuasoFoundries\Histogram\Printer\Text(); |
93
|
|
|
return \HuasoFoundries\Histogram\Printer\Common::_doStaticPrint($printer, $hist, $options); |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Prints a simple ASCII bar |
98
|
|
|
* |
99
|
|
|
* @access private |
100
|
|
|
* @param int $freq the frequency |
101
|
|
|
* @param int $maxfreq the maximum frequency |
102
|
|
|
* @param int $total the total count |
103
|
|
|
* @return string |
104
|
|
|
*/ |
105
|
|
|
public function _bar($freq, $maxfreq, $total) |
106
|
|
|
{ |
107
|
|
|
$fact = floatval(($maxfreq > 40) ? 40 / $maxfreq : 1); |
108
|
|
|
$niter = round($freq * $fact); |
109
|
|
|
$out = ""; |
110
|
|
|
for ($i = 0; $i < $niter; $i++) { |
111
|
|
|
$out .= "*"; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $out . sprintf(" (%.1f%%)", $freq / $total * 100); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Prints the histogram data statistics |
119
|
|
|
* |
120
|
|
|
* @access private |
121
|
|
|
* @param array $stats Associative array of statistics |
122
|
|
|
* @param optional string $prefix Prefix to use when printing out statistics |
123
|
|
|
* @return string |
124
|
|
|
*/ |
125
|
|
|
public function _printStats($stats, $prefix = '') |
126
|
|
|
{ |
127
|
|
|
$out = ''; |
128
|
|
|
foreach ($stats as $name => $value) { |
129
|
|
|
if (is_array($value)) { |
130
|
|
|
$out .= $prefix . $name . ":\n"; |
131
|
|
|
$out .= $this->_printStats($value, $prefix . "\t"); |
132
|
|
|
} else { |
133
|
|
|
$out .= "{$prefix}{$name}: $value\n"; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
return $out; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// vim: ts=4:sw=4:et: |
141
|
|
|
// vim6: fdl=1: |
142
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths