-
Notifications
You must be signed in to change notification settings - Fork 1
/
formulas.php
150 lines (123 loc) · 2.21 KB
/
formulas.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<?php
class formulas
{
public $inputs;
public $outputs;
function sum($cell, $array)
{
return array_sum($array);
}
function divide($cell, $array)
{
return array_sum($array);
}
function average($cell, $array)
{
$total = 0;
$count = count($array);
foreach ($array as $value) {
$total = $total + $value;
}
$average = ($total / $count);
return $average;
}
function avg($cell, $array)
{
return $this->average($cell, $array);
}
function count($cell, $array)
{
$count = 0;
foreach ($array as $value) {
if ($value != null) $count++;
}
return $count;
}
function counta($cell, $array)
{
$count = 0;
foreach ($array as $value) {
if (!empty($value)) $count++;
}
return $count;
}
function max($cell, $array)
{
return max($array);
}
function min($cell, $array)
{
return min($array);
}
function mean($cell, $array)
{
sort($array);
$count = count($array); //total numbers in array
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
if($count % 2) { // odd number, middle is the median
$median = $array[$middleval];
} else { // even number, calculate avg of 2 medians
$low = $array[$middleval];
$high = $array[$middleval+1];
$median = (($low+$high)/2);
}
return $median;
}
function abs($cell, $array)
{
return abs($array);
}
function ceiling($cell, $array)
{
return ceil($array);
}
function floor($cell, $array)
{
return floor($array);
}
function int($cell, $array)
{
return floor($array);
}
function round($cell, $array)
{
return round($array);
}
function rand($cell, $array)
{
return rand();
}
function rnd($cell, $array)
{
return $this->rand($cell, $array);
}
function true($cell, $array)
{
return 'TRUE';
}
function false($cell, $array)
{
return 'FALSE';
}
function pi($cell, $array)
{
return pi();
}
function power($cell, $array)
{
return pow($array[0], $array[1]);
}
function sqrt($cell, $array)
{
return sqrt($array);
}
function input($cell, $array)
{
return (!empty($this->inputs[$array[0]]) ? $this->inputs[$array[0]] : 0);
}
function output($cell, $array)
{
$this->outputs[$array[0]] = (!empty($array[1]) ? $array[1] : 0);
return '';
}
}