Skip to content

Commit

Permalink
fix range parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Apr 18, 2024
1 parent c1829d6 commit 26bc19b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@ repos:
hooks:
- id: validate-pyproject

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
language_version: python

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
language_version: python

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.238
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.5
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
rev: v1.9.0
hooks:
- id: mypy
language_version: python
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.12.1 (2024-04-18)

* fix GET range parsing

## 0.12.0 (2024-01-24)

Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ default_section = "THIRDPARTY"
no_strict_optional = true

[tool.ruff]
line-length = 90

[tool.ruff.lint]
select = [
"D1", # pydocstyle errors
"E", # pycodestyle errors
Expand All @@ -105,3 +108,6 @@ ignore = [
"B008", # do not perform function calls in argument defaults
"B905", # ignore zip() without an explicit strict= parameter, only support with python >3.10
]

[tool.ruff.lint.mccabe]
max-complexity = 14
1 change: 0 additions & 1 deletion tests/test_viz.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tests for tilebench."""


from starlette.testclient import TestClient

from tilebench.viz import TileDebug
Expand Down
8 changes: 3 additions & 5 deletions tilebench/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ def parse_logs(logs: List[str]) -> Dict[str, Any]:
}

# GET
all_get_requests = len(
[line for line in logs if "CURL_INFO_HEADER_OUT: GET" in line]
)
all_get_requests = len([line for line in logs if "CURL_INFO_HEADER_OUT: GET" in line])

get_requests = [line for line in logs if ": Downloading" in line]
get_values = [
map(int, get.split(" Downloading ")[1].split(" ")[0].split("-"))
list(map(int, get.split(" Downloading ")[1].split(" ")[0].split("-")))
for get in get_requests
]
get_values_str = [get.split(" ")[4] for get in get_requests]
get_values_str = [f"{start}-{end}" for (start, end) in get_values]
data_transfer = sum([j - i + 1 for i, j in get_values])

get_summary = {
Expand Down
6 changes: 3 additions & 3 deletions tilebench/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ async def dispatch(self, request: Request, call_next):
ranges_results = "ranges; values={}".format(
"|".join(results["GET"]["ranges"])
)
response.headers[
"VSI-Stats"
] = f"{head_results}, {get_results}, {ranges_results}"
response.headers["VSI-Stats"] = (
f"{head_results}, {get_results}, {ranges_results}"
)

return response

Expand Down
8 changes: 4 additions & 4 deletions tilebench/scripts/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def profile(
module, classname = reader.rsplit(".", 1)
reader = getattr(importlib.import_module(module), classname) # noqa
if not issubclass(reader, (BaseReader, MultiBandReader, MultiBaseReader)):
warnings.warn(f"Invalid reader type: {type(reader)}")
warnings.warn(f"Invalid reader type: {type(reader)}", stacklevel=1)

Reader = reader or COGReader

Expand Down Expand Up @@ -159,7 +159,7 @@ def get_zooms(input, reader, tms):
module, classname = reader.rsplit(".", 1)
reader = getattr(importlib.import_module(module), classname) # noqa
if not issubclass(reader, (BaseReader, MultiBandReader, MultiBaseReader)):
warnings.warn(f"Invalid reader type: {type(reader)}")
warnings.warn(f"Invalid reader type: {type(reader)}", stacklevel=1)

Reader = reader or COGReader

Expand Down Expand Up @@ -191,7 +191,7 @@ def random(input, zoom, reader, tms):
module, classname = reader.rsplit(".", 1)
reader = getattr(importlib.import_module(module), classname) # noqa
if not issubclass(reader, (BaseReader, MultiBandReader, MultiBaseReader)):
warnings.warn(f"Invalid reader type: {type(reader)}")
warnings.warn(f"Invalid reader type: {type(reader)}", stacklevel=1)

Reader = reader or COGReader

Expand Down Expand Up @@ -253,7 +253,7 @@ def viz(src_path, port, host, server_only, reader, config):
module, classname = reader.rsplit(".", 1)
reader = getattr(importlib.import_module(module), classname) # noqa
if not issubclass(reader, (BaseReader)):
warnings.warn(f"Invalid reader type: {type(reader)}")
warnings.warn(f"Invalid reader type: {type(reader)}", stacklevel=1)

Reader = reader or COGReader

Expand Down
14 changes: 6 additions & 8 deletions tilebench/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,14 @@ def _read_tile(src_path: str, x: int, y: int, z: int):

head_results = "head;count={count}".format(**stats["HEAD"])
get_results = "get;count={count};size={bytes}".format(**stats["GET"])
ranges_results = "ranges; values={}".format(
"|".join(stats["GET"]["ranges"])
ranges_results = "ranges; values={}".format("|".join(stats["GET"]["ranges"]))
response.headers["VSI-Stats"] = (
f"{head_results}, {get_results}, {ranges_results}"
)
response.headers[
"VSI-Stats"
] = f"{head_results}, {get_results}, {ranges_results}"

response.headers[
"server-timing"
] = f"dataread; dur={round(t.elapsed * 1000, 2)}"
response.headers["server-timing"] = (
f"dataread; dur={round(t.elapsed * 1000, 2)}"
)
return "OK"

@self.router.get(
Expand Down

0 comments on commit 26bc19b

Please sign in to comment.