Skip to content

Commit

Permalink
migrated from public transport to nearby locations
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jul 28, 2024
1 parent 10325a0 commit 80d8517
Show file tree
Hide file tree
Showing 15 changed files with 358 additions and 93 deletions.
4 changes: 0 additions & 4 deletions data/compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
merge,
nat,
poi,
public_transport,
roomfinder,
search,
sections,
Expand Down Expand Up @@ -110,9 +109,6 @@ def main() -> None:
sections.generate_buildings_overview(data)
sections.generate_rooms_overview(data)

logging.info("-- 82 Generate public transport")
public_transport.add_nearby_public_transport(data)

logging.info("-- 90 Search: Build base ranking")
search.add_ranking_base(data)

Expand Down
38 changes: 0 additions & 38 deletions data/processors/public_transport.py

This file was deleted.

1 change: 0 additions & 1 deletion data/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ backoff==2.2.1
beautifulsoup4==4.12.3
defusedxml==0.7.1
lxml==5.2.2
numba==0.60.0
Pillow==10.4.0
pydantic==2.8.2
pyyaml==6.0.1
Expand Down
4 changes: 1 addition & 3 deletions data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pathlib import Path
from typing import Any, Union

import numba
from PIL import Image
from ruamel.yaml import YAML

Expand Down Expand Up @@ -119,10 +118,9 @@ def setup_logging(level: int = logging.INFO) -> None:
EARTH_RADIUS_METERS: int = 6_371_000


@numba.njit(cache=True, fastmath=True)
def distance_via_great_circle(lat1: float, lon1: float, lat2: float, lon2: float) -> float:
"""
Calculate the approximate distance in meters betweeen two points using the great circle approach
Calculate the approximate distance in meters between two points using the great circle approach
Basic idea from https://blog.petehouston.com/calculate-distance-of-two-locations-on-earth/
"""
Expand Down
103 changes: 68 additions & 35 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,56 @@ paths:
description: The uri you are trying to request is unreasonably long. Search querys dont have thousands of chars..
tags:
- core
'/api/locations/{id}/nearby':
get:
operationId: nearby
summary: Get the nearby items
description: |
Shows nearby POIs like public transport stations
parameters:
- name: id
in: path
description: string you want to search for
required: true
schema:
type: string
examples:
'1543':
summary: virtual room (humangenetik)
value: '1543'
'5304':
summary: normal building
value: '5304'
garching:
summary: garching campus
value: garching
mri:
summary: MRI campus
value: mri
mi:
summary: large building (mi)
value: mi
mw:
summary: other large building (mw)
value: mw
5606.EG.036:
summary: regular room (fsmpic)
value: 5606.EG.036
5605.EG.011:
summary: room with custom props (rechnerhalle-mi)
value: 5605.EG.011
5401.01.100A:
summary: virtual room (tb-chemie)
value: 5401.01.100A
responses:
'200':
description: More data about the requested building/room
content:
application/json:
schema:
$ref: '#/components/schemas/NearbyLocationsResponse'
examples:
mi-hs-1:
'/api/get/{id}':
get:
operationId: details
Expand Down Expand Up @@ -1800,6 +1850,16 @@ components:
required:
- sections
- time_ms
NearbyLocationsResponse:
type: object
properties:
public_transport:
type: array
items:
$ref: '#/components/schemas/Station'
maxItems: 50
required:
- public_transport
DetailsResponse:
type: object
properties:
Expand Down Expand Up @@ -1895,17 +1955,6 @@ components:
$ref: '#/components/schemas/RoomsOverview'
featured_overview:
$ref: '#/components/schemas/FeaturedOverview'
poi:
type: object
properties:
mvg:
type: array
items:
$ref: '#/components/schemas/Station'
minItems: 1
uniqueItems: true
required:
- mvg
required:
- id
- type
Expand Down Expand Up @@ -2338,12 +2387,16 @@ components:
Station:
type: object
properties:
id:
type: string
parent_id:
type: string
parent_name:
type: string
distance:
type: number
format: double
exclusiveMinimum: 0
station_id:
type: string
name:
type: string
lat:
Expand All @@ -2352,33 +2405,13 @@ components:
lon:
type: number
format: double
sub_stations:
type: array
items:
type: object
properties:
station_id:
type: string
name:
type: string
lat:
type: number
format: double
lon:
type: number
format: double
required:
- station_id
- name
- lat
- lon
required:
- parent_id
- distance
- station_id
- id
- name
- lat
- lon
- sub_stations
x-examples:
Example 1:
distance: 264.3434461761658
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions server/main-api/migrations/20240727225546_transport.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add down migration script here
DROP table transportation_stations;
15 changes: 15 additions & 0 deletions server/main-api/migrations/20240727225546_transport.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Add up migration script here
CREATE TABLE transportation_stations
(
parent TEXT NULL,
id TEXT UNIQUE PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
coordinate Point NOT NULL
);
alter table transportation_stations
add constraint transportation_stations_transportation_stations_station_id_fk
foreign key (parent) references transportation_stations
on update cascade on delete set null;
CREATE INDEX transportation_stations_loc_idx
ON transportation_stations
USING GIST (coordinate);
3 changes: 3 additions & 0 deletions server/main-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ mod feedback;
mod limited;
mod maps;
mod models;
mod nearby;
mod search;
mod setup;
mod utils;
Expand Down Expand Up @@ -149,6 +150,7 @@ async fn run_maintenance_work(
let _ = debug_span!("updating postgis data").enter();
setup::database::setup(&pool).await.unwrap();
setup::database::load_data(&pool).await.unwrap();
setup::transportation::setup(&pool).await.unwrap();
} else {
info!("skipping the database setup as SKIP_DB_SETUP=true");
}
Expand Down Expand Up @@ -193,6 +195,7 @@ async fn run() -> Result<(), BoxedError> {
.service(web::scope("/api/feedback").configure(feedback::configure))
.service(details::get_handler)
.service(search::search_handler)
.service(nearby::nearby_handler)
})
.bind(std::env::var("BIND_ADDRESS").unwrap_or_else(|_| "0.0.0.0:3003".to_string()))?
.run()
Expand Down
Loading

0 comments on commit 80d8517

Please sign in to comment.