Skip to content

Commit

Permalink
Please amend this with other fixes, temporary commit to show examples
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlou05 committed Dec 20, 2024
1 parent 04e47c8 commit 010ffc3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions modules/communications_log_to_kml.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def convert_communication_log_to_kml(
log_file: str, document_name_prefix: str, save_directory: str
log_file_path: pathlib.Path, document_name_prefix: str, save_directory: pathlib.Path
) -> "tuple[bool, pathlib.Path | None]":
"""
Given a communications log file with a specific format, return a corresponding KML file.
Expand All @@ -31,8 +31,10 @@ def convert_communication_log_to_kml(
"""
locations = []

with open(log_file, "r", encoding="utf-8") as f:
for line in f:
with open(log_file_path, "r", encoding="utf-8") as log_file:
for line in log_file:
# Use the timestamp (hh:mm:ss) as the name of the marker in the KML file
time = line[:8]
# find all the latitudes and longitudes within the line
latitudes = re.findall(r"latitude: (-?\d+\.\d+)", line)
longitudes = re.findall(r"longitude: (-?\d+\.\d+)", line)
Expand All @@ -45,20 +47,21 @@ def convert_communication_log_to_kml(
print(f"# of altitudes: {len(latitudes)}, # of longitudes: {len(longitudes)}")
return False, None

# Convert list of strings to list of floats
latitudes = list(map(float, latitudes))
longitudes = list(map(float, longitudes))

# Cannot use for each loop here
# Cannot use for each loop here, iterating through both lists at the same time
# pylint: disable-next=consider-using-enumerate
for i in range(len(latitudes)):
success, location = location_global.LocationGlobal.create(
latitudes[i], longitudes[i]
result, location = location_global.NamedLocationGlobal.create(
time, latitudes[i], longitudes[i]
)
if not success:
if not result:
return False, None
locations.append(location)

return kml_conversion.locations_to_kml(locations, document_name_prefix, save_directory)
return kml_conversion.named_locations_to_kml(locations, document_name_prefix, save_directory)


# similar main to other logs to kml scripts
Expand Down

0 comments on commit 010ffc3

Please sign in to comment.