.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 415 of file weather.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 434 of file weather.py.

434 def __init__(self, azimuth: float | int | Point):
435 if isinstance(azimuth, str):
436 if azimuth not in self.POINTS:
437 raise ValueError(f"Invalid compass point: {azimuth}")
438 azimuth = self.POINTS.index(azimuth) * self.RANGE
439 self.azimuth = azimuth % self.TURN
440

References POINTS, and RANGE.

Member Function Documentation

◆ __str__()

searx.weather.Compass.__str__ ( self)

Definition at line 441 of file weather.py.

441 def __str__(self):
442 return self.l10n()
443

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 461 of file weather.py.

467 ) -> str:
468 if isinstance(locale, GeoLocation):
469 locale = locale.locale()
470 elif locale is None:
471 locale = babel.Locale.parse(_get_sxng_locale_tag(), sep='-')
472
473 if unit == "Point":
474 val_str = self.value(unit)
475 return template.format(value=val_str, unit="")
476
477 val_str = babel.numbers.format_decimal(self.value(unit), locale=locale, format=num_pattern)
478 return template.format(value=val_str, unit=unit)
479
480

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 452 of file weather.py.

452 def point(cls, azimuth: float | int) -> Point:
453 """Returns the compass point to an azimuth value."""
454 azimuth = azimuth % cls.TURN
455 # The angle sector of a compass point starts 1/2 sector range before
456 # and after compass point (example: "N" goes from -11.25° to +11.25°)
457 azimuth = azimuth - cls.RANGE / 2
458 idx = int(azimuth // cls.RANGE)
459 return cls.POINTS[idx]
460

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 444 of file weather.py.

444 def value(self, unit: Units):
445 if unit == "Point":
446 return self.point(self.azimuth)
447 if unit == "°":
448 return self.azimuth
449 raise ValueError(f"unknown unit: {unit}")
450

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 439 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 420 of file weather.py.

◆ POINTS

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

Definition at line 428 of file weather.py.

Referenced by __init__(), and point().

◆ RANGE

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

Definition at line 431 of file weather.py.

Referenced by __init__(), and point().

◆ TURN

float searx.weather.Compass.TURN = 360.0
static

Definition at line 425 of file weather.py.

Referenced by point().

◆ Units

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

Definition at line 418 of file weather.py.


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