.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.answerers.statistics.answerer Namespace Reference

Functions

 answer (query)
 
 self_info ()
 

Variables

tuple keywords = ('min', 'max', 'avg', 'sum', 'prod')
 

Function Documentation

◆ answer()

searx.answerers.statistics.answerer.answer ( query)

Definition at line 15 of file answerer.py.

15def 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

◆ self_info()

searx.answerers.statistics.answerer.self_info ( )

Definition at line 48 of file answerer.py.

48def 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 }

References searx.format.

Variable Documentation

◆ keywords

tuple searx.answerers.statistics.answerer.keywords = ('min', 'max', 'avg', 'sum', 'prod')

Definition at line 10 of file answerer.py.