Compare commits
No commits in common. "9f54c3ac038f8aa573f954b98019dd2d6351abf9" and "ace517c482e0d0cecad034a831ff1170f518ff73" have entirely different histories.
9f54c3ac03
...
ace517c482
|
@ -36,7 +36,6 @@ from . import (
|
||||||
uk_holiday,
|
uk_holiday,
|
||||||
)
|
)
|
||||||
from .types import Event, StrDict
|
from .types import Event, StrDict
|
||||||
from .utils import time_function
|
|
||||||
|
|
||||||
here = dateutil.tz.tzlocal()
|
here = dateutil.tz.tzlocal()
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ def timezone_transition(
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
async def n_somerset_waste_collection_events(
|
async def waste_collection_events(
|
||||||
data_dir: str, postcode: str, uprn: str
|
data_dir: str, postcode: str, uprn: str
|
||||||
) -> list[Event]:
|
) -> list[Event]:
|
||||||
"""Waste colllection events."""
|
"""Waste colllection events."""
|
||||||
|
@ -95,6 +94,22 @@ def find_events_during_stay(
|
||||||
return overlapping_markets
|
return overlapping_markets
|
||||||
|
|
||||||
|
|
||||||
|
async def time_function(
|
||||||
|
name: str,
|
||||||
|
func: typing.Callable[..., typing.Coroutine[typing.Any, typing.Any, typing.Any]],
|
||||||
|
*args: typing.Any,
|
||||||
|
**kwargs: typing.Any,
|
||||||
|
) -> tuple[str, typing.Any, float, Exception | None]:
|
||||||
|
"""Time the execution of an asynchronous function."""
|
||||||
|
start_time, result, exception = time(), None, None
|
||||||
|
try:
|
||||||
|
result = await func(*args, **kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
exception = e
|
||||||
|
end_time = time()
|
||||||
|
return name, result, end_time - start_time, exception
|
||||||
|
|
||||||
|
|
||||||
def hide_markets_while_away(
|
def hide_markets_while_away(
|
||||||
events: list[Event], accommodation_events: list[Event]
|
events: list[Event], accommodation_events: list[Event]
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -152,7 +167,7 @@ async def get_data(now: datetime, config: flask.config.Config) -> AgendaData:
|
||||||
time_function("gwr_advance_tickets", gwr.advance_ticket_date, data_dir),
|
time_function("gwr_advance_tickets", gwr.advance_ticket_date, data_dir),
|
||||||
time_function(
|
time_function(
|
||||||
"backwell_bins",
|
"backwell_bins",
|
||||||
n_somerset_waste_collection_events,
|
waste_collection_events,
|
||||||
data_dir,
|
data_dir,
|
||||||
config["BACKWELL_POSTCODE"],
|
config["BACKWELL_POSTCODE"],
|
||||||
config["BACKWELL_UPRN"],
|
config["BACKWELL_UPRN"],
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import typing
|
import typing
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import ephem # type: ignore
|
import ephem
|
||||||
|
|
||||||
|
|
||||||
def bristol() -> ephem.Observer:
|
def bristol() -> ephem.Observer:
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
"""Utility functions."""
|
"""Utility functions."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import typing
|
|
||||||
from datetime import date, datetime, timezone
|
from datetime import date, datetime, timezone
|
||||||
from time import time
|
|
||||||
|
|
||||||
|
|
||||||
def as_date(d: datetime | date) -> date:
|
def as_date(d: datetime | date) -> date:
|
||||||
|
@ -86,19 +84,3 @@ def make_waste_dir(data_dir: str) -> None:
|
||||||
waste_dir = os.path.join(data_dir, "waste")
|
waste_dir = os.path.join(data_dir, "waste")
|
||||||
if not os.path.exists(waste_dir):
|
if not os.path.exists(waste_dir):
|
||||||
os.mkdir(waste_dir)
|
os.mkdir(waste_dir)
|
||||||
|
|
||||||
|
|
||||||
async def time_function(
|
|
||||||
name: str,
|
|
||||||
func: typing.Callable[..., typing.Coroutine[typing.Any, typing.Any, typing.Any]],
|
|
||||||
*args: typing.Any,
|
|
||||||
**kwargs: typing.Any,
|
|
||||||
) -> tuple[str, typing.Any, float, Exception | None]:
|
|
||||||
"""Time the execution of an asynchronous function."""
|
|
||||||
start_time, result, exception = time(), None, None
|
|
||||||
try:
|
|
||||||
result = await func(*args, **kwargs)
|
|
||||||
except Exception as e:
|
|
||||||
exception = e
|
|
||||||
end_time = time()
|
|
||||||
return name, result, end_time - start_time, exception
|
|
||||||
|
|
Loading…
Reference in a new issue