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

Version 6.0.0 - Route Storing #457

Merged
merged 125 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
754487e
Remove obsolete code in AutomaticWalkTimeTableGenerator
maede97 Aug 4, 2024
963860f
remove obsolete docker-compose.yml version field
maede97 Aug 4, 2024
f30645a
remove heightprofile
maede97 Aug 4, 2024
a8b2fce
run linter
maede97 Aug 4, 2024
109c2fa
bump version, update docs, drop obsolete requirement
maede97 Aug 4, 2024
d5fef41
change version to minor update
maede97 Aug 4, 2024
ac35c6a
remove user chosen map/excel generation, always generate both
maede97 Aug 4, 2024
cf8ae25
Feature: QR-Code (#456)
maede97 Aug 4, 2024
f2aaa73
run linter
maede97 Aug 4, 2024
95caf48
Merge branch 'master' into dev
maede97 Aug 4, 2024
d77308c
Bump vue from 3.4.34 to 3.4.35 in /docs
dependabot[bot] Aug 5, 2024
bb477a0
Bump the angular group in /frontend with 13 updates
dependabot[bot] Aug 5, 2024
25d1d44
Bump karma from 6.4.3 to 6.4.4 in /frontend
dependabot[bot] Aug 5, 2024
0d77315
Bump typescript from 5.5.3 to 5.5.4 in /frontend
dependabot[bot] Aug 5, 2024
2628f13
Bump @types/node from 22.0.0 to 22.1.0 in /frontend
dependabot[bot] Aug 5, 2024
34be7e8
Merge pull request #463 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 5, 2024
a61b06b
Merge pull request #462 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 5, 2024
c06abf0
Merge pull request #461 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 5, 2024
6322377
Merge pull request #460 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 5, 2024
8a33554
Merge pull request #459 from cevi/dependabot/npm_and_yarn/docs/dev/vu…
wp99cp Aug 5, 2024
f627650
Bump the angular group in /frontend with 13 updates
dependabot[bot] Aug 12, 2024
4216fb3
Bump zone.js from 0.14.8 to 0.14.10 in /frontend
dependabot[bot] Aug 12, 2024
c6f4fa4
Bump proj4 from 2.11.0 to 2.12.0 in /frontend
dependabot[bot] Aug 12, 2024
9e6a5ce
Bump vue from 3.4.35 to 3.4.37 in /docs
dependabot[bot] Aug 12, 2024
d0bc5da
Bump gunicorn from 22.0.0 to 23.0.0 in /backend
dependabot[bot] Aug 12, 2024
e2dab43
Merge pull request #471 from cevi/dependabot/pip/backend/dev/gunicorn…
wp99cp Aug 12, 2024
e8ac69a
Merge pull request #465 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 12, 2024
3c36f0a
Merge pull request #466 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 12, 2024
fef2c16
Merge pull request #470 from cevi/dependabot/npm_and_yarn/docs/dev/vu…
wp99cp Aug 12, 2024
7ae68aa
Merge pull request #467 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 12, 2024
7f112b7
Bump @types/node from 22.1.0 to 22.2.0 in /frontend
dependabot[bot] Aug 12, 2024
6589bcc
Bump vitepress from 1.3.1 to 1.3.2 in /docs
dependabot[bot] Aug 12, 2024
b858a57
Merge pull request #469 from cevi/dependabot/npm_and_yarn/docs/dev/vi…
wp99cp Aug 12, 2024
e7e73f5
Merge pull request #468 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Aug 12, 2024
db8d8a1
Bump the angular group in /frontend with 13 updates (#472)
dependabot[bot] Aug 19, 2024
352d423
Bump @types/node from 22.2.0 to 22.4.1 in /frontend (#473)
dependabot[bot] Aug 19, 2024
69595e7
Bump vitepress from 1.3.2 to 1.3.3 in /docs (#474)
dependabot[bot] Aug 19, 2024
96640d4
Bump numpy from 2.0.1 to 2.1.0 in /backend (#476)
dependabot[bot] Aug 19, 2024
c315337
Bump the angular group in /frontend with 13 updates (#479)
dependabot[bot] Aug 26, 2024
770002d
Bump ol from 10.0.0 to 10.1.0 in /frontend (#480)
dependabot[bot] Aug 26, 2024
2d3acdb
Bump @types/node from 22.4.1 to 22.5.0 in /frontend (#481)
dependabot[bot] Aug 26, 2024
fe3e5a5
Bump tslib from 2.6.3 to 2.7.0 in /frontend (#482)
dependabot[bot] Aug 26, 2024
a4df382
Bump vitepress from 1.3.3 to 1.3.4 in /docs (#478)
dependabot[bot] Aug 26, 2024
244d97c
Bump the angular group in /frontend with 13 updates (#483)
dependabot[bot] Sep 2, 2024
7a9438f
Bump @types/node from 22.5.0 to 22.5.2 in /frontend (#484)
dependabot[bot] Sep 2, 2024
c3f7d1d
Bump flask-cors from 4.0.1 to 5.0.0 in /backend (#485)
dependabot[bot] Sep 4, 2024
862c0d8
Bump vue from 3.4.38 to 3.5.3 in /docs (#492)
dependabot[bot] Sep 10, 2024
66f9ae7
Bump jasmine-core from 5.2.0 to 5.3.0 in /frontend (#491)
dependabot[bot] Sep 10, 2024
4a65cdb
Bump proj4 from 2.12.0 to 2.12.1 in /frontend (#490)
dependabot[bot] Sep 10, 2024
1a51de0
Bump @types/node from 22.5.2 to 22.5.4 in /frontend (#489)
dependabot[bot] Sep 10, 2024
5e63f23
Bump the angular group in /frontend with 13 updates (#488)
dependabot[bot] Sep 10, 2024
dd9dda4
Bump numpy from 2.1.0 to 2.1.1 in /backend (#487)
dependabot[bot] Sep 10, 2024
6b2c022
Bump vue from 3.5.3 to 3.5.6 in /docs (#496)
dependabot[bot] Sep 18, 2024
cd3cb5e
Bump the angular group in /frontend with 13 updates (#494)
dependabot[bot] Sep 18, 2024
247871a
Bump micromatch from 4.0.7 to 4.0.8 in /frontend (#493)
dependabot[bot] Sep 18, 2024
80be5e7
Implement Route-Storing and QR Code Generation (#464)
maede97 Sep 22, 2024
41d0b5f
fix linter
maede97 Sep 22, 2024
a3e82a5
downgrade valhalla
maede97 Sep 22, 2024
805107d
make linter happy
maede97 Sep 22, 2024
d5a2b33
downgrade valhalla also in dev
maede97 Sep 22, 2024
3d9979b
update entrypoint
maede97 Sep 22, 2024
b83f99c
multi stage build for swiss_TLM_API (#500)
johannschwabe Sep 22, 2024
4e5d458
make qr code bigger
maede97 Sep 22, 2024
4b021f1
move qr upwards
maede97 Sep 22, 2024
afa4b80
only rebuild the failed index
maede97 Sep 22, 2024
29e05a1
make linter happy
maede97 Sep 22, 2024
758405c
fix cypress
maede97 Sep 22, 2024
fe99388
fix cypress
maede97 Sep 22, 2024
f1e4ad0
add names to points
maede97 Sep 22, 2024
aeef28c
change conn
maede97 Sep 22, 2024
c596707
make linter happy
maede97 Sep 22, 2024
6091e8c
change docs url
maede97 Sep 22, 2024
52ededa
add logging
maede97 Sep 22, 2024
48bebb8
log username as well
maede97 Sep 22, 2024
df235da
log more
maede97 Sep 22, 2024
a1928f1
fix typo
maede97 Sep 22, 2024
3c1d143
remove loggers
maede97 Sep 22, 2024
c0e7b3a
add more fields
maede97 Sep 22, 2024
19ad4cd
fix extensoins
maede97 Sep 22, 2024
f535e98
fix
maede97 Sep 22, 2024
b70410e
use waypoints instead of pois
maede97 Sep 22, 2024
d79b140
make linter happy
maede97 Sep 22, 2024
9f5453c
try/catch map numbers
maede97 Sep 22, 2024
2adc07c
make linter happy
maede97 Sep 22, 2024
3e05d76
update index of split
maede97 Sep 22, 2024
a7ded25
Bump actions/setup-node from 4.0.3 to 4.0.4 (#502)
dependabot[bot] Sep 23, 2024
2b80482
Bump the angular group in /frontend with 13 updates (#503)
dependabot[bot] Sep 23, 2024
a6e854c
Bump vue from 3.5.6 to 3.5.8 in /docs (#504)
dependabot[bot] Sep 23, 2024
2956a7e
Bump ol from 10.1.0 to 10.2.0 in /frontend (#505)
dependabot[bot] Sep 23, 2024
f8b48c8
Bump pypdf from 4.3.1 to 5.0.0 in /backend (#506)
dependabot[bot] Sep 23, 2024
5736e36
add white rectangle to mapfish
maede97 Sep 23, 2024
fc036d1
change uuid to sth. meaningful
maede97 Sep 23, 2024
2bc0acc
revert rectangle change
maede97 Sep 23, 2024
be8b739
Bump the angular group in /frontend with 13 updates
dependabot[bot] Sep 30, 2024
bff6d26
Bump ol from 10.2.0 to 10.2.1 in /frontend
dependabot[bot] Sep 30, 2024
104b395
Bump @types/node from 22.5.4 to 22.7.4 in /frontend
dependabot[bot] Sep 30, 2024
354a636
Bump vue from 3.5.8 to 3.5.10 in /docs
dependabot[bot] Sep 30, 2024
e4cfaec
Bump pypdf from 5.0.0 to 5.0.1 in /backend
dependabot[bot] Sep 30, 2024
3382cb5
first try of waypoints to swisstopo app
wp99cp Sep 30, 2024
fe0e434
fix Swisstopo GPX export
wp99cp Sep 30, 2024
e9e3d58
format files
wp99cp Sep 30, 2024
d5cba74
Merge pull request #512 from cevi/dependabot/pip/backend/dev/pypdf-5.0.1
wp99cp Sep 30, 2024
58cd64b
Merge pull request #511 from cevi/dependabot/npm_and_yarn/docs/dev/vu…
wp99cp Sep 30, 2024
bf6ca01
Merge pull request #510 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Sep 30, 2024
65bedcb
Merge pull request #509 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Sep 30, 2024
521c4c3
Merge pull request #508 from cevi/dependabot/npm_and_yarn/frontend/de…
wp99cp Sep 30, 2024
301c616
cleanup and TODO fixes
wp99cp Oct 1, 2024
78f9532
add white rectangle behind image
wp99cp Oct 1, 2024
ae00bce
format files
wp99cp Oct 1, 2024
de41221
allow for off path drawing (#382)
wp99cp Oct 1, 2024
14ec7e0
allow to delete last point (partially implements #378)
wp99cp Oct 1, 2024
4c7178d
update Readme.md
wp99cp Oct 1, 2024
c187fa8
fix #499
wp99cp Oct 1, 2024
3a27131
improve container start time
wp99cp Oct 2, 2024
3cd0445
add remark about mongoDB password
wp99cp Oct 2, 2024
238abf6
switch to package imports
wp99cp Oct 2, 2024
59287e7
update mapfish version
wp99cp Oct 2, 2024
b33a495
Merge branch 'fix/upgrade-valhalla' into dev
wp99cp Oct 2, 2024
bbe60e2
remove experimental flag
wp99cp Oct 2, 2024
717c608
Merge branch 'feature/improve-drawing' into dev
wp99cp Oct 2, 2024
b55bc81
update change log
wp99cp Oct 2, 2024
68ae6ed
fix waypoint id
wp99cp Oct 2, 2024
9dbfb48
fix waypoint ids
wp99cp Oct 2, 2024
20747b1
add waypoint names to swisstopo export
wp99cp Oct 2, 2024
e7d1c89
format files
wp99cp Oct 2, 2024
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
5 changes: 5 additions & 0 deletions .env.ci-testing
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ FRONTEND_DOMAIN=http://awt-frontend
PRINT_API_BASE_URL=awt-mapfish-print-server
CYPRESS_BASE_URL=http://awt-frontend
VALHALLA_DOMAIN=http://awt-valhalla:8002
STORE_API_URL=http://awt-store-api:6000

# Configures the logging level for the backend
# valid values are DEBUG, INFO, WARNING, ERROR or CRITICAL
LOG_LEVEL=INFO

# MongoDB settings for route storing
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=pass
6 changes: 6 additions & 0 deletions .env.local-dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ DOCS_DOMAIN=http://localhost:4000
FRONTEND_DOMAIN=http://localhost
PRINT_API_BASE_URL=awt-mapfish-print-server
VALHALLA_DOMAIN=http://localhost:8002
STORE_API_URL=http://awt-store-api:6000

# Configures the logging level for the backend
# valid values are DEBUG, INFO, WARNING, ERROR or CRITICAL
LOG_LEVEL=DEBUG
FAULTHANDLER=true

# MongoDB settings for route storing
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=pass
ME_CONFIG_MONGODB_URL=mongodb://admin:pass@awt-mongodb:27017/
8 changes: 7 additions & 1 deletion .env.prod-dev
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ DOCS_DOMAIN=http://docs.dev.map.cevi.tools
FRONTEND_DOMAIN=https://dev.map.cevi.tools
PRINT_API_BASE_URL=awt-mapfish-print-server
VALHALLA_DOMAIN=https://valhalla.dev.map.cevi.tools
STORE_API_URL=http://awt-store-api:6000

# Configures the logging level for the backend
# valid values are DEBUG, INFO, WARNING, ERROR or CRITICAL
LOG_LEVEL=INFO
LOG_LEVEL=INFO

# MongoDB settings for route storing
MONGO_INITDB_ROOT_USERNAME=admin
# TODO: Change to the more secure password in production
wp99cp marked this conversation as resolved.
Show resolved Hide resolved
MONGO_INITDB_ROOT_PASSWORD=pass
10 changes: 8 additions & 2 deletions .env.prod-latest
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Configuration for the angular application: development or production
ANGULAR_BUILD_MODE=production
BACKEND_DOMAIN=https://backend.map.cevi.tools
DOCS_DOMAIN=http://docs.map.cevi.tools
DOCS_DOMAIN=https://docs.map.cevi.tools
FRONTEND_DOMAIN=https://map.cevi.tools
PRINT_API_BASE_URL=awt-mapfish-print-server
VALHALLA_DOMAIN=https://valhalla.map.cevi.tools
STORE_API_URL=http://awt-store-api:6000

# Configures the logging level for the backend
# valid values are DEBUG, INFO, WARNING, ERROR or CRITICAL
LOG_LEVEL=INFO
LOG_LEVEL=INFO

# MongoDB settings for route storing
MONGO_INITDB_ROOT_USERNAME=admin
# TODO: Change to the more secure password in production
wp99cp marked this conversation as resolved.
Show resolved Hide resolved
MONGO_INITDB_ROOT_PASSWORD=pass
2 changes: 1 addition & 1 deletion .github/workflows/create_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/[email protected].3
- uses: actions/[email protected].4
with:
node-version: '16'

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ jobs:
- name: 🛎️ Checkout
uses: actions/checkout@v4

- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
tool-cache: false
docker-images: false

- name: create dumy files for ./git/HEAD and ./git/refs/heads/
run: |
mkdir -p .git/refs/heads
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ anpassen (siehe auch J+S-Broschüre Berg).
GPX-File) dient dabei als Grundlage.
- [x] In einem nächsten Schritt soll es möglich sein, die gewählten Punkte auf der einer interaktiven Karte zu
visualisieren und bei Bedarf zu verschieben.
- [ ] Das Zeichnen neuer Routen soll direkt in unserem Webinterface möglich sein (damit entfällt der GPX-Export). Herzu
- [x] Das Zeichnen neuer Routen soll direkt in unserem Webinterface möglich sein (damit entfällt der GPX-Export). Herzu
werden magnetische Wege verwendet. D.h. die Route soll dabei automatisch an den nächsten Weg angepasst werden.

Weitere Funktionalitäten können gerne auch per Enhancement-Issue gewünscht werden.
Expand Down
133 changes: 127 additions & 6 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from threading import Thread

import polyline
import requests
from flask import Flask, request, send_file, redirect
from flask_cors import CORS

Expand All @@ -27,7 +28,8 @@
)
from automatic_walk_time_tables.path_transformers.pois_transfomer import POIsTransformer
from automatic_walk_time_tables.utils.error import UserException
from automatic_walk_time_tables.utils.path import Path
from automatic_walk_time_tables.utils.gpx_creator import create_gpx_file
from automatic_walk_time_tables.utils.path import Path, path_from_json
from automatic_walk_time_tables.utils.point import Point_LV95
from server_logging.log_helper import setup_recursive_logger
from server_logging.status_handler import ExportStateHandler, ExportStateLogger
Expand Down Expand Up @@ -297,10 +299,24 @@ def create_export(options, uuid):
if "name_points_in_export" not in options["settings"]:
options["settings"]["name_points_in_export"] = True

logger.info("OPTIONS:" + str(options))

generator = AutomatedWalkTableGenerator(uuid, options)
generator.set_data(path, way_points, pois)

store_dict = generator.get_store_dict()
r = requests.post(os.environ["STORE_API_URL"] + "/store", json=store_dict)
if r.status_code == 200:
logger.log(
ExportStateLogger.REQUESTABLE,
"Daten abgespeichert.",
{"uuid": uuid, "status": GeneratorStatus.RUNNING},
)
else:
logger.log(
ExportStateLogger.REQUESTABLE,
"Daten nicht abgespeichert.",
{"uuid": uuid, "status": GeneratorStatus.ERROR},
)

generator.run()

# Create a new thread and start it
Expand Down Expand Up @@ -373,9 +389,15 @@ def download(uuid):
base_path = pathlib.Path("./output/" + uuid + "/")
state = stateHandler.get_status(uuid)

if (state and state["status"] != GeneratorStatus.SUCCESS) or not os.path.exists(
base_path
):
status_ok = state and state["status"] == GeneratorStatus.SUCCESS
files_exists = os.path.exists(base_path)

storage = None
if not status_ok and not files_exists:
storage = fetch_data_for_uuid(uuid)

if not status_ok and not files_exists and storage is None:

# check if content type is HTML
if "text/html" in request.headers.get("Accept", ""):
frontend_url = os.environ["FRONTEND_DOMAIN"]
Expand All @@ -392,6 +414,35 @@ def download(uuid):
mimetype="application/json",
)

if not files_exists and storage is not None:

logger.debug("Files not found, creating them now.")
logger.debug("Storage options: %s" % storage["options"])

# Create the folder and files
thread = Thread(
target=create_export, kwargs={"options": storage["options"], "uuid": uuid}
)
thread.start()

return app.response_class(
response=json.dumps({"status": GeneratorStatus.RUNNING, "uuid": str(uuid)}),
status=200,
mimetype="application/json",
)

if not files_exists and storage is None:
return app.response_class(
response=json.dumps(
{
"status": GeneratorStatus.ERROR,
"message": "Die angeforderten Daten sind nicht verfügbar.",
}
),
status=404,
mimetype="application/json",
)

# Return Zip with data
data = io.BytesIO()
with zipfile.ZipFile(data, mode="w") as z:
Expand All @@ -409,6 +460,76 @@ def download(uuid):
)


def fetch_data_for_uuid(uuid):
"""
Fetches the data for the given UUID from the store API.
:param uuid: The UUID of the data to fetch
:return: The data for the given UUID or None if the data is not available
"""

r = requests.post(os.environ["STORE_API_URL"] + "/retrieve", json={"uuid": uuid})
if r.status_code == 200:
return r.json()

return None


@app.route("/retrieve/<uuid>")
def retrieve_route(uuid):
data = fetch_data_for_uuid(uuid)
if data is not None:
options = data["options"]
# TODO: check if the export folder still exists.
# if yes: do not export again, but rather just serve the folder
# if no: do as is now.

thread = Thread(
target=create_export, kwargs={"options": options, "uuid": str(uuid)}
)
thread.start()

return app.response_class(
response=json.dumps({"status": GeneratorStatus.RUNNING, "uuid": str(uuid)}),
status=200,
mimetype="application/json",
)
else:
return app.response_class(
response=json.dumps(
{
"status": GeneratorStatus.ERROR,
"message": "Die angeforderte GPX Datei ist nicht verfügbar.",
}
),
status=404,
mimetype="application/json",
)


@app.route("/gpx/<uuid>.gpx")
def generate_gpx(uuid):
data = fetch_data_for_uuid(uuid)

if data is None:
return app.response_class(
response=json.dumps(
{
"status": GeneratorStatus.ERROR,
"message": "Die angeforderte GPX Datei ist nicht verfügbar.",
}
),
status=404,
mimetype="application/json",
)

path: path.Path = path_from_json(data["path"])
way_points: path.Path = path_from_json(data["way_points"])
gpx_string = create_gpx_file(path, way_points)
return app.response_class(
response=gpx_string, status=200, mimetype="application/gpx+xml"
)


if __name__ == "__main__":
app.run(
debug=(os.environ.get("DEBUG", "False").lower() in ("true", "1", "t")),
Expand Down
34 changes: 33 additions & 1 deletion backend/automatic_walk_time_tables/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
from automatic_walk_time_tables.path_transformers.pois_transfomer import POIsTransformer
from automatic_walk_time_tables.utils import path
from automatic_walk_time_tables.utils.file_parser import GeoFileParser
from automatic_walk_time_tables.walk_time_table.walk_table import create_walk_table
from automatic_walk_time_tables.walk_time_table.walk_table import (
create_walk_table,
plot_elevation_profile,
)
from server_logging.status_handler import ExportStateLogger
from automatic_walk_time_tables.utils.error import UserException

Expand Down Expand Up @@ -93,6 +96,21 @@ def __create_files(self):
naming_fetcher = NamingTransformer()
self.__way_points = naming_fetcher.transform(self.__way_points)

self.__log_runtime(
plot_elevation_profile,
"Benötigte Zeit zum erstellen des Höhenprofils",
self.__path,
self.__way_points,
self.__pois,
file_name=name,
legend_position=self.options["settings"]["legend_position"],
)
self.__logger.log(
ExportStateLogger.REQUESTABLE,
"Höhenprofil wurde erstellt.",
{"uuid": self.uuid, "status": GeneratorStatus.RUNNING},
)

# We use fetch map numbers only for the selected way points,
# this is much faster that for every point in the original path. As the swiss_TML_api uses a tolerance
# of 2_000m anyway the chance to miss a map number is very small.
Expand Down Expand Up @@ -173,3 +191,17 @@ def set_data(self, path_data: path.Path, way_points: path.Path, pois: path.Path)
self.__path = path_data
self.__way_points = way_points
self.__pois = pois

def get_store_dict(self):

# name way_points
naming_fetcher = NamingTransformer(use_default_name=True)
__way_points = naming_fetcher.transform(self.__way_points)

return {
"uuid": self.uuid,
"options": self.options,
"path": self.__path.to_json(),
"pois": self.__pois.to_json(),
"way_points": __way_points.to_json(),
}
27 changes: 27 additions & 0 deletions backend/automatic_walk_time_tables/map_downloader/create_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
import time
import base64
from pathlib import Path
from typing import List

Expand Down Expand Up @@ -321,11 +322,14 @@ def create_mapfish_query(
point_layer = self.create_point_json(lv95, point, "#00BFFF", pointRadius=7)
point_layers.append(point_layer)

qr_code_string = self.__build_qr_code_string()

query_json = {
"layout": "A4 landscape",
"outputFormat": "pdf",
"attributes": {
"scale": "Massstab: 1:" + f"{map_scaling:,}".replace(",", "'"),
"qr_code": qr_code_string,
"map": {
"center": center,
"scale": map_scaling,
Expand All @@ -340,6 +344,29 @@ def create_mapfish_query(

return query_json

def __build_qr_code_string(self):
backend_domain = os.environ["BACKEND_DOMAIN"]
clear_url = f"{backend_domain}/gpx/{self.uuid}.gpx"
b64_url = base64.b64encode(clear_url.encode("ascii")).decode("ascii")
final_url = "https://swisstopo.app/u/" + b64_url
r = requests.post(
"https://backend.qr.cevi.tools/png",
json={"text": final_url},
)
if r.status_code == 200:
qr_code_bytes = r.content

# Convert the byte string to a base64-encoded string
base64_encoded = base64.b64encode(qr_code_bytes).decode("utf-8")

# Add the appropriate prefix for embedding in a webpage as a data URL
data_url = f"data:image/png;base64,{base64_encoded}"

# Print or return the data URL
return data_url
else:
return "" # TODO: does this work?

def create_point_json(
self, lv95, point, color="#FF0000", pointRadius=5, label=False
):
Expand Down
Loading
Loading