Skip to content

Commit 098c2bd

Browse files
committed
๐Ÿ› ๏ธ models.py -> Added choices for demographic disaggregation.
๐Ÿ› ๏ธ models.py -> Added models for geographic and demographic scope. ๐Ÿ› ๏ธ models.py -> Added models for organisations access and sharing. ๐Ÿ› ๏ธ models.py -> Added fields for reporting cadence, demographic scope, demographic disaggregation, data censoring, missingness, organisations access list, and organisations sharing list. ๐Ÿ› ๏ธ tasks.py -> Added error handling for HTTP response in get_covidcast_meta function.
1 parent 09d03dc commit 098c2bd

File tree

2 files changed

+105
-2
lines changed

2 files changed

+105
-2
lines changed

โ€Žsrc/signals/models.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class ActiveChoices(models.TextChoices):
5757
HISTORICAL = False, _('Historical')
5858

5959

60+
class DemograohicDisaggregation(models.TextChoices):
61+
"""
62+
A class representing choices for demographic disaggregation.
63+
"""
64+
pass # TODO: Add choices for demographic disaggregation or split into separate classes if needed. Should be discussed.
65+
66+
6067
class SignalCategory(TimeStampedModel):
6168
"""
6269
A model representing a signal category.
@@ -145,6 +152,66 @@ def __str__(self) -> str:
145152
return str(self.name)
146153

147154

155+
class GeographicScope(TimeStampedModel): # TODO: Requirements for this model are not clear. Need to be discussed.
156+
"""
157+
A model representing a geographic scope.
158+
"""
159+
name: models.CharField = models.CharField(
160+
help_text=_('Name'),
161+
max_length=128,
162+
unique=True
163+
)
164+
165+
def __str__(self) -> str:
166+
"""
167+
Returns the name of the geographic scope as a string.
168+
169+
:return: The name of the geographic scope as a string.
170+
:rtype: str
171+
"""
172+
return str(self.name)
173+
174+
175+
class DemograficScope(TimeStampedModel):
176+
"""
177+
A model representing a demographic scope.
178+
"""
179+
name: models.CharField = models.CharField(
180+
help_text=_('Name'),
181+
max_length=128,
182+
unique=True
183+
)
184+
185+
def __str__(self) -> str:
186+
"""
187+
Returns the name of the demographic scope as a string.
188+
189+
:return: The name of the demographic scope as a string.
190+
:rtype: str
191+
"""
192+
return str(self.name)
193+
194+
195+
class OrganisationsAccess(TimeStampedModel): # TODO: Requirements for this model are not clear. Need to be discussed.
196+
"""
197+
A model representing an access list.
198+
"""
199+
organisation_name: models.CharField = models.CharField(
200+
help_text=_('Organisation Name'),
201+
max_length=128,
202+
)
203+
204+
205+
class SharingOrganisation(TimeStampedModel): # TODO: Requirements for this model are not clear. Need to be discussed.
206+
"""
207+
A model representing a sharing organisation.
208+
"""
209+
organisation_name: models.CharField = models.CharField(
210+
help_text=_('Organisation Name'),
211+
max_length=128,
212+
)
213+
214+
148215
class Signal(TimeStampedModel):
149216
"""
150217
A model representing a signal.
@@ -206,6 +273,21 @@ class Signal(TimeStampedModel):
206273
max_length=128,
207274
choices=TimeLabelChoices.choices
208275
)
276+
reporting_cadence: models.CharField = models.CharField(
277+
help_text=_('Reporting Cadence'),
278+
max_length=128,
279+
choices=ReportingCadence.choices
280+
)
281+
demographic_scope: models.ManyToManyField = models.ManyToManyField(
282+
'signals.DemograficScope',
283+
related_name='signals',
284+
help_text=_('Demographic Scope')
285+
)
286+
demographic_disaggregation: models.CharField = models.CharField( # TODO: Choices for this field are not clear. Need to be discussed.
287+
help_text=_('Demographic Disaggregation'),
288+
max_length=128,
289+
choices=DemograohicDisaggregation.choices
290+
)
209291
category: models.ForeignKey = models.ForeignKey(
210292
'signals.SignalCategory',
211293
related_name='signals',
@@ -253,6 +335,26 @@ class Signal(TimeStampedModel):
253335
help_text=_('Source Subdivision'),
254336
on_delete=models.PROTECT,
255337
)
338+
data_censoring: models.TextField = models.TextField(
339+
help_text=_('Data Censoring'),
340+
null=True,
341+
blank=True
342+
)
343+
missingness: models.TextField = models.TextField(
344+
help_text=_('Missingness'),
345+
null=True,
346+
blank=True
347+
)
348+
organisations_access_list: models.ManyToManyField = models.ManyToManyField( # TODO: Requirements for this field are not clear. Need to be discussed.
349+
'signals.OrganisationsAccess',
350+
help_text=_('Organisations Access List')
351+
)
352+
353+
organisations_sharing_list: models.ManyToManyField = models.ManyToManyField( # TODO: Requirements for this field are not clear. Need to be discussed.
354+
'signals.SharingOrganisation',
355+
help_text=_('Organisations Sharing List')
356+
)
357+
256358
last_updated: models.DateField = models.DateField(
257359
help_text=_('Last Updated'),
258360
null=True,

โ€Žsrc/signals/tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33

44
import requests
5+
from rest_framework.status import is_client_error, is_server_error
56

67
from signal_documentation.celery import BaseTaskWithRetry, app
78
from signals.tools import SignalLastUpdatedParser
@@ -12,8 +13,8 @@
1213
@app.task(bind=BaseTaskWithRetry)
1314
def get_covidcast_meta(self):
1415
response = requests.get(COVID_CAST_META_URL, timeout=5)
15-
if response is None:
16-
return f'Not response, url {COVID_CAST_META_URL}'
16+
if is_client_error(response.status_code) or is_server_error(response.status_code):
17+
return f'{COVID_CAST_META_URL}. Error: {response.status_code} - {response.content}'
1718

1819
if response.status_code == 200:
1920
parser = SignalLastUpdatedParser(covidcast_meta_data=json.loads(response.content))

0 commit comments

Comments
ย (0)