Skip to content

Commit

Permalink
Disable DTM Providers on public app.
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot committed Jan 27, 2025
1 parent fd83ebf commit bd182ce
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 48 deletions.
1 change: 0 additions & 1 deletion dev/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ owslib
tqdm
types-tqdm
scipy
schedule
streamlit-folium
12 changes: 11 additions & 1 deletion maps4fs/generator/dtm/dtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,16 @@ def get_provider_by_code(cls, code: str) -> Type[DTMProvider] | None:
return None

@classmethod
def get_valid_provider_descriptions(cls, lat_lon: tuple[float, float]) -> dict[str, str]:
def get_valid_provider_descriptions(
cls, lat_lon: tuple[float, float], default_code: str = "srtm30"
) -> dict[str, str]:
"""Get descriptions of all providers, where keys are provider codes and
values are provider descriptions.
Arguments:
lat_lon (tuple): Latitude and longitude of the center point.
default_code (str): Default provider code.
Returns:
dict: Provider descriptions.
"""
Expand All @@ -262,6 +268,10 @@ def get_valid_provider_descriptions(cls, lat_lon: tuple[float, float]) -> dict[s
code = provider.code()
if code is not None:
providers[code] = provider.description()

# Sort the dictionary, to make sure that the default provider is the first one.
providers = dict(sorted(providers.items(), key=lambda item: item[0] != default_code))

return providers

@classmethod
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ pygmdl
owslib
tqdm
scipy
schedule
streamlit-folium
3 changes: 2 additions & 1 deletion webui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def is_public() -> bool:
Returns:
bool: True if the script is running on a public server, False otherwise.
"""
return os.environ.get(PUBLIC_HOSTNAME_KEY) == PUBLIC_HOSTNAME_VALUE
# return os.environ.get(PUBLIC_HOSTNAME_KEY) == PUBLIC_HOSTNAME_VALUE
return True


def remove_with_delay_without_blocking(
Expand Down
2 changes: 1 addition & 1 deletion webui/generator/advanced_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ def is_disabled_on_public(self, raw_field_name: str) -> bool:
if not self.public:
return False

disabled_fields = ["resize_factor", "dissolve", "zoom_level", "download_images"]
disabled_fields = ["resize_factor", "dissolve", "zoom_level"] # , "download_images"]
return raw_field_name in disabled_fields
2 changes: 1 addition & 1 deletion webui/generator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def limit_on_public(self, settings_json: dict) -> dict:
limited_settings["BackgroundSettings"]["resize_factor"] = 8
limited_settings["TextureSettings"]["dissolve"] = False
limited_settings["SatelliteSettings"]["zoom_level"] = 14
limited_settings["SatelliteSettings"]["download_images"] = False
# limited_settings["SatelliteSettings"]["download_images"] = False
return limited_settings

def get_json_settings(self) -> dict[str, mfs.settings.SettingsModel]:
Expand Down
2 changes: 1 addition & 1 deletion webui/generator/main_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, public: bool, **kwargs):
format_func=lambda code: providers[code],
key="dtm_provider",
label_visibility="collapsed",
# disabled=self.public, # * For temprorary test of the public app.
disabled=self.public,
on_change=self.provider_info,
)
self.provider_settings = None
Expand Down
42 changes: 1 addition & 41 deletions webui/queuing.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
import json
import os
import shutil
import threading
from time import sleep
from typing import Generator

import schedule
from config import (
ARCHIVES_DIRECTORY,
MAPS_DIRECTORY,
QUEUE_FILE,
QUEUE_INTERVAL,
QUEUE_TIMEOUT,
TEMP_DIRECTORY,
create_dirs,
is_public,
)
from config import QUEUE_FILE, QUEUE_INTERVAL, QUEUE_TIMEOUT

from maps4fs import Logger

Expand Down Expand Up @@ -149,32 +138,3 @@ def start_termination(session: str) -> None:
logger.debug("Session %s will be terminated after %s seconds.", session, QUEUE_TIMEOUT)
sleep(QUEUE_TIMEOUT)
remove_from_queue(session)


def auto_clean() -> None:
"""Automatically clean the directories."""
if not is_public():
return
if get_queue_length() > 0:
return

to_clean = [ARCHIVES_DIRECTORY, MAPS_DIRECTORY, TEMP_DIRECTORY]
for directory in to_clean:
shutil.rmtree(directory, ignore_errors=True)

create_dirs()


def run_scheduler():
while True:
schedule.run_pending()
sleep(1)


if is_public():
schedule.every(240).minutes.do(auto_clean)
scheduler_thread = threading.Thread(target=run_scheduler)
scheduler_thread.daemon = True
scheduler_thread.start()

get_queue(force=True)

0 comments on commit bd182ce

Please sign in to comment.