Add lean mode (overpass source and no map view in frontend)
This commit is contained in:
parent
d10b91804c
commit
3ef6dcf5d9
|
@ -4,6 +4,7 @@ DEBUG = True
|
||||||
VERBOSE = False
|
VERBOSE = False
|
||||||
AUTO_RESTART = True
|
AUTO_RESTART = True
|
||||||
SECRET = "!!!!!!!!!!!!CHANGE ME!!!!!!!!!!!!"
|
SECRET = "!!!!!!!!!!!!CHANGE ME!!!!!!!!!!!!"
|
||||||
|
LEAN_MODE = True
|
||||||
POSTGRES_URL = "postgresql+asyncpg://obs:obs@postgres/obs"
|
POSTGRES_URL = "postgresql+asyncpg://obs:obs@postgres/obs"
|
||||||
POSTGRES_POOL_SIZE = 20
|
POSTGRES_POOL_SIZE = 20
|
||||||
POSTGRES_MAX_OVERFLOW = 2 * POSTGRES_POOL_SIZE
|
POSTGRES_MAX_OVERFLOW = 2 * POSTGRES_POOL_SIZE
|
||||||
|
|
|
@ -7,6 +7,11 @@ DEBUG = False
|
||||||
VERBOSE = DEBUG
|
VERBOSE = DEBUG
|
||||||
AUTO_RESTART = DEBUG
|
AUTO_RESTART = DEBUG
|
||||||
|
|
||||||
|
# Turn on lean mode to simplify the setup. Lots of features will be
|
||||||
|
# unavailable, but you will not need to manage OpenStreetMap data. Please make
|
||||||
|
# sure to configure the OBS_FACE_CACHE_DIR correctly for lean mode.
|
||||||
|
LEAN_MODE = False
|
||||||
|
|
||||||
# Required to encrypt or sign sessions, cookies, tokens, etc.
|
# Required to encrypt or sign sessions, cookies, tokens, etc.
|
||||||
SECRET = "!!!<<<CHANGEME>>>!!!"
|
SECRET = "!!!<<<CHANGEME>>>!!!"
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ from obs.face.filter import (
|
||||||
RequiredFieldsFilter,
|
RequiredFieldsFilter,
|
||||||
)
|
)
|
||||||
|
|
||||||
from obs.face.osm import DataSource, DatabaseTileSource
|
from obs.face.osm import DataSource, DatabaseTileSource, OverpassTileSource
|
||||||
|
|
||||||
from obs.api.db import OvertakingEvent, Track, make_session
|
from obs.api.db import OvertakingEvent, Track, make_session
|
||||||
from obs.api.app import app
|
from obs.api.app import app
|
||||||
|
@ -33,6 +33,20 @@ from obs.api.app import app
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def get_data_source():
|
||||||
|
"""
|
||||||
|
Creates a data source based on the configuration of the portal. In *lean*
|
||||||
|
mode, the OverpassTileSource is used to fetch data on demand. In normal
|
||||||
|
mode, the roads database is used.
|
||||||
|
"""
|
||||||
|
if app.config.LEAN_MODE:
|
||||||
|
tile_source = OverpassTileSource(cache_dir=app.config.OBS_FACE_CACHE_DIR)
|
||||||
|
else:
|
||||||
|
tile_source = DatabaseTileSource()
|
||||||
|
|
||||||
|
return DataSource(tile_source)
|
||||||
|
|
||||||
|
|
||||||
async def process_tracks_loop(delay):
|
async def process_tracks_loop(delay):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -50,9 +64,7 @@ async def process_tracks_loop(delay):
|
||||||
await asyncio.sleep(delay)
|
await asyncio.sleep(delay)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
tile_source = DatabaseTileSource()
|
data_source = get_data_source()
|
||||||
data_source = DataSource(tile_source)
|
|
||||||
|
|
||||||
await process_track(session, track, data_source)
|
await process_track(session, track, data_source)
|
||||||
except BaseException:
|
except BaseException:
|
||||||
log.exception("Failed to process track. Will continue.")
|
log.exception("Failed to process track. Will continue.")
|
||||||
|
@ -66,8 +78,7 @@ async def process_tracks(tracks):
|
||||||
|
|
||||||
:param tracks: A list of strings which
|
:param tracks: A list of strings which
|
||||||
"""
|
"""
|
||||||
tile_source = DatabaseTileSource()
|
data_source = get_data_source()
|
||||||
data_source = DataSource(tile_source)
|
|
||||||
|
|
||||||
async with make_session() as session:
|
async with make_session() as session:
|
||||||
for track_id_or_slug in tracks:
|
for track_id_or_slug in tracks:
|
||||||
|
|
|
@ -6,6 +6,7 @@ from sanic.exceptions import NotFound
|
||||||
from obs.api.app import app
|
from obs.api.app import app
|
||||||
|
|
||||||
if app.config.FRONTEND_CONFIG:
|
if app.config.FRONTEND_CONFIG:
|
||||||
|
|
||||||
@app.get("/config.json")
|
@app.get("/config.json")
|
||||||
def get_frontend_config(req):
|
def get_frontend_config(req):
|
||||||
result = {
|
result = {
|
||||||
|
@ -13,7 +14,10 @@ if app.config.FRONTEND_CONFIG:
|
||||||
**req.app.config.FRONTEND_CONFIG,
|
**req.app.config.FRONTEND_CONFIG,
|
||||||
"apiUrl": f"{req.ctx.api_url}/api",
|
"apiUrl": f"{req.ctx.api_url}/api",
|
||||||
"loginUrl": f"{req.ctx.api_url}/login",
|
"loginUrl": f"{req.ctx.api_url}/login",
|
||||||
"obsMapSource": {
|
"obsMapSource": (
|
||||||
|
None
|
||||||
|
if app.config.LEAN_MODE
|
||||||
|
else {
|
||||||
"type": "vector",
|
"type": "vector",
|
||||||
"tiles": [
|
"tiles": [
|
||||||
req.ctx.api_url
|
req.ctx.api_url
|
||||||
|
@ -24,7 +28,8 @@ if app.config.FRONTEND_CONFIG:
|
||||||
],
|
],
|
||||||
"minzoom": 12,
|
"minzoom": 12,
|
||||||
"maxzoom": 14,
|
"maxzoom": 14,
|
||||||
},
|
}
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.json(result)
|
return response.json(result)
|
||||||
|
|
|
@ -59,6 +59,8 @@ const App = connect((state) => ({login: state.login}))(function App({login}) {
|
||||||
const config = useConfig()
|
const config = useConfig()
|
||||||
const apiVersion = useObservable(() => from(api.get('/info')).pipe(pluck('version')))
|
const apiVersion = useObservable(() => from(api.get('/info')).pipe(pluck('version')))
|
||||||
|
|
||||||
|
const hasMap = Boolean(config?.obsMapSource)
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
api.loadUser()
|
api.loadUser()
|
||||||
}, [])
|
}, [])
|
||||||
|
@ -72,7 +74,7 @@ const App = connect((state) => ({login: state.login}))(function App({login}) {
|
||||||
OpenBikeSensor
|
OpenBikeSensor
|
||||||
</Link>
|
</Link>
|
||||||
|
|
||||||
{config?.obsMapSource && (
|
{hasMap && (
|
||||||
<Link component={MenuItemForLink} to="/map" as="a">
|
<Link component={MenuItemForLink} to="/map" as="a">
|
||||||
Map
|
Map
|
||||||
</Link>
|
</Link>
|
||||||
|
@ -110,9 +112,9 @@ const App = connect((state) => ({login: state.login}))(function App({login}) {
|
||||||
<Route path="/" exact>
|
<Route path="/" exact>
|
||||||
<HomePage />
|
<HomePage />
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/map" exact>
|
{hasMap && <Route path="/map" exact>
|
||||||
<MapPage />
|
<MapPage />
|
||||||
</Route>
|
</Route>}
|
||||||
<Route path="/tracks" exact>
|
<Route path="/tracks" exact>
|
||||||
<TracksPage />
|
<TracksPage />
|
||||||
</Route>
|
</Route>
|
||||||
|
|
Loading…
Reference in a new issue