ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Mean.php
Go to the documentation of this file.
1<?php
2
4
10
11class Mean
12{
27 public static function geometric(...$args)
28 {
29 $aArgs = Functions::flattenArray($args);
30
31 $aMean = MathTrig\Operations::product($aArgs);
32 if (is_numeric($aMean) && ($aMean > 0)) {
33 $aCount = Counts::COUNT($aArgs);
34 if (Minimum::min($aArgs) > 0) {
35 return $aMean ** (1 / $aCount);
36 }
37 }
38
39 return Functions::NAN();
40 }
41
55 public static function harmonic(...$args)
56 {
57 // Loop through arguments
58 $aArgs = Functions::flattenArray($args);
59 if (Minimum::min($aArgs) < 0) {
60 return Functions::NAN();
61 }
62
63 $returnValue = 0;
64 $aCount = 0;
65 foreach ($aArgs as $arg) {
66 // Is it a numeric value?
67 if ((is_numeric($arg)) && (!is_string($arg))) {
68 if ($arg <= 0) {
69 return Functions::NAN();
70 }
71 $returnValue += (1 / $arg);
72 ++$aCount;
73 }
74 }
75
76 // Return
77 if ($aCount > 0) {
78 return 1 / ($returnValue / $aCount);
79 }
80
81 return Functions::NA();
82 }
83
98 public static function trim(...$args)
99 {
100 $aArgs = Functions::flattenArray($args);
101
102 // Calculate
103 $percent = array_pop($aArgs);
104
105 if ((is_numeric($percent)) && (!is_string($percent))) {
106 if (($percent < 0) || ($percent > 1)) {
107 return Functions::NAN();
108 }
109
110 $mArgs = [];
111 foreach ($aArgs as $arg) {
112 // Is it a numeric value?
113 if ((is_numeric($arg)) && (!is_string($arg))) {
114 $mArgs[] = $arg;
115 }
116 }
117
118 $discard = floor(Counts::COUNT($mArgs) * $percent / 2);
119 sort($mArgs);
120
121 for ($i = 0; $i < $discard; ++$i) {
122 array_pop($mArgs);
123 array_shift($mArgs);
124 }
125
126 return Averages::average($mArgs);
127 }
128
129 return Functions::VALUE();
130 }
131}
An exception for terminatinating execution or to throw for unit testing.
static flattenArray($array)
Convert a multi-dimensional array to a simple 1-dimensional array.
Definition: Functions.php:583
$i
Definition: disco.tpl.php:19