Skip to content

Commit

Permalink
Merge branch 'main' into calendar_frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm authored Aug 23, 2023
2 parents 45a5f7c + 67457cc commit b3216b7
Show file tree
Hide file tree
Showing 67 changed files with 99,426 additions and 83,801 deletions.
64 changes: 20 additions & 44 deletions .github/workflows/server-cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,15 @@ jobs:
server
- run: cargo clippy --workspace
working-directory: server
feedback-build:
needs:
- tests
- linting
uses: ./.github/workflows/_docker-build.yml
with:
image_suffix: feedback
context: ./server
dockerfile: feedback/Dockerfile
permissions:
contents: read
packages: write
feedback-deployment:
uses: ./.github/workflows/_restart-argocd.yml
needs:
- feedback-build
with:
deployment: feedback
secrets:
ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
calendar-build:
needs:
- tests
- linting
uses: ./.github/workflows/_docker-build.yml
with:
image_suffix: calendar
context: ./server
dockerfile: calendar/Dockerfile
permissions:
contents: read
packages: write
calendar-deployment:
uses: ./.github/workflows/_restart-argocd.yml
needs:
- calendar-build
with:
deployment: calendar
secrets:
ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
main-api-build:
server-build:
uses: ./.github/workflows/_docker-build.yml
needs:
- tests
- linting
with:
image_suffix: main-api
image_suffix: server
context: ./server
dockerfile: main-api/Dockerfile.server
dockerfile: Dockerfile
permissions:
contents: read
packages: write
Expand Down Expand Up @@ -124,10 +84,26 @@ jobs:
permissions:
contents: read
packages: write
feedback-deployment:
uses: ./.github/workflows/_restart-argocd.yml
needs:
- server-build
with:
deployment: feedback
secrets:
ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
calendar-deployment:
uses: ./.github/workflows/_restart-argocd.yml
needs:
- server-build
with:
deployment: calendar
secrets:
ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
server-deployment:
uses: ./.github/workflows/_restart-argocd.yml
needs:
- main-api-build
- server-build
- building-db-init-build
- mieli-search-init-build
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ docker run -it --rm -v /tmp/navigatum/meili:/meili_data ghcr.io/tum-dev/navigatu
docker run -it --rm -p 7700:7700 --name search -v /tmp/navigatum/meili:/meili_data --network navigatum-net getmeili/meilisearch:latest

docker run -it --rm -v /tmp:/navigatum/server/ ghcr.io/tum-dev/navigatum-building-db-init:main
docker run -it --rm -p 8080:8080 --network navigatum-net -e API_SVC_SERVICE_HOST=search ghcr.io/tum-dev/navigatum-main-api:main
docker run -it --rm -p 8080:8080 --network navigatum-net -e API_SVC_SERVICE_HOST=search ghcr.io/tum-dev/navigatum-server:main /bin/navigatum-main-api
```

Else you can follow the steps in the [server documentation](server/README.md).
Expand Down
23 changes: 13 additions & 10 deletions data/compile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
import os
from multiprocessing import Process

import processors.areatree.process as areatree
import processors.maps.process as maps
from processors import (
coords,
export,
images,
maps,
merge,
nat,
poi,
Expand All @@ -26,6 +27,11 @@
# pylint: disable=too-many-locals,too-many-statements
def main() -> None:
"""Main function"""
# start other thread to resize images
logging.info("-- (Parallel) Convert, resize and crop the images for different resolutions and formats")
resizer = Process(target=images.resize_and_crop)
resizer.start()

# --- Read base data ---
logging.info("-- 00 areatree")
data = areatree.read_areatree()
Expand Down Expand Up @@ -89,13 +95,11 @@ def main() -> None:
coords.add_and_check_coords(data)

logging.info("-- 45 Roomfinder maps")
maps.roomfinder_maps(data)
maps.add_roomfinder_maps(data)

logging.info("-- 46 Overlay maps")
maps.add_overlay_maps(data)

logging.info("-- 50 Convert, resize and crop the images for different resolutions and formats")
images.resize_and_crop()
logging.info("-- 51 Add image information")
images.add_img(data)

Expand All @@ -118,15 +122,14 @@ def main() -> None:
logging.info("-- 97 Search: Get combined ranking")
search.add_ranking_combined(data)

logging.info("-- 99 Search: Export")
logging.info("-- 100 Export and generate Sitemap")
export.export_for_search(data, "output/search_data.json")

logging.info("-- 100 Export: API")
export.export_for_api(data, "output/api_data.json")
sitemap.generate_sitemap() # only for deployments

# Sitemap is only generated for deployments
logging.info("-- 101 Extra: Sitemap")
sitemap.generate_sitemap()
resizer.join(timeout=60 * 4)
if resizer.exitcode != 0:
raise RuntimeError("Resizer process during the execution of the script")


if __name__ == "__main__":
Expand Down
21 changes: 11 additions & 10 deletions data/external/models/common.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
from pathlib import Path

import pydantic
from pydantic.dataclasses import dataclass
from pydantic import BaseModel

PydanticConfiguration = pydantic.ConfigDict(
frozen=True,
str_strip_whitespace=True,
extra=pydantic.Extra.forbid,
populate_by_name=True,
validate_default=True,
)

class PydanticConfiguration(BaseModel):
model_config = pydantic.ConfigDict(
frozen=True,
str_strip_whitespace=True,
extra=pydantic.Extra.forbid,
populate_by_name=True,
validate_default=True,
)


RESULTS = Path(__file__).parent.parent / "results"


@dataclass(config=PydanticConfiguration)
class TranslatableStr:
class TranslatableStr(PydanticConfiguration):
# pylint: disable-next=invalid-name
de: str
# pylint: disable-next=invalid-name
Expand Down
40 changes: 19 additions & 21 deletions data/external/models/nat.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import json

from external.models.common import PydanticConfiguration, RESULTS, TranslatableStr
from pydantic.dataclasses import dataclass


@dataclass(config=PydanticConfiguration)
class Building:
class Building(PydanticConfiguration):
building_code: str
building_id: int | None
building_name: str
Expand All @@ -16,51 +14,45 @@ class Building:
def load_all(cls) -> list["Building"]:
"""Load all nat.Building's"""
with open(RESULTS / "buildings_nat.json", encoding="utf-8") as file:
return [cls(**item) for item in json.load(file)]
return [cls.model_validate(item) for item in json.load(file)]


@dataclass(config=PydanticConfiguration)
class Campus:
class Campus(PydanticConfiguration):
campus: TranslatableStr
campusshort: TranslatableStr

@classmethod
def load_all(cls) -> dict[str, "Campus"]:
"""Load all nat.Campus's"""
with open(RESULTS / "campus_nat.json", encoding="utf-8") as file:
return {key: cls(**item) for key, item in json.load(file).items()}
return {key: cls.model_validate(item) for key, item in json.load(file).items()}


@dataclass(config=PydanticConfiguration)
class Coordinate:
class Coordinate(PydanticConfiguration):
lat: float | None
lon: float | None
source: str


@dataclass(config=PydanticConfiguration)
class MapType:
class MapType(PydanticConfiguration):
maptype_id: int
maptype: TranslatableStr


@dataclass(config=PydanticConfiguration)
class Map:
class Map(PydanticConfiguration):
map_id: int
maptype: MapType
url: str


@dataclass(config=PydanticConfiguration)
class SeatingPlan:
class SeatingPlan(PydanticConfiguration):
seat_count: int
seating: TranslatableStr
seating_id: int


@dataclass(config=PydanticConfiguration)
# pylint: disable-next=too-many-instance-attributes
class Room:
class Room(PydanticConfiguration):
description: str
purpose: TranslatableStr
purpose_id: int
Expand Down Expand Up @@ -91,18 +83,24 @@ class Room:
def load_all(cls) -> dict[str, "Room"]:
"""Load all nat.Room's"""
with open(RESULTS / "rooms_nat.json", encoding="utf-8") as file:
return {key: cls(**item) for key, item in json.load(file).items()}
return {key: cls.model_validate(item) for key, item in json.load(file).items()}


@dataclass(config=PydanticConfiguration)
class Organisation:
class School(PydanticConfiguration):
org_code: str
org_name: TranslatableStr | str
org_id: int


class Organisation(PydanticConfiguration):
org_code: str
org_name: TranslatableStr
org_type: str
org_url: str | None
school: School | None

@classmethod
def load_all(cls) -> dict[str, "Organisation"]:
"""Load all nat.Organisation's"""
with open(RESULTS / "orgs_nat.json", encoding="utf-8") as file:
return {key: cls(**item) for key, item in json.load(file).items()}
return {key: cls.model_validate(item) for key, item in json.load(file).items()}
9 changes: 3 additions & 6 deletions data/external/models/public_transport.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import json

from external.models.common import PydanticConfiguration, RESULTS
from pydantic.dataclasses import dataclass


@dataclass(config=PydanticConfiguration)
class SubStation:
class SubStation(PydanticConfiguration):
station_id: str
name: str
lat: float
lon: float


@dataclass(config=PydanticConfiguration)
class Station:
class Station(PydanticConfiguration):
station_id: str
name: str
lat: float
Expand All @@ -24,4 +21,4 @@ class Station:
def load_all(cls) -> list["Station"]:
"""Load all public_transport.Station's"""
with open(RESULTS / "public_transport.json", encoding="utf-8") as file:
return [cls(**item) for item in json.load(file)]
return [cls.model_validate(item) for item in json.load(file)]
Loading

0 comments on commit b3216b7

Please sign in to comment.