Skip to content
Snippets Groups Projects
Commit 1e54094d authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Normalize time series names

parent 0347af2a
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,9 @@ YEAR_RE = re.compile(r'^([12]\d{3})$')
MONTH_RE = re.compile(r'^([12]\d{3})-([01]\d)$')
DAY_RE = re.compile(r'^([12]\d{3})-([01]\d)-([0-3]\d)$')
# Helps normalize space
NORM_SPACES_RE = re.compile(r'\s+')
def write_series_file(file_path: Path, periods, observations, obs_status=None):
""" write series tsv file from period and value list """
......@@ -62,6 +65,15 @@ def write_series_file(file_path: Path, periods, observations, obs_status=None):
fd.write('{}\n'.format('\t'.join(tup)))
def norm_space(str_value):
""" Converts ' abc de f ' into 'abc de f'
>>> norm_space(" ab\tc de f ")
'ab c de f'
"""
return NORM_SPACES_RE.sub(' ', str_value).strip()
def norm_period(period_str, freq):
"""Normalize period respecting frequency value
......@@ -120,7 +132,7 @@ def load_series_xml_file(xml_file: Path):
if elt.tag == SERIES_TAG:
info['code'] = elt.attrib['BBK_ID']
name_attr = 'BBK_TITLE_ENG' if 'BBK_TITLE_ENG' in elt.attrib else 'BBK_TITLE'
info['name'] = elt.attrib[name_attr]
info['name'] = norm_space(elt.attrib[name_attr])
info['freq'] = elt.attrib['FREQ']
info['periods'] = []
info['obs'] = []
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment