mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 11:56:18 -05:00
Reworking map import to handle postgres data dumps.
This commit is contained in:
parent
be4c3a5021
commit
5178f72b66
11 changed files with 194 additions and 109 deletions
|
|
@ -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)),
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue