.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 28 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 42 of file statistics.py.

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

◆ info()

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

Reimplemented from searx.answerers._core.Answerer.

Definition at line 33 of file statistics.py.

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

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


The documentation for this class was generated from the following file:
  • /home/andrew/Documents/code/public/searxng/searx/answerers/statistics.py