Passed
Push — next ( 0f1d72...90a142 )
by Bas
10:40
created

HasNumericFunctions::decayExp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\AQL;
6
7
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
8
use LaravelFreelancerNL\FluentAQL\Expressions\FunctionExpression;
9
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
10
11
/**
12
 * Trait hasNumericFunctions.
13
 *
14
 * Numeric AQL functions.
15
 *
16
 * @see https://www.arangodb.com/docs/stable/aql/functions-miscellaneous.html
17
 */
18
trait HasNumericFunctions
19
{
20
    /**
21
     * Return the average (arithmetic mean) of the values in array.
22
     *
23
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#average
24
     * @param array<mixed>|string|QueryBuilder|Expression $value
25
     */
26 3
    public function average(array|string|QueryBuilder|Expression $value): FunctionExpression
27
    {
28 3
        return new FunctionExpression('AVERAGE', [$value]);
29
    }
30
31
    /**
32
     * @param array<mixed>|string|QueryBuilder|Expression $value
33
     */
34 1
    public function avg(array|string|QueryBuilder|Expression $value): FunctionExpression
35
    {
36 1
        return $this->average($value);
37
    }
38
39
    /**
40
     * Return the integer closest but not less than value.
41
     *
42
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#ceil
43
     */
44 1
    public function ceil(
45
        int|float|QueryBuilder|Expression $value
46
    ): FunctionExpression {
47 1
        return new FunctionExpression('CEIL', [$value]);
48
    }
49
50
    /**
51
     * Return the cosine similarity between x and y.
52
     *
53
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#cosine_similarity
54
     *
55
     * @param array<array<int|float>|int|float>|QueryBuilder|Expression $x
56
     * @param array<array<int|float>|int|float>|QueryBuilder|Expression $y
57
     */
58 1
    public function cosineSimilarity(
59
        array|QueryBuilder|Expression $x,
60
        array|QueryBuilder|Expression $y
61
    ): FunctionExpression {
62 1
        return new FunctionExpression('COSINE_SIMILARITY', [$x, $y]);
63
    }
64
65
    /**
66
     * Calculate the score for one or multiple values with a Gaussian function that decays
67
     * depending on the distance of a numeric value from a user-given origin.
68
     *
69
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#decay_gauss
70
     *
71
     * @param array<int|float>|int|float $value
72
     */
73 2
    public function decayGauss(
74
        array|int|float|QueryBuilder|Expression $value,
75
        int|float|QueryBuilder|Expression $origin,
76
        int|float|QueryBuilder|Expression $scale,
77
        int|float|QueryBuilder|Expression $offset,
78
        int|float|QueryBuilder|Expression $decay,
79
    ): FunctionExpression {
80 2
        return new FunctionExpression('DECAY_GAUSS', [$value, $origin, $scale, $offset, $decay]);
81
    }
82
83
    /**
84
     * Calculate the score for one or multiple values with an exponential function that decays depending
85
     * on the distance of a numeric value from a user-given origin.
86
     *
87
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#decay_exp
88
     */
89 1
    public function decayExp(
90
        int|float|QueryBuilder|Expression $value,
91
        int|float|QueryBuilder|Expression $origin,
92
        int|float|QueryBuilder|Expression $scale,
93
        int|float|QueryBuilder|Expression $offset,
94
        int|float|QueryBuilder|Expression $decay,
95
    ): FunctionExpression {
96 1
        return new FunctionExpression('DECAY_EXP', [$value, $origin, $scale, $offset, $decay]);
97
    }
98
99
    /**
100
     * Calculate the score for one or multiple values with a linear function that decays depending
101
     * on the distance of a numeric value from a user-given origin.
102
     *
103
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#decay_linear
104
     */
105 1
    public function decayLinear(
106
        int|float|QueryBuilder|Expression $value,
107
        int|float|QueryBuilder|Expression $origin,
108
        int|float|QueryBuilder|Expression $scale,
109
        int|float|QueryBuilder|Expression $offset,
110
        int|float|QueryBuilder|Expression $decay,
111
    ): FunctionExpression {
112 1
        return new FunctionExpression('DECAY_LINEAR', [$value, $origin, $scale, $offset, $decay]);
113
    }
114
115
116
    /**
117
     * Return the integer closest but not greater than value.
118
     *
119
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#floor
120
     */
121 1
    public function floor(
122
        int|float|QueryBuilder|Expression $value
123
    ): FunctionExpression {
124 1
        return new FunctionExpression('FLOOR', [$value]);
125
    }
126
127
    /**
128
     * Return the Manhattan distance between x and y.
129
     *
130
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#l1_distance
131
     *
132
     * @param array<array<int|float>|int|float>|QueryBuilder|Expression $x
133
     * @param array<array<int|float>|int|float>|QueryBuilder|Expression $y
134
     */
135 1
    public function l1Distance(
136
        array|QueryBuilder|Expression $x,
137
        array|QueryBuilder|Expression $y
138
    ): FunctionExpression {
139 1
        return new FunctionExpression('L1_DISTANCE', [$x, $y]);
140
    }
141
142
    /**
143
     * Return the Euclidean distance between x and y.
144
     *
145
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#l2_distance
146
     *
147
     * @param array<array<int|float>|int|float>|QueryBuilder|Expression $x
148
     * @param array<array<int|float>|int|float>|QueryBuilder|Expression $y
149
     */
150 1
    public function l2Distance(
151
        array|QueryBuilder|Expression $x,
152
        array|QueryBuilder|Expression $y
153
    ): FunctionExpression {
154 1
        return new FunctionExpression('L2_DISTANCE', [$x, $y]);
155
    }
156
157
    /**
158
     * Return the largest element of an array.
159
     *
160
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#max
161
     *
162
     * @param mixed $value
163
     *
164
     * @return FunctionExpression
165
     */
166 1
    public function max($value)
167
    {
168 1
        return new FunctionExpression('MAX', [$value]);
169
    }
170
171
    /**
172
     * Return the smallest element of an array.
173
     *
174
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#min
175
     *
176
     * @param mixed $value
177
     *
178
     * @return FunctionExpression
179
     */
180 1
    public function min($value)
181
    {
182 1
        return new FunctionExpression('MIN', [$value]);
183
    }
184
185
    /**
186
     * Return the product of the values in array
187
     *
188
     * https://www.arangodb.com/docs/stable/aql/functions-numeric.html#product
189
     *
190
     * @param array<mixed>|object $array
191
     */
192 1
    public function product(
193
        array|object $array
194
    ): FunctionExpression {
195 1
        return new FunctionExpression('PRODUCT', [$array]);
196
    }
197
198
    /**
199
     * Return a pseudo-random number between 0 and 1.
200
     *
201
     * https://www.arangodb.com/docs/stable/aql/functions-numeric.html#rand.
202
     *
203
     * @return FunctionExpression
204
     */
205 1
    public function rand()
206
    {
207 1
        return new FunctionExpression('RAND');
208
    }
209
210
    /**
211
     * Return an array of numbers in the specified range, optionally with increments other than 1.
212
     *
213
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#range
214
     */
215 1
    public function range(
216
        int|float|object $start,
217
        int|float|object $stop,
218
        int|float|object $step
219
    ): FunctionExpression {
220 1
        return new FunctionExpression('RANGE', [$start, $stop, $step]);
221
    }
222
223
    /**
224
     * Return the integer closest to value.
225
     *
226
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#round
227
     */
228 1
    public function round(int|float|QueryBuilder|Expression $value): FunctionExpression
229
    {
230 1
        return new FunctionExpression('ROUND', [$value]);
231
    }
232
233
    /**
234
     * Return the sum of the values in an array.
235
     *
236
     * @link https://www.arangodb.com/docs/stable/aql/functions-numeric.html#sum
237
     *
238
     * @param mixed $value
239
     *
240
     * @return FunctionExpression
241
     */
242 1
    public function sum($value)
243
    {
244 1
        return new FunctionExpression('SUM', [$value]);
245
    }
246
}
247