Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions app/routers/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ class Sources(str, enum.Enum):
NYT = "nyt"


def get_latest_data(locations):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def get_latest_data(locations):
def _get_latest_data(locations) -> dict:

Can we make this private since it really shouldn't be used outside of this module?

return {
"confirmed": sum(map(lambda location: location.confirmed, locations)),
"deaths": sum(map(lambda location: location.deaths, locations)),
"recovered": sum(map(lambda location: location.recovered, locations)),
}

@V2.get("/latest", response_model=LatestResponse)
async def get_latest(
request: Request, source: Sources = Sources.JHU
Expand All @@ -27,15 +34,11 @@ async def get_latest(
Getting latest amount of total confirmed cases, deaths, and recoveries.
"""
locations = await request.state.source.get_all()
latest_data = get_latest_data(locations)
return {
"latest": {
"confirmed": sum(map(lambda location: location.confirmed, locations)),
"deaths": sum(map(lambda location: location.deaths, locations)),
"recovered": sum(map(lambda location: location.recovered, locations)),
}
"latest": latest_data
}


# pylint: disable=unused-argument,too-many-arguments,redefined-builtin
@V2.get("/locations", response_model=LocationsResponse, response_model_exclude_unset=True)
async def get_locations(
Expand Down Expand Up @@ -79,13 +82,10 @@ async def get_locations(
404, detail=f"Source `{source}` does not have the desired location data.",
)

latest_data = get_latest_data(locations)
# Return final serialized data.
return {
"latest": {
"confirmed": sum(map(lambda location: location.confirmed, locations)),
"deaths": sum(map(lambda location: location.deaths, locations)),
"recovered": sum(map(lambda location: location.recovered, locations)),
},
"latest": latest_data,
"locations": [location.serialize(timelines) for location in locations],
}

Expand Down