.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
answerer.py
Go to the documentation of this file.
1
# SPDX-License-Identifier: AGPL-3.0-or-later
2
# pylint: disable=missing-module-docstring
3
4
from
functools
import
reduce
5
from
operator
import
mul
6
7
from
flask_babel
import
gettext
8
9
10
keywords = (
'min'
,
'max'
,
'avg'
,
'sum'
,
'prod'
)
11
12
13
# required answerer function
14
# can return a list of results (any result type) for a given query
15
def
answer
(query):
16
parts = query.query.split()
17
18
if
len(parts) < 2:
19
return
[]
20
21
try
:
22
args = list(map(float, parts[1:]))
23
except
:
# pylint: disable=bare-except
24
return
[]
25
26
func = parts[0]
27
_answer =
None
28
29
if
func ==
'min'
:
30
_answer = min(args)
31
elif
func ==
'max'
:
32
_answer = max(args)
33
elif
func ==
'avg'
:
34
_answer = sum(args) / len(args)
35
elif
func ==
'sum'
:
36
_answer = sum(args)
37
elif
func ==
'prod'
:
38
_answer = reduce(mul, args, 1)
39
40
if
_answer
is
None
:
41
return
[]
42
43
return
[{
'answer'
: str(_answer)}]
44
45
46
# required answerer function
47
# returns information about the answerer
48
def
self_info
():
49
return
{
50
'name'
: gettext(
'Statistics functions'
),
51
'description'
: gettext(
'Compute {functions} of the arguments'
).
format
(functions=
'/'
.join(keywords)),
52
'examples'
: [
'avg 123 548 2.04 24.2'
],
53
}
searx.answerers.statistics.answerer.self_info
self_info()
Definition
answerer.py:48
searx.answerers.statistics.answerer.answer
answer(query)
Definition
answerer.py:15
searx.format
format
Definition
__init__.py:94
searxng
searx
answerers
statistics
answerer.py
Generated on Sat Nov 16 2024 00:10:57 for .oO SearXNG Developer Documentation Oo. by
1.12.0