From f44ac9131955e9121678c9fbfd7411e5f182863a Mon Sep 17 00:00:00 2001 From: Roland Date: Thu, 7 Sep 2023 13:01:19 -0600 Subject: [PATCH] Use exponential curve for large map files. --- modules/map/lib.py | 6 ++++++ modules/map/test/test_lib.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/map/lib.py b/modules/map/lib.py index d548fbae..fc8f816f 100644 --- a/modules/map/lib.py +++ b/modules/map/lib.py @@ -230,4 +230,10 @@ RPI4_PBF_BYTES_PER_SECOND = 61879 def seconds_to_import(size_in_bytes: int) -> int: """Attempt to predict how long it will take an RPi4 to import a given PBF file.""" + if size_in_bytes > 1_000_000_000: + # Use exponential curve for large files. These magic numbers are from testing many imports on an RPi 4. + a = 7.17509261732342e-14 * size_in_bytes ** 2 + b = 6.6590760410412e-5 * size_in_bytes + c = 10283 + return int(a - b + c) return max(int(size_in_bytes // RPI4_PBF_BYTES_PER_SECOND), 0) diff --git a/modules/map/test/test_lib.py b/modules/map/test/test_lib.py index 4573b1de..58d3d217 100644 --- a/modules/map/test/test_lib.py +++ b/modules/map/test/test_lib.py @@ -73,8 +73,12 @@ async def test_run_import_command(test_directory, mock_create_subprocess_shell): (17737381, 286), (63434267, 1025), (87745484, 1418), - (136372996, 2203), (116318111, 1879), + (136372996, 2203), + (1936075318, 150308), + (2676094489, 345922), + (3392375001, 610106), + (11346305075, 8491840), ]) def test_seconds_to_import_rpi4(size, expected): assert lib.seconds_to_import(size) == expected