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

Extend data processor and allow data type override. #1161

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions tom_dataproducts/data_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
DEFAULT_DATA_PROCESSOR_CLASS = 'tom_dataproducts.data_processor.DataProcessor'


def run_data_processor(dp):
def run_data_processor(dp, dp_type_override=None):
"""
Reads the `data_product_type` from the dp parameter and imports the corresponding `DATA_PROCESSORS` specified in
`settings.py`, then runs `process_data` and inserts the returned values into the database.

:param dp: DataProduct which will be processed into a list
:type dp: DataProduct

:param dp_type_override: Optional. DataProduct type to override with. If None, the
type from the `dp` object is used.
:type dp_type_override: str, optional

:returns: QuerySet of `ReducedDatum` objects created by the `run_data_processor` call
:rtype: `QuerySet` of `ReducedDatum`
"""

data_type = dp_type_override or dp.data_product_type
try:
processor_class = settings.DATA_PROCESSORS[dp.data_product_type]
processor_class = settings.DATA_PROCESSORS[data_type]
except Exception:
processor_class = DEFAULT_DATA_PROCESSOR_CLASS

Expand All @@ -41,7 +45,7 @@ def run_data_processor(dp):
data_processor = clazz()
# data returned by process_data is a list of 3-tuples: (timestamp, datum, source)
data = data_processor.process_data(dp)
data_type = data_processor.data_type_override() or dp.data_product_type
data_type = data_processor.data_type_override() or data_type

# Add only the new (non-duplicate) ReducedDatum objects to the database

Expand Down