controllers package
Submodules
controllers.download_controller module
controllers.error_controller module
- add_constraints(df)[source]
Apply constraints and validity checks to a dataFrame of points.
This function applies several constraints and checks to a points dataFrame to ensure that the data is valid and within acceptable limits. The constraints include checking the number of points, the validity of hose length values, and the maximum distance between consecutive points.
- Parameters:
df (pandas.DataFrame) – A DataFrame containing point data with columns ‘latitude’, ‘longitude’, ‘hose_length’, and optionally other columns.
- Returns:
If the data passes all constraints and checks.
- Return type:
None
- Raises:
ValueError – If any of the constraints or checks fail, a ValueError is raised with a corresponding error message.
Note
The function checks that the DataFrame is not empty.
It limits the number of hydrants to 10 or fewer.
It validates the hose length values to be within the range [120, 5000].
It checks that each point is not more than 25 kilometers from the previously chosen one.
- check_distance(df)[source]
Check if consecutive points in a DataFrame are within a specified distance threshold.
This function calculates the distances between consecutive points in a dataFrame based on their latitude and longitude coordinates using the Haversine formula. It then checks if all calculated distances are within a specified threshold (in kilometers).
- Parameters:
df (pandas.DataFrame) – A DataFrame containing columns ‘latitude’ and ‘longitude’ with geographic coordinate values.
- Returns:
- True if all consecutive points are within the distance threshold,
False otherwise.
- Return type:
bool
Note
This function assumes that the DataFrame has been preprocessed with a shift operation to create ‘pre_latitude’ and ‘pre_longitude’ columns, as well as a ‘distance’ column containing the distances between consecutive points.
- haversine(lat1, lon1, lat2, lon2)[source]
Calculate the great-circle distance between two points on the Earth’s surface using the Haversine formula.
The Haversine formula calculates the shortest distance between two points on the surface of a sphere, given their latitude and longitude in degrees.
- Parameters:
lat1 (float) – Latitude of the first point in degrees.
lon1 (float) – Longitude of the first point in degrees.
lat2 (float) – Latitude of the second point in degrees.
lon2 (float) – Longitude of the second point in degrees.
- Returns:
The distance between the two points in kilometers.
- Return type:
float
controllers.results_controller module
controllers.results_controller_helper module
- input_string_to_df(input: str) Tuple[bool, DataFrame][source]
Parse a JSON input string into a pandas DataFrame.
This function takes a JSON input string, parses it, and constructs a pandas DataFrame. It also extracts a boolean flag to indicate whether elevations should be displayed.
- Parameters:
input (str) – A JSON input string.
- Returns:
- A tuple containing two elements:
bool: A flag indicating whether to display elevations.
pd.DataFrame: A pandas DataFrame containing parsed data.
- Return type:
Tuple[bool, pd.DataFrame]
Example
>>> { >>> "elevation": true, >>> "points": { >>> "1": { >>> "latitude": "48.140709", >>> "longitude": "11.510707", >>> "length": "111", >>> "mode": "Walking", >>> "point_type": "fire" >>> }, >>> ... >>> } >>> }
- pipeline_input_to_map_output(input: str)[source]
Process a pipeline input string to generate an interactive Folium map.
This function takes an input string, processes it to create an interactive Folium map, and returns the map as a Folium object.
- Parameters:
input (str) – A pipeline input string.
- Returns:
An interactive Folium map.
- Return type:
folium.Map
- Example JSON input format:
>>> { >>> "elevation": true, >>> "points": { >>> "1": { >>> "latitude": "48.140709", >>> "longitude": "11.510707", >>> "length": "111", >>> "mode": "Walking", >>> "point_type": "fire" >>> }, >>> ... >>> } >>> }
controllers.saved_maps module
- map_html_data = {}
Dictionary to store map HTML data