Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes as per code review. #608

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
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
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
Loading