Skip to content

Commit 164d1f9

Browse files
committed
🛠️ models.py -> Modified GeographicScope model with a TODO comment.
🛠️ models.py -> Added return type annotations to example_url and has_all_demographic_scopes methods. 🛠️ resources.py -> Modified SignalResource with additional fields like format_type, reporting_cadence, demographic_scope, severenity_pyramid_rungs, data_censoring, missingness, gender_breakdown, race_breakdown, and age_breakdown. 🛠️ resources.py -> Updated SignalResource with processing demographic scope in the pre-process method.
1 parent 4d78314 commit 164d1f9

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

src/signals/models.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def __str__(self) -> str:
168168
return str(self.name)
169169

170170

171-
class GeographicScope(TimeStampedModel):
171+
class GeographicScope(TimeStampedModel): # TODO: Requirements for this model are not clear. Need to be discussed.
172172
"""
173173
A model representing a geographic scope.
174174
"""
@@ -409,6 +409,9 @@ class Signal(TimeStampedModel):
409409
def example_url(self) -> str | None:
410410
"""
411411
Returns the example URL of the signal.
412+
413+
:return: The example URL of the signal.
414+
:rtype: str | None
412415
"""
413416
example_url = self.links.filter(link_type="example_url").first()
414417
return example_url.url if example_url else None
@@ -417,6 +420,9 @@ def example_url(self) -> str | None:
417420
def has_all_demographic_scopes(self) -> bool:
418421
"""
419422
Returns True if the signal has all demographic scopes, False otherwise.
423+
424+
:return: True if the signal has all demographic scopes, False otherwise.
425+
:rtype: bool
420426
"""
421427
return self.demographic_scope.count() == DemographicScope.objects.count()
422428

src/signals/resources.py

+42-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from base.models import Link, LinkTypeChoices
99
from datasources.models import SourceSubdivision
1010
from signals.models import (
11+
DemographicScope,
1112
Geography,
1213
Pathogen,
1314
Signal,
@@ -72,9 +73,13 @@ class SignalResource(resources.ModelResource):
7273
active = Field(attribute='active', column_name='Active')
7374
short_description = Field(attribute='short_description', column_name='Short Description')
7475
description = Field(attribute='description', column_name='Description')
75-
format = Field(attribute='format', column_name='Format')
76+
format_type = Field(attribute='format_type', column_name='Format')
7677
time_type = Field(attribute='time_type', column_name='Time Type')
7778
time_label = Field(attribute='time_label', column_name='Time Label')
79+
reporting_cadence = Field(attribute='reporting_cadence', column_name='Reporting Cadence')
80+
demographic_scope = Field(attribute='demographic_scope', column_name='Demographic Scope')
81+
severenity_pyramid_rungs = Field(attribute='severenity_pyramid_rungs', column_name='Severity Pyramid Rungs')
82+
7883
category = Field(
7984
attribute='category',
8085
column_name='Category',
@@ -101,6 +106,11 @@ class SignalResource(resources.ModelResource):
101106
column_name='Links',
102107
widget=widgets.ManyToManyWidget(Link, field='url', separator='|'),
103108
)
109+
data_censoring = Field(attribute='data_censoring', column_name='Data Censoring')
110+
missingness = Field(attribute='missingness', column_name='Missingness')
111+
gender_breakdown = Field(attribute='gender_breakdown', column_name='Gender Breakdown')
112+
race_breakdown = Field(attribute='race_breakdown', column_name='Race Breakdown')
113+
age_breakdown = Field(attribute='age_breakdown', column_name='Age Breakdown')
104114

105115
class Meta:
106116
model = Signal
@@ -112,9 +122,12 @@ class Meta:
112122
'active',
113123
'short_description',
114124
'description',
115-
'format',
125+
'format_type',
116126
'time_type',
117127
'time_label',
128+
'reporting_cadence',
129+
'demographic_scope',
130+
'severenity_pyramid_rungs',
118131
'available_geography',
119132
'is_smoothed',
120133
'is_weighted',
@@ -123,7 +136,12 @@ class Meta:
123136
'has_sample_size',
124137
'high_values_are',
125138
'source',
126-
'links'
139+
'links',
140+
'data_censoring',
141+
'missingness',
142+
'gender_breakdown',
143+
'race_breakdown',
144+
'age_breakdown',
127145
]
128146
import_id_fields: list[str] = ['name', 'source', 'display_name']
129147

@@ -132,9 +150,19 @@ def before_import_row(self, row, **kwargs) -> None:
132150
Pre-processes each row before importing.
133151
"""
134152

135-
self.fix_boolean_fields(row, ['Active', 'Is Smoothed', 'Is Weighted', 'Is Cumulative', 'Has StdErr', 'Has Sample Size'])
153+
self.fix_boolean_fields(row, [
154+
'Active',
155+
'Is Smoothed',
156+
'Is Weighted',
157+
'Is Cumulative',
158+
'Has StdErr',
159+
'Has Sample Size',
160+
'gender_breakdown',
161+
'race_breakdown',
162+
])
136163
self.process_links(row)
137164
self.process_pathogen(row)
165+
self.process_demographic_scope(row)
138166

139167
def is_url_in_domain(self, url, domain) -> Any:
140168
"""
@@ -193,3 +221,13 @@ def process_pathogen(self, row) -> None:
193221
pathogens: str = row['Pathogen/ Disease Area'].split(',')
194222
for pathogen in pathogens:
195223
Pathogen.objects.get_or_create(name=pathogen.strip())
224+
225+
def process_demographic_scope(self, row) -> None:
226+
"""
227+
Processes demographic scope.
228+
"""
229+
230+
if row['Demographic Scope']:
231+
demographic_scopes: str = row['Demographic Scope'].split(',')
232+
for demographic_scope in demographic_scopes:
233+
DemographicScope.objects.get_or_create(name=demographic_scope.strip())

0 commit comments

Comments
 (0)