Skip to content

Commit

Permalink
Merge pull request #19 from publichealthengland/COV-59_csv_format_issue
Browse files Browse the repository at this point in the history
COV-59 csv format issue
  • Loading branch information
adebayoolabintan authored Mar 7, 2023
2 parents c457b1d + 3245b75 commit 75831c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
12 changes: 1 addition & 11 deletions app/engine/from_db/nested.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,17 @@ def process_nested_data(results: Iterable[Record], request: Request) -> DataFram
df = json_normalize(
map(dict, results),
nested_metric_name,
[*base_columns, MetricData.nested_struct[nested_metric_name]],
errors='ignore'
base_columns,
)

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

columns = [*base_columns, *MetricData.nested_struct[nested_metric_name]]
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: 4 additions & 8 deletions app/utils/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@


query = """\
SELECT rr.timestamp
SELECT rr.timestamp
FROM covid19.release_reference AS rr
JOIN covid19.release_category AS rc ON rc.release_id = rr.id
WHERE DATE(rr.timestamp) = $1
Expand Down Expand Up @@ -146,16 +146,12 @@ class MetricData:
"cumVaccinationThirdInjectionUptakeByVaccinationDatePercentage",
"cumVaccinationCompleteCoverageByVaccinationDatePercentage",

"newPeopleVaccinatedAutumn22ByVaccinationDate",
"cumPeopleVaccinatedAutumn22ByVaccinationDate",
"cumVaccinationAutumn22UptakeByVaccinationDatePercentage",
"newPeopleVaccinatedSpring22ByVaccinationDate",
"cumPeopleVaccinatedSpring22ByVaccinationDate",
"cumVaccinationSpring22UptakeByVaccinationDatePercentage",

'newPeopleVaccinatedSpring22ByVaccinationDate',
'newPeopleVaccinatedAutumn22ByVaccinationDate',
'cumPeopleVaccinatedSpring22ByVaccinationDate',
'cumPeopleVaccinatedAutumn22ByVaccinationDate',
'cumVaccinationAutumn22UptakeByVaccinationDatePercentage',
'cumVaccinationSpring22UptakeByVaccinationDatePercentage',
]
}

Expand Down
13 changes: 10 additions & 3 deletions app/utils/operations/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

# 3rd party:

# Internal:
# 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,7 +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}"
# 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 75831c0

Please sign in to comment.