Calculating time-to-import for map pbf files in the backend. These times were created using a test RPi4. Encoding URL of archive files to prevent error which blocked displaying of archives.

This commit is contained in:
Roland 2022-03-12 09:50:16 -07:00
parent 6a22090e54
commit c815aa68c6
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
10 changed files with 46 additions and 59 deletions

View file

@ -113,12 +113,14 @@ async def import_pbf(pbf: Path):
stdout, stderr = await proc.communicate()
elapsed = now() - start
logger.info(f'Import of {pbf} took {timedelta_to_timestamp(elapsed)}')
success = 'Successful' if proc.returncode == 0 else 'Unsuccessful'
logger.info(f'{success} import of {pbf.name} took {timedelta_to_timestamp(elapsed)}')
if proc.returncode != 0:
# Log all lines. Truncate long lines.
for line in stdout.decode().splitlines():
logger.info(line)
logger.debug(line[:500])
for line in stderr.decode().splitlines():
logger.error(line)
logger.error(line[:500])
raise ValueError(f'Importing PBF failed with return code {proc.returncode}')

View file

@ -1,8 +1,16 @@
from sqlalchemy import Column, Integer, Boolean, BigInteger
from wrolpi import dates
from wrolpi.common import Base, ModelHelper
from wrolpi.media_path import MediaPathType
RPI4_BYTES_PER_SECOND = 3963
def seconds_to_import(size: int) -> int:
"""Attempt to predict how long it will take an RPi4 to import a given PBF file."""
return max(int(size // RPI4_BYTES_PER_SECOND), 0)
class MapFile(Base, ModelHelper):
__tablename__ = 'map_file'
@ -18,4 +26,5 @@ class MapFile(Base, ModelHelper):
'path': self.path,
'imported': self.imported,
'size': self.size,
'time_to_import': dates.seconds_to_timestamp(seconds_to_import(self.size)),
}

View file

@ -0,0 +1,16 @@
import pytest
from modules.map import models
@pytest.mark.parametrize('size,expected', [
(0, 0),
(-1, 0),
(17737381, 4475),
(63434267, 16006),
(87745484, 22141),
(136372996, 34411),
(116318111, 29351),
])
def test_seconds_to_import_rpi4(size, expected):
assert models.seconds_to_import(size) == expected