Skip to content

Commit

Permalink
Changes as per code review. (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
milo-hyben authored Nov 15, 2023
1 parent f4d7784 commit 2dc9d2f
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 173 deletions.
2 changes: 0 additions & 2 deletions api/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os

from api.routes.sample import router as sample_router
from api.routes.imports import router as import_router
from api.routes.analysis import router as analysis_router
Expand Down
6 changes: 3 additions & 3 deletions api/routes/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def get_datasets(


@router.get(
'/sequencing_types',
'/sequencing-types',
response_model=list[str],
operation_id='getSequencingTypes',
)
Expand Down Expand Up @@ -151,7 +151,7 @@ async def get_stages(


@router.get(
'/sequencing_groups',
'/sequencing-groups',
response_model=list[str],
operation_id='getSequencingGroups',
)
Expand All @@ -170,7 +170,7 @@ async def get_sequencing_groups(


@router.get(
'/invoice_months',
'/invoice-months',
response_model=list[str],
operation_id='getInvoiceMonths',
)
Expand Down
26 changes: 25 additions & 1 deletion api/utils/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def parse_date_only_string(d: str | None) -> date | None:


def get_invoice_month_range(convert_month: date) -> tuple[date, date]:
"""Get the start and end date of the invoice month for a given date"""
"""
Get the start and end date of the invoice month for a given date
Start and end date are used mostly for optimising BQ queries
All our BQ tables/views are partitioned by day
"""
first_day = convert_month.replace(day=1)

# Grab the first day of invoice month then subtract INVOICE_DAY_DIFF days
Expand All @@ -34,3 +38,23 @@ def get_invoice_month_range(convert_month: date) -> tuple[date, date]:
)

return start_day, last_day


def reformat_datetime(
in_date: str | None, in_format: str, out_format: str
) -> str | None:
"""
Reformat datetime as string to another string format
This function take string as input and return string as output
"""
if not in_date:
return None

try:
result = datetime.strptime(
in_date, in_format
)
return result.strftime(out_format)

except Exception as excep:
raise ValueError(f'Date could not be converted: {in_date}') from excep
Loading

0 comments on commit 2dc9d2f

Please sign in to comment.