Skip to content

Commit

Permalink
Upload HTML file to S3. Fix code. Add a few comments. Ignore system M…
Browse files Browse the repository at this point in the history
…acOS files
  • Loading branch information
emi420 committed Nov 18, 2024
1 parent 655f318 commit 7acb431
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ Pipfile.lock
#backend
backend/data
backend/.env

.DS_Store
19 changes: 16 additions & 3 deletions API/api_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,10 @@ def process_raw_data(self, params, user=None):
file_parts,
)

# Post-proccessing: Generate GeoJSON/HTML stats and transliterations
polygon_stats = None
geojson_stats_html = None

download_html_url = None
if "include_stats" or "include_translit" in params.dict():
post_processor = PostProcessor({
"include_stats": params.include_stats,
Expand All @@ -245,9 +246,9 @@ def process_raw_data(self, params, user=None):
tpl = "stats"
if 'waterway' in post_processor.geoJSONStats.config.keys:
tpl = "stats_waterway"
if 'highway' in post_processor.geoJSONStats.config.keys:
elif 'highway' in post_processor.geoJSONStats.config.keys:
tpl = "stats_highway"
if 'building' in post_processor.geoJSONStats.config.keys:
elif 'building' in post_processor.geoJSONStats.config.keys:
tpl = "stats_building"
project_root = pathlib.Path(__file__).resolve().parent
tpl_path = os.path.join(project_root, "../src/post_processing/{tpl}_tpl.html".format(tpl=tpl))
Expand Down Expand Up @@ -322,6 +323,15 @@ def process_raw_data(self, params, user=None):
upload_name,
file_suffix="zip" if bind_zip else params.output_type.lower(),
)

# If there's an HTML file, upload it too
if geojson_stats_html:
download_html_url = file_transfer_obj.upload(
upload_html_path,
upload_name,
file_suffix="html",
)

else:
# give the static file download url back to user served from fastapi static export path
download_url = str(upload_file_path)
Expand All @@ -347,6 +357,9 @@ def process_raw_data(self, params, user=None):
}
if polygon_stats:
final_response["stats"] = polygon_stats
if download_html_url:
final_response["download_html_url"] = download_html_url

return final_response

except Exception as ex:
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ psutil==5.9.8
tqdm==4.66.2

# stats for geojson data
geojson-stats==0.2.2
geojson-stats==0.2.3

# transliterations
transliterate==1.10.2
Expand Down

0 comments on commit 7acb431

Please sign in to comment.