.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.answerers.statistics.SXNGAnswerer Class Reference
+ Inheritance diagram for searx.answerers.statistics.SXNGAnswerer:
+ Collaboration diagram for searx.answerers.statistics.SXNGAnswerer:

Public Member Functions

 info (self)
 
list[BaseAnsweranswer (self, str query)
 

Additional Inherited Members

- Static Public Attributes inherited from searx.answerers._core.Answerer
list keywords [str]
 

Detailed Description

Statistics functions

Definition at line 27 of file statistics.py.

Member Function Documentation

◆ answer()

list[BaseAnswer] searx.answerers.statistics.SXNGAnswerer.answer ( self,
str query )
Function that returns a list of answers to the question/query.

Reimplemented from searx.answerers._core.Answerer.

Definition at line 41 of file statistics.py.

41 def answer(self, query: str) -> list[BaseAnswer]:
42
43 results = []
44 parts = query.split()
45 if len(parts) < 2:
46 return results
47
48 ui_locale = babel.Locale.parse(sxng_request.preferences.get_value('locale'), sep='-')
49
50 try:
51 args = [babel.numbers.parse_decimal(num, ui_locale, numbering_system="latn") for num in parts[1:]]
52 except: # pylint: disable=bare-except
53 # seems one of the args is not a float type, can't be converted to float
54 return results
55
56 for k, func in kw2func:
57 if k == parts[0]:
58 res = func(args)
59 res = babel.numbers.format_decimal(res, locale=ui_locale)
60 f_str = ', '.join(babel.numbers.format_decimal(arg, locale=ui_locale) for arg in args)
61 results.append(Answer(answer=f"[{ui_locale}] {k}({f_str}) = {res} "))
62 break
63
64 return results

◆ info()

searx.answerers.statistics.SXNGAnswerer.info ( self)
Informations about the *answerer*, see :py:obj:`AnswererInfo`.

Reimplemented from searx.answerers._core.Answerer.

Definition at line 32 of file statistics.py.

32 def info(self):
33
34 return AnswererInfo(
35 name=gettext(self.__doc__),
36 description=gettext("Compute {func} of the arguments".format(func='/'.join(self.keywords))),
37 keywords=self.keywords,
38 examples=["avg 123 548 2.04 24.2"],
39 )
40

References searx.answerers._core.Answerer.keywords, and searx.answerers._core.AnswererInfo.keywords.


The documentation for this class was generated from the following file: