Reworking map import to handle postgres data dumps.

This commit is contained in:
Roland 2022-03-31 07:31:15 -06:00
parent be4c3a5021
commit 5178f72b66
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
11 changed files with 194 additions and 109 deletions

View file

@ -1,15 +1,21 @@
from pathlib import Path
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
RPI4_PBF_BYTES_PER_SECOND = 3963
def seconds_to_import(size: int) -> int:
def seconds_to_import(path: Path, 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)
if str(path).endswith('.osm.pbf'):
return max(int(size // RPI4_PBF_BYTES_PER_SECOND), 0)
# Can't calculate an unknown file.
return 0
class MapFile(Base, ModelHelper):
@ -20,11 +26,14 @@ class MapFile(Base, ModelHelper):
imported = Column(Boolean, default=False, nullable=False)
size = Column(BigInteger)
def __repr__(self):
return f'<MapFile {self.path} imported={self.imported}>'
def __json__(self):
return {
'id': self.id,
'path': self.path,
'imported': self.imported,
'size': self.size,
'time_to_import': dates.seconds_to_timestamp(seconds_to_import(self.size)),
'time_to_import': dates.seconds_to_timestamp(seconds_to_import(self.path.path, self.size)),
}