Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 167 HTML file Support #171

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 38 additions & 52 deletions backend/PythonClient/server/simulation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,79 +154,65 @@ def process_gcs_directory(prefix, result, fuzzy_path_value):
Processes blobs in a GCS directory and populates the result dictionary.
"""
blobs = bucket.list_blobs(prefix=prefix)

def extract_fuzzy_value(fuzzy_path):
return fuzzy_path.split("_")[-1] if fuzzy_path else ""

def classify_and_append(blob_name, file_data):
for monitor_type in result.keys():
if monitor_type in blob_name:
result[monitor_type].append(file_data)
break

for blob in blobs:
file_name = os.path.basename(blob.name)
if blob.name.endswith('.txt'):
# Download the text content
file_contents = blob.download_as_text()

info_content = get_info_contents(file_contents, "INFO", {})
pass_content = get_info_contents(file_contents, "PASS", {})
fail_content = get_info_contents(file_contents, "FAIL", {})
fuzzy_value = extract_fuzzy_value(fuzzy_path_value)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change this to case switch/ pattern matching to make more readable

if blob.name.endswith('.html'):
# Generate a public URL for the HTML file
html_url = blob.public_url

file_data = {
"name": file_name,
"type": "text/plain",
"type": "text/html",
"fuzzyPath": fuzzy_path_value,
"fuzzyValue": fuzzy_path_value.split("_")[-1] if fuzzy_path_value else "",
"content": file_contents,
"infoContent": info_content,
"passContent": pass_content,
"failContent": fail_content
"fuzzyValue": fuzzy_value,
"content": html_url,
"infoContent": get_info_contents(html_url, "INFO", {}),
"passContent": get_info_contents(html_url, "PASS", {}),
"failContent": get_info_contents(html_url, "FAIL", {})
}
classify_and_append(blob.name, file_data)

# Determine the monitor type and append the file data
if "UnorderedWaypointMonitor" in blob.name:
result["UnorderedWaypointMonitor"].append(file_data)
elif "CircularDeviationMonitor" in blob.name:
result["CircularDeviationMonitor"].append(file_data)
elif "CollisionMonitor" in blob.name:
result["CollisionMonitor"].append(file_data)
elif "LandspaceMonitor" in blob.name:
result["LandspaceMonitor"].append(file_data)
elif "OrderedWaypointMonitor" in blob.name:
result["OrderedWaypointMonitor"].append(file_data)
elif "PointDeviationMonitor" in blob.name:
result["PointDeviationMonitor"].append(file_data)
elif "MinSepDistMonitor" in blob.name:
result["MinSepDistMonitor"].append(file_data)
elif "NoFlyZoneMonitor" in blob.name:
result["NoFlyZoneMonitor"].append(file_data)
elif blob.name.endswith('.txt'):
file_contents = blob.download_as_text()

file_data = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeat of above, some way to reduce code repition

"name": file_name,
"type": "text/plain",
"fuzzyPath": fuzzy_path_value,
"fuzzyValue": fuzzy_value,
"content": file_contents,
"infoContent": get_info_contents(html_url, "INFO", {}),
"passContent": get_info_contents(html_url, "PASS", {}),
"failContent": get_info_contents(html_url, "FAIL", {})
}
classify_and_append(blob.name, file_data)

elif blob.name.endswith('.png'):
# Download and encode the image in base64
image_content = blob.download_as_bytes()
encoded_string = base64.b64encode(image_content).decode('utf-8')

# Assume corresponding HTML exists
html_path = blob.name.replace("_plot.png", "_interactive.html")

file_data = {
"name": file_name,
"type": "image/png",
"fuzzyPath": fuzzy_path_value,
"fuzzyValue": fuzzy_path_value.split("_")[-1] if fuzzy_path_value else "",
"fuzzyValue": fuzzy_value,
"imgContent": encoded_string,
"path": html_path
}

# Determine the monitor type and append the file data
if "UnorderedWaypointMonitor" in blob.name:
result["UnorderedWaypointMonitor"].append(file_data)
elif "CircularDeviationMonitor" in blob.name:
result["CircularDeviationMonitor"].append(file_data)
elif "CollisionMonitor" in blob.name:
result["CollisionMonitor"].append(file_data)
elif "LandspaceMonitor" in blob.name:
result["LandspaceMonitor"].append(file_data)
elif "OrderedWaypointMonitor" in blob.name:
result["OrderedWaypointMonitor"].append(file_data)
elif "PointDeviationMonitor" in blob.name:
result["PointDeviationMonitor"].append(file_data)
elif "MinSepDistMonitor" in blob.name:
result["MinSepDistMonitor"].append(file_data)
elif "NoFlyZoneMonitor" in blob.name:
result["NoFlyZoneMonitor"].append(file_data)
classify_and_append(blob.name, file_data)

def get_info_contents(file_contents, keyword, drone_map):
"""
Expand Down
Loading