src.api.services.validation_service module

src.api.services.validation_service.extract_parameters(request, parameter_list)[source]

Extracts specified parameters from a request object.

This function iterates over a list of parameters and attempts to retrieve each one from the request’s arguments. If a parameter is not found, it is set to None.

Parameters:
  • request (flask.Request) – The request object to extract parameters from.

  • parameter_list (list of str) – A list of parameter names to extract.

Returns:

A dictionary where the keys are the parameter names and the values are the extracted parameters or None if the parameter was not found.

Return type:

dict

src.api.services.validation_service.jd_arange(a, b, dr, decimals=11)[source]

Generates a sequence of Julian Dates between two given dates with a specified increment.

This function compensates for round-off errors by rounding the computed dates to a specified number of decimal places.

Parameters:
  • a (float) – The first Julian Date in the sequence.

  • b (float) – The last Julian Date in the sequence. If the exact date b cannot be included due to the increment dr, the sequence will stop at the nearest date before b.

  • dr (float) – The increment between consecutive Julian Dates in the sequence.

  • decimals (int, optional) – The number of decimal places to which each computed Julian Date should be rounded. Default is 11.

Returns:

results – An array of astropy Time objects representing the Julian Dates between a and b with an increment of dr.

Return type:

astropy.time.core.Time

Raises:

500: – If an invalid Julian Date is encountered.

src.api.services.validation_service.parse_tle(tle)[source]

Parses a URL-encoded Two-Line Element (TLE) string and returns a TLE object.

Args:
tle (str): A URL-encoded TLE string. The string can be either two or three lines,

separated by newline characters (`

` or n).

Returns:

TLE: An object containing the parsed TLE data.

Raises:

ValidationError: If the TLE format is incorrect

Example:
>>> tle_string = "1 25544U 98067A   21275.48835648  .00002182  00000-0  51170-4 0  9993\n2 25544  51.6442  21.4776 0003887  45.3456  314.6567 15.48815347275345"
>>> tle = parse_tle(tle_string)
>>> print(tle)
TLE(tle_line1='1 25544U 98067A   21275.48835648  .00002182  00000-0  51170-4 0  9993', tle_line2='2 25544  51.6442  21.4776 0003887  45.3456  314.6567 15.48815347275345', date_collected=None, name=None, catalog='2554', data_source='user')
src.api.services.validation_service.validate_parameters(request: Any, parameter_list: list[str], required_parameters: list[str]) dict[str, Any][source]

Validates and sanitizes parameters for satellite tracking.

This function checks if all required parameters are present in the input parameters. It then converts latitude, longitude, and elevation to floats and constructs an EarthLocation object. It also sanitizes the min_altitude, max_altitude, and data_source parameters.

Parameters:
  • parameters (list of str) – The input parameters to validate and sanitize.

  • required_parameters (list of str) – A list of parameter names that are required.

Returns:

The validated and sanitized parameters.

Return type:

dict

Raises:

HTTPException – If a required parameter is missing, if the location parameters are invalid, if the altitude parameters are invalid, or if the data source is invalid.