Skip to content

Commit 0db546a

Browse files
authored
Merge pull request #80 from broadinstitute/db-add-age-in-seconds
adding normalized seconds column to convention metadata export
2 parents 64572f3 + 3d70bf1 commit 0db546a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ __pycache__/
88
# Ignore editor configuration
99
.idea/
1010
.vscode/
11+
*.sublime-project
12+
*.sublime-workspace
1113

1214
# Ignore other detritus
1315
*.log
@@ -16,3 +18,6 @@ __pycache__/
1618
coverage.xml
1719
issues.json
1820
htmlcov/
21+
22+
errors.txt
23+
info.txt

ingest/validation/validate_metadata.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,31 @@ def serialize_bq(bq_dict, filename='bq.json'):
773773
"""Write metadata collected for validation to json file
774774
BigQuery requires newline delimited json objects
775775
"""
776-
data = json.dumps(bq_dict)
776+
bq_dict_copy = bq_dict.copy()
777+
if ('organism_age' in bq_dict and 'organism_age__unit_label' in bq_dict):
778+
bq_dict_copy['organism_age__seconds'] = calculate_organism_age_in_seconds(bq_dict['organism_age'], bq_dict['organism_age__unit_label'])
779+
780+
data = json.dumps(bq_dict_copy)
777781
with open(filename, 'a') as jsonfile:
778782
jsonfile.write(data + '\n')
779783

780784

785+
def calculate_organism_age_in_seconds(organism_age, organism_age_unit_label):
786+
multipliers = {
787+
'microsecond': 0.000001,
788+
'millisecond': 0.001,
789+
'second': 1,
790+
'minute': 60,
791+
'hour': 3600,
792+
'day': 86400,
793+
'week': 604800,
794+
'month': 2626560, #(day * 30.4 to fuzzy-account for different months)
795+
'year': 31557600 # (day * 365.25 to fuzzy-account for leap-years)
796+
}
797+
multiplier = multipliers[organism_age_unit_label]
798+
return organism_age * multiplier
799+
800+
781801
def serialize_issues(metadata):
782802
"""Write collected issues to json file
783803
"""

0 commit comments

Comments
 (0)