Skip to content

Commit

Permalink
Merge pull request #667 from populationgenomics/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
milo-hyben authored Jan 28, 2024
2 parents a3eac91 + 733330c commit c8ce4e2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
10 changes: 5 additions & 5 deletions db/python/tables/bq/billing_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from db.python.tables.bq.billing_filter import BillingFilter
from db.python.tables.bq.function_bq_filter import FunctionBQFilter
from db.python.tables.bq.generic_bq_filter import GenericBQFilter
from models.enums import BillingTimePeriods
from models.enums import BillingTimeColumn, BillingTimePeriods
from models.models import (
BillingColumn,
BillingCostBudgetRecord,
Expand Down Expand Up @@ -44,26 +44,26 @@ def prepare_time_periods(
query: BillingTotalCostQueryModel,
) -> TimeGroupingDetails:
"""Prepare Time periods grouping and parsing formulas"""
time_column = query.time_column or BillingTimePeriods.DAY
time_column: BillingTimeColumn = query.time_column or BillingTimeColumn.DAY

# Based on specified time period, add the corresponding column
if query.time_periods == BillingTimePeriods.DAY:
return TimeGroupingDetails(
field=f'FORMAT_DATE("%Y-%m-%d", {time_column}) as day',
field=f'FORMAT_DATE("%Y-%m-%d", {time_column.value}) as day',
formula='PARSE_DATE("%Y-%m-%d", day) as day',
separator=',',
)

if query.time_periods == BillingTimePeriods.WEEK:
return TimeGroupingDetails(
field=f'FORMAT_DATE("%Y%W", {time_column}) as day',
field=f'FORMAT_DATE("%Y%W", {time_column.value}) as day',
formula='PARSE_DATE("%Y%W", day) as day',
separator=',',
)

if query.time_periods == BillingTimePeriods.MONTH:
return TimeGroupingDetails(
field=f'FORMAT_DATE("%Y%m", {time_column}) as day',
field=f'FORMAT_DATE("%Y%m", {time_column.value}) as day',
formula='PARSE_DATE("%Y%m", day) as day',
separator=',',
)
Expand Down
19 changes: 10 additions & 9 deletions scripts/create_test_subset.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def transfer_samples_sgs_assays(
type=sample_type or None,
meta=(copy_files_in_dict(s['meta'], project) or {}),
participant_id=existing_pid,
sequencing_groups=upsert_sequencing_groups(s, existing_data),
sequencing_groups=upsert_sequencing_groups(s, existing_data, project),
id=existing_sid,
)

Expand All @@ -289,7 +289,7 @@ def transfer_samples_sgs_assays(


def upsert_sequencing_groups(
sample: dict, existing_data: dict
sample: dict, existing_data: dict, project: str
) -> list[SequencingGroupUpsert]:
"""Create SG Upsert Objects for a sample"""
sgs_to_upsert: list[SequencingGroupUpsert] = []
Expand All @@ -306,7 +306,7 @@ def upsert_sequencing_groups(
technology=sg.get('technology'),
type=sg.get('type'),
assays=upsert_assays(
sg, existing_sgid, existing_data, sample.get('externalId')
sg, existing_sgid, existing_data, sample.get('externalId'), project
),
)
sgs_to_upsert.append(sg_upsert)
Expand All @@ -315,7 +315,11 @@ def upsert_sequencing_groups(


def upsert_assays(
sg: dict, existing_sgid: str | None, existing_data: dict, sample_external_id
sg: dict,
existing_sgid: str | None,
existing_data: dict,
sample_external_id,
project: str,
) -> list[AssayUpsert]:
"""Create Assay Upsert Objects for a sequencing group"""
print(sg)
Expand All @@ -325,17 +329,14 @@ def upsert_assays(
# Check if assay exists
if existing_sgid:
_existing_assay = get_existing_assay(
existing_data,
sample_external_id,
existing_sgid,
assay
existing_data, sample_external_id, existing_sgid, assay
)
existing_assay_id = _existing_assay.get('id') if _existing_assay else None
assay_upsert = AssayUpsert(
type=assay.get('type'),
id=existing_assay_id,
external_ids=assay.get('externalIds') or {},
meta=assay.get('meta'),
meta=copy_files_in_dict(assay.get('meta'), project),
)

assays_to_upsert.append(assay_upsert)
Expand Down

0 comments on commit c8ce4e2

Please sign in to comment.