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

Allow Open SDG to skip certain indicators #357

Draft
wants to merge 2 commits into
base: 2.4.0-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions sdg/inputs/InputBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, logging=None, column_map=None, code_map=None, request_params=
self.column_map = column_map
self.code_map = code_map
self.meta_suffix = meta_suffix
self.skip_indicators = []


def execute_once(self, indicator_options):
Expand Down Expand Up @@ -204,6 +205,8 @@ def add_indicator(self, indicator_id, name=None, data=None, meta=None, options=N
options : IndicatorOptions or None
The indicator options
"""
if indicator_id in self.skip_indicators:
return
data = self.alter_data(data, indicator_id=indicator_id)
meta = self.alter_meta(meta, indicator_id=indicator_id)
indicator = Indicator(indicator_id, name=name, data=data, meta=meta, options=options, logging=self.logging)
Expand Down Expand Up @@ -368,3 +371,15 @@ def apply_code_map(self, data):
except:
data.replace(to_replace=code_dict, inplace=True)
return data


def set_skip_indicators(self, indicator_ids):
"""Set this input to skip certain indicators.

Parameters
----------
indicator_ids : list
List of indicator IDs.
"""
if type(indicator_ids) is list:
self.skip_indicators = indicator_ids
14 changes: 12 additions & 2 deletions sdg/open_sdg.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def open_sdg_build(src_dir='', site_dir='_site', schema_file='_prose.yml',
logging=None, indicator_export_filename='all_indicators',
datapackage=None, csvw=None, data_schema=None, docs_metadata_fields=None,
alter_indicator=None, indicator_callback=None,
ignore_out_of_scope_disaggregation_stats=False):
ignore_out_of_scope_disaggregation_stats=False, skip_indicators=None):
"""Read each input file and edge file and write out json.

Args:
Expand Down Expand Up @@ -90,6 +90,7 @@ def open_sdg_build(src_dir='', site_dir='_site', schema_file='_prose.yml',
the MetadataReportService class.
ignore_out_of_scope_disaggregation_stats: boolean. Whether to omit the
not-applicable disaggregation stats.
skip_indicators: list. A list of indicator IDs to skip/ignore.

Returns:
Boolean status of file writes
Expand Down Expand Up @@ -136,6 +137,7 @@ def open_sdg_build(src_dir='', site_dir='_site', schema_file='_prose.yml',
'indicator_export_filename': indicator_export_filename,
'docs_metadata_fields': docs_metadata_fields,
'ignore_out_of_scope_disaggregation_stats': ignore_out_of_scope_disaggregation_stats,
'skip_indicators': skip_indicators
}
# Allow for a config file to update these.
options = open_sdg_config(config, defaults)
Expand Down Expand Up @@ -238,7 +240,8 @@ def open_sdg_indicator_options_from_dict(options):

def open_sdg_check(src_dir='', schema_file='_prose.yml', config='open_sdg_config.yml',
inputs=None, alter_data=None, alter_meta=None, indicator_options=None,
data_schema=None, schema=None, logging=None, alter_indicator=None):
data_schema=None, schema=None, logging=None, alter_indicator=None,
skip_indicators=None):
"""Run validation checks for all indicators.

This checks both *.csv (data) and *.md (metadata) files.
Expand All @@ -256,6 +259,7 @@ def open_sdg_check(src_dir='', schema_file='_prose.yml', config='open_sdg_config
alter_indicator: function. A callback function that alters the full Indicator objects (for each output)
data_schema: dict . Dict describing an instance of DataSchemaInputBase
logging: Noneor list. Type of logs to print, including 'warn' and 'debug'
skip_indicators: list. A list of indicator IDs to skip/ignore.

Returns:
boolean: True if the check was successful, False if not.
Expand Down Expand Up @@ -284,6 +288,7 @@ def open_sdg_check(src_dir='', schema_file='_prose.yml', config='open_sdg_config
'logging': logging,
'indicator_export_filename': None,
'ignore_out_of_scope_disaggregation_stats': False,
'skip_indicators': skip_indicators,
}
# Allow for a config file to update these.
options = open_sdg_config(config, defaults)
Expand Down Expand Up @@ -338,6 +343,11 @@ def open_sdg_prep(options):
for input in inputs:
input.add_meta_alteration(options['alter_meta'])

# Set the indicators to skip, if any.
if 'skip_indicators' in options and type(options['skip_indicators']) is list:
for input in inputs:
input.set_skip_indicators(options['skip_indicators'])

# Use the specified metadata schema.
schema = options['schema']

Expand Down
Loading