Skip to content

Commit

Permalink
remove comments, adjust response url for sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslaw Michalski committed Mar 2, 2023
1 parent 380464e commit 3245b75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 20 deletions.
17 changes: 0 additions & 17 deletions app/engine/from_db/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,20 @@ def process_nested_data(results: Iterable[Record], request: Request) -> DataFram
]

if request.format == "csv":
columns = [*base_columns, *MetricData.nested_struct[nested_metric_name]]

df = json_normalize(
map(dict, results),
nested_metric_name,
base_columns,
# meta_prefix=f"{nested_metric_name}.",
# errors='ignore'
)
# df.drop(
# axis=1,
# columns=[f"{nested_metric_name}.{column}" for column in MetricData.nested_struct[nested_metric_name]],
# inplace=True
# )

# df.rename(
# columns={col: col.removeprefix(f"{nested_metric_name}.") for col in df.columns},
# inplace=True
# )

else:
df = DataFrame(
results,
columns=["areaCode", "areaType", "areaName", "date", "metric", nested_metric_name]
)
columns = df.columns

payload = (
df
.sort_values(["date", "areaCode"], ascending=[False, True])
# .loc[:, columns]
)
payload = payload.where(payload.notnull(), None)

Expand Down
12 changes: 9 additions & 3 deletions app/utils/operations/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# 3rd party:

# Internal:
from app.config import Settings
from ..assets import get_latest_timestamp
from .request import Request

Expand All @@ -21,7 +22,7 @@


API_PREFIX = "/api/"
API_URL = "coronavirus.data.gov.uk"
API_URL = Settings.service_domain

ResponseContentType = Union[None, bytes, AsyncGenerator[bytes, None]]

Expand All @@ -38,8 +39,13 @@ def __init__(self, request, container, path):
host: str = request.base_request.headers.get("X-Forwarded-Host", API_URL)
host = host.removeprefix("https://").removeprefix("api.")

# self.location = f"https://api.{host}/downloads/{container}/{path}"
self.location = f"https://{API_URL}/{container}/{path}"
# TODO: remove this IF statement when routing rule for rr-apiv2cache frontend
# domain name has been change
self.location = (
f"https://api.{host}/downloads/{container}/{path}"
if not host.startswith("sandbox")
else f"https://api-{host}/downloads/{container}/{path}"
)

permalink = f"https://{API_URL}/apiv2cache/{request.path}"

Expand Down

0 comments on commit 3245b75

Please sign in to comment.