Skip to content

Commit

Permalink
Logging update
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot authored Dec 13, 2024
1 parent 4c6a661 commit 5065e85
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 35 deletions.
3 changes: 1 addition & 2 deletions maps4fs/generator/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def generate_obj_files(self) -> None:
self.logger.warning("DEM file not found, generation will be stopped: %s", dem_path)
return

self.logger.info("DEM file for tile %s found: %s", tile.code, dem_path)
self.logger.debug("DEM file for tile %s found: %s", tile.code, dem_path)

base_directory = os.path.dirname(dem_path)
save_path = os.path.join(base_directory, f"{tile.code}.obj")
Expand All @@ -164,7 +164,6 @@ def plane_from_np(self, tile_code: str, dem_data: np.ndarray, save_path: str) ->
if tile_code == PATH_FULL_NAME:
resize_factor = FULL_RESIZE_FACTOR
simplify_factor = FULL_SIMPLIFY_FACTOR
self.logger.info("Generating a full map obj file")
else:
resize_factor = RESIZE_FACTOR
simplify_factor = SIMPLIFY_FACTOR
Expand Down
2 changes: 1 addition & 1 deletion maps4fs/generator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _set_map_size(self) -> None:
self.logger.warning("Map XML file not found: %s.", self._map_xml_path)
return
tree = ET.parse(self._map_xml_path)
self.logger.debug("Map XML file loaded from: %s.", self._map_xml_path)
self.logger.info("Map XML file loaded from: %s.", self._map_xml_path)
root = tree.getroot()
for map_elem in root.iter("map"):
map_elem.set("width", str(self.map_width))
Expand Down
20 changes: 12 additions & 8 deletions maps4fs/generator/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def process(self) -> None:
north, south, east, west = self.bbox

dem_output_resolution = self.get_output_resolution()
self.logger.debug("DEM output resolution: %s.", dem_output_resolution)
self.logger.info("DEM output resolution: %s.", dem_output_resolution)

tile_path = self._srtm_tile()
if not tile_path:
Expand Down Expand Up @@ -223,7 +223,7 @@ def process(self) -> None:
)

cv2.imwrite(self._dem_path, resampled_data)
self.logger.debug("DEM data was saved to %s.", self._dem_path)
self.logger.info("DEM data was saved to %s.", self._dem_path)

if self.game.additional_dem_name is not None:
self.make_copy(self.game.additional_dem_name)
Expand All @@ -239,7 +239,7 @@ def make_copy(self, dem_name: str) -> None:
additional_dem_path = os.path.join(dem_directory, dem_name)

shutil.copyfile(self._dem_path, additional_dem_path)
self.logger.debug("Additional DEM data was copied to %s.", additional_dem_path)
self.logger.info("Additional DEM data was copied to %s.", additional_dem_path)

def _tile_info(self, lat: float, lon: float) -> tuple[str, str]:
"""Returns latitude band and tile name for SRTM tile from coordinates.
Expand All @@ -260,7 +260,7 @@ def _tile_info(self, lat: float, lon: float) -> tuple[str, str]:
else:
tile_name = f"{latitude_band}E{abs(tile_longitude):03d}"

self.logger.debug(
self.logger.info(
"Detected tile name: %s for coordinates: lat %s, lon %s.", tile_name, lat, lon
)
return latitude_band, tile_name
Expand Down Expand Up @@ -421,14 +421,18 @@ def _normalize_dem(self, data: np.ndarray) -> np.ndarray:

scaling_factor = self._get_scaling_factor(max_dev)
adjusted_max_height = int(65535 * scaling_factor)
self.logger.debug(
f"Maximum deviation: {max_dev}. Scaling factor: {scaling_factor}. "
f"Adjusted max height: {adjusted_max_height}."
self.logger.info(
"Maximum deviation: %s. Scaling factor: %s. Adjusted max height: %s.",
max_dev,
scaling_factor,
adjusted_max_height,
)
normalized_data = (
(data - data.min()) / (data.max() - data.min()) * adjusted_max_height
).astype("uint16")
self.logger.debug(
f"DEM data was normalized to {normalized_data.min()} - {normalized_data.max()}."
"DEM data was normalized to %s - %s.",
normalized_data.min(),
normalized_data.max(),
)
return normalized_data
2 changes: 1 addition & 1 deletion maps4fs/generator/grle.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def process(self) -> None:
info_layer_data = np.zeros((height, width), dtype=data_type)
print(info_layer_data.shape)
cv2.imwrite(file_path, info_layer_data) # pylint: disable=no-member
self.logger.info("InfoLayer PNG file %s created.", file_path)
self.logger.debug("InfoLayer PNG file %s created.", file_path)
else:
self.logger.warning("Invalid InfoLayer schema: %s.", info_layer)

Expand Down
8 changes: 3 additions & 5 deletions maps4fs/generator/i3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _update_i3d_file(self) -> None:
self.logger.debug("TerrainTransformGroup element updated in I3D file.")

tree.write(self._map_i3d_path) # type: ignore
self.logger.debug("Map I3D file saved to: %s.", self._map_i3d_path)
self.logger.info("Map I3D file saved to: %s.", self._map_i3d_path)

def previews(self) -> list[str]:
"""Returns a list of paths to the preview images (empty list).
Expand Down Expand Up @@ -120,13 +120,11 @@ def _add_fields(self) -> None:
self.logger.warning("Fields data not found in textures info layer.")
return

self.logger.debug("Found %s fields in textures info layer.", len(fields))
self.logger.info("Found %s fields in textures info layer.", len(fields))

root = tree.getroot()
gameplay_node = root.find(".//TransformGroup[@name='gameplay']")
if gameplay_node is not None:
self.logger.debug("Found the gameplay node.")

fields_node = gameplay_node.find(".//TransformGroup[@name='fields']")
user_attributes_node = root.find(".//UserAttributes")

Expand Down Expand Up @@ -194,7 +192,7 @@ def _add_fields(self) -> None:
node_id += 1

tree.write(self._map_i3d_path) # type: ignore
self.logger.debug("Map I3D file saved to: %s.", self._map_i3d_path)
self.logger.info("Map I3D file saved to: %s.", self._map_i3d_path)

def get_name_indicator_node(self, node_id: int, field_id: int) -> tuple[ET.Element, int]:
"""Creates a name indicator node with given node ID and field ID.
Expand Down
6 changes: 3 additions & 3 deletions maps4fs/generator/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ def __init__( # pylint: disable=R0917
if not logger:
logger = Logger(to_stdout=True, to_file=False)
self.logger = logger
self.logger.debug("Game was set to %s", game.code)
self.logger.info("Game was set to %s", game.code)

self.kwargs = kwargs
self.logger.debug("Additional arguments: %s", kwargs)
self.logger.info("Additional arguments: %s", kwargs)

os.makedirs(self.map_directory, exist_ok=True)
self.logger.debug("Map directory created: %s", self.map_directory)

try:
shutil.unpack_archive(game.template_path, self.map_directory)
self.logger.info("Map template unpacked to %s", self.map_directory)
self.logger.debug("Map template unpacked to %s", self.map_directory)
except Exception as e:
raise RuntimeError(f"Can not unpack map template due to error: {e}") from e

Expand Down
8 changes: 4 additions & 4 deletions maps4fs/generator/texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _prepare_weights(self):

for layer in self.layers:
self._generate_weights(layer)
self.logger.debug("Prepared weights for %s layers.", len(self.layers))
self.logger.info("Prepared weights for %s layers.", len(self.layers))

def _generate_weights(self, layer: Layer) -> None:
"""Generates weight files for textures. Each file is a numpy array of zeros and
Expand Down Expand Up @@ -339,7 +339,7 @@ def draw(self) -> None:
cumulative_image = cv2.bitwise_or(cumulative_image, output_image)

cv2.imwrite(layer_path, output_image)
self.logger.debug("Texture %s saved.", layer_path)
self.logger.info("Texture %s saved.", layer_path)

# Save info layer data.
with open(self.info_layer_path, "w", encoding="utf-8") as f:
Expand All @@ -351,7 +351,7 @@ def draw(self) -> None:
if not self.light_version:
self.dissolve()
else:
self.logger.info("Skipping dissolve in light version of the map.")
self.logger.debug("Skipping dissolve in light version of the map.")

def dissolve(self) -> None:
"""Dissolves textures of the layers with tags into sublayers for them to look more
Expand Down Expand Up @@ -423,7 +423,7 @@ def draw_base_layer(self, cumulative_image: np.ndarray) -> None:
self.logger.debug("Drawing base layer %s.", layer_path)
img = cv2.bitwise_not(cumulative_image)
cv2.imwrite(layer_path, img)
self.logger.debug("Base texture %s saved.", layer_path)
self.logger.info("Base texture %s saved.", layer_path)

def get_relative_x(self, x: float) -> int:
"""Converts UTM X coordinate to relative X coordinate in map image.
Expand Down
4 changes: 2 additions & 2 deletions webui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def remove_with_delay_without_blocking(
"""

def remove_file() -> None:
logger.info("Removing file from %s in %s seconds.", file_path, delay)
logger.debug("Removing file from %s in %s seconds.", file_path, delay)
sleep(delay)
try:
os.remove(file_path)
logger.info("File %s removed.", file_path)
except FileNotFoundError:
logger.warning("File %s not found.", file_path)
logger.debug("File %s not found.", file_path)

logger.debug("Starting a new thread to remove the file %s.", file_path)
threading.Thread(target=remove_file).start()
18 changes: 9 additions & 9 deletions webui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class GeneratorUI:

def __init__(self):
self.download_path = None
self.logger = mfs.Logger(level="DEBUG", to_file=False)
self.logger = mfs.Logger(level="INFO", to_file=False)

self.community = config.is_on_community_server()
self.logger.info("The application launched on the community server: %s", self.community)
self.logger.debug("The application launched on the community server: %s", self.community)

self.left_column, self.right_column = st.columns(2, gap="large")

Expand Down Expand Up @@ -94,7 +94,7 @@ def map_preview(self) -> None:
except ValueError:
return

self.logger.info(
self.logger.debug(
"Generating map preview for lat=%s, lon=%s, map_size=%s", lat, lon, map_size
)

Expand All @@ -106,14 +106,14 @@ def map_preview(self) -> None:

def add_right_widgets(self) -> None:
"""Add widgets to the right column."""
self.logger.info("Adding widgets to the right column...")
self.logger.debug("Adding widgets to the right column...")
self.html_preview_container = st.empty()
self.map_selector_container = st.container()
self.preview_container = st.container()

def add_left_widgets(self) -> None:
"""Add widgets to the left column."""
self.logger.info("Adding widgets to the left column...")
self.logger.debug("Adding widgets to the left column...")

st.title(Messages.TITLE)
st.write(Messages.MAIN_PAGE_DESCRIPTION)
Expand Down Expand Up @@ -158,7 +158,7 @@ def add_left_widgets(self) -> None:
)

if self.map_size_input == "Custom":
self.logger.info("Custom map size selected.")
self.logger.debug("Custom map size selected.")

st.info("ℹ️ Map size can be only a power of 2. For example: 2, 4, ... 2048, 4096, ...")
st.warning("⚠️ Large map sizes can crash on generation or import in the game.")
Expand Down Expand Up @@ -209,7 +209,7 @@ def add_left_widgets(self) -> None:
)

if self.advanced_settings:
self.logger.info("Advanced settings are enabled.")
self.logger.debug("Advanced settings are enabled.")

st.warning("⚠️ Changing these settings can lead to unexpected results.")
st.info(
Expand Down Expand Up @@ -267,7 +267,7 @@ def add_left_widgets(self) -> None:

# Download button.
if st.session_state.generated:
self.logger.info("Generated was set to True in the session state.")
self.logger.debug("Generated was set to True in the session state.")
with open(self.download_path, "rb") as f:
with self.buttons_container:
st.download_button(
Expand All @@ -282,7 +282,7 @@ def add_left_widgets(self) -> None:
config.remove_with_delay_without_blocking(self.download_path, self.logger)

st.session_state.generated = False
self.logger.info("Generated was set to False in the session state.")
self.logger.debug("Generated was set to False in the session state.")

def get_sesion_name(self, coordinates: tuple[float, float]) -> str:
"""Return a session name for the map, using the coordinates and the current timestamp.
Expand Down

0 comments on commit 5065e85

Please sign in to comment.