.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.weather.Compass Class Reference

Public Member Functions

 __init__ (self, float|int|Point azimuth)
 __str__ (self)
 value (self, Units unit)
Point point (cls, float|int azimuth)
str l10n (self, Units unit="Point", babel.Locale|GeoLocation|None locale=None, str template="{value}{unit}", str num_pattern="#,##0")

Public Attributes

float azimuth = azimuth % self.TURN

Static Public Attributes

 Units = typing.Literal["°", "Point"]
 Point
float TURN = 360.0
 POINTS = list(typing.get_args(Point))
float RANGE = TURN / len(POINTS)

Detailed Description

Class for converting compass points and azimuth values (360°)

Definition at line 451 of file weather.py.

Constructor & Destructor Documentation

◆ __init__()

searx.weather.Compass.__init__ ( self,
float | int | Point azimuth )

Definition at line 470 of file weather.py.

470 def __init__(self, azimuth: float | int | Point):
471 if isinstance(azimuth, str):
472 if azimuth not in self.POINTS:
473 raise ValueError(f"Invalid compass point: {azimuth}")
474 azimuth = self.POINTS.index(azimuth) * self.RANGE
475 self.azimuth = azimuth % self.TURN
476

References POINTS, and RANGE.

Member Function Documentation

◆ __str__()

searx.weather.Compass.__str__ ( self)

Definition at line 477 of file weather.py.

477 def __str__(self):
478 return self.l10n()
479

References l10n(), searx.weather.DateTime.l10n(), searx.weather.Pressure.l10n(), searx.weather.RelativeHumidity.l10n(), searx.weather.Temperature.l10n(), and searx.weather.WindSpeed.l10n().

Here is the call graph for this function:

◆ l10n()

str searx.weather.Compass.l10n ( self,
Units unit = "Point",
babel.Locale | GeoLocation | None locale = None,
str template = "{value}{unit}",
str num_pattern = "#,##0" )

Definition at line 497 of file weather.py.

503 ) -> str:
504 if isinstance(locale, GeoLocation):
505 locale = locale.locale()
506 elif locale is None:
507 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
508
509 if unit == "Point":
510 val_str = self.value(unit)
511 return template.format(value=val_str, unit="")
512
513 val_str = babel.numbers.format_decimal(self.value(unit), locale=locale, format=num_pattern)
514 return template.format(value=val_str, unit=unit)
515
516

References searx.weather._get_sxng_locale_tag(), searx.preferences.BooleanSetting.value, searx.preferences.EnumStringSetting.value, searx.preferences.MapSetting.value, searx.preferences.MultipleChoiceSetting.value, searx.preferences.SearchLanguageSetting.value, searx.preferences.Setting.value, value(), searx.weather.Pressure.value(), searx.weather.RelativeHumidity.value(), searx.weather.Temperature.value(), and searx.weather.WindSpeed.value().

Referenced by __str__().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ point()

Point searx.weather.Compass.point ( cls,
float | int azimuth )
Returns the compass point to an azimuth value.

Definition at line 488 of file weather.py.

488 def point(cls, azimuth: float | int) -> Point:
489 """Returns the compass point to an azimuth value."""
490 azimuth = azimuth % cls.TURN
491 # The angle sector of a compass point starts 1/2 sector range before
492 # and after compass point (example: "N" goes from -11.25° to +11.25°)
493 azimuth = azimuth - cls.RANGE / 2
494 idx = int(azimuth // cls.RANGE)
495 return cls.POINTS[idx]
496

References POINTS, RANGE, and TURN.

Referenced by value().

Here is the caller graph for this function:

◆ value()

searx.weather.Compass.value ( self,
Units unit )

Definition at line 480 of file weather.py.

480 def value(self, unit: Units):
481 if unit == "Point":
482 return self.point(self.azimuth)
483 if unit == "°":
484 return self.azimuth
485 raise ValueError(f"unknown unit: {unit}")
486

References azimuth, and point().

Referenced by l10n().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ azimuth

searx.weather.Compass.azimuth = azimuth % self.TURN

Definition at line 475 of file weather.py.

Referenced by value().

◆ Point

searx.weather.Compass.Point
static
Initial value:
= typing.Literal[
"N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"
]

Definition at line 456 of file weather.py.

◆ POINTS

searx.weather.Compass.POINTS = list(typing.get_args(Point))
static

Definition at line 464 of file weather.py.

Referenced by __init__(), and point().

◆ RANGE

float searx.weather.Compass.RANGE = TURN / len(POINTS)
static

Definition at line 467 of file weather.py.

Referenced by __init__(), and point().

◆ TURN

float searx.weather.Compass.TURN = 360.0
static

Definition at line 461 of file weather.py.

Referenced by point().

◆ Units

searx.weather.Compass.Units = typing.Literal["°", "Point"]
static

Definition at line 454 of file weather.py.


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