Commit 1183c95c authored by Christophe Benz's avatar Christophe Benz
Browse files

Reformat files

parent 907891d0
Pipeline #223551 passed with stage
in 1 minute and 46 seconds
......@@ -77,10 +77,10 @@ def generate_tsv_from_csv_data_line(csv_code, csv_name, cols, ds_dir):
def compute_freq_and_code(period_value):
""" 2017CY -> ('A', 'CY')
2017FY -> ('A', 'FY')
2017Q1 -> ('Q', 'Q')
201701 -> ('M', 'M')
"""2017CY -> ('A', 'CY')
2017FY -> ('A', 'FY')
2017Q1 -> ('Q', 'Q')
201701 -> ('M', 'M')
"""
assert len(period_value) == 6, period_value
suff = period_value[4:]
......@@ -96,9 +96,9 @@ def compute_freq_and_code(period_value):
def norm_period_values(period_values, freq):
"""
2007CY, ... 2017CY -> 2007, ... 2017
2007FY, ... 2017FY -> 2007, ... 2017
2007Q1, ... 2017Q4 -> 2007-Q1, ... 2017-Q4
2007CY, ... 2017CY -> 2007, ... 2017
2007FY, ... 2017FY -> 2007, ... 2017
2007Q1, ... 2017Q4 -> 2007-Q1, ... 2017-Q4
"""
# sanitize period_values (trim 'p ' at the beginning of the period value)
period_values = [p.lstrip("p ") for p in period_values]
......@@ -203,8 +203,8 @@ class CSVLineHelper:
def extract_concept(csv_name):
""" extract 'IP' (Industrial production) from
'Seasonally adjusted Index by Industry : Industrial Production (2010=100.0)' """
"""extract 'IP' (Industrial production) from
'Seasonally adjusted Index by Industry : Industrial Production (2010=100.0)'"""
idx = csv_name.find(":")
assert idx != -1, "No «:» found in [{}]".format(csv_name)
......@@ -223,9 +223,9 @@ def extract_timeseries_from_csv(
csv_code, csv_filepath: Path, ds_dir: Path, with_concept=False
):
"""
Extracts time series from csv_filepath
Generates tsv files
Returns time series info to write dataset.json
Extracts time series from csv_filepath
Generates tsv files
Returns time series info to write dataset.json
"""
series_info = []
with csv_filepath.open("rt", encoding="ascii") as csv_fd:
......@@ -273,9 +273,9 @@ def generate_dataset(
ds_code, source_dir: Path, ds_name, target_dir: Path, with_concept=False
):
"""
creates dataset_dir
generates time series tsv files
generates dataset.json
creates dataset_dir
generates time series tsv files
generates dataset.json
"""
log.info("Generating dataset [%s]", ds_code)
......@@ -310,10 +310,20 @@ def write_dataset_json(
"seasonal_adjustment": "Seasonal adjustment",
},
"dimensions_values_labels": {
"frequency": {"A": "Annual", "Q": "Quarterly", "M": "Monthly",},
"seasonal_adjustment": {"S": "Seasonaly adjusted", "O": "Original",},
"frequency": {
"A": "Annual",
"Q": "Quarterly",
"M": "Monthly",
},
"seasonal_adjustment": {
"S": "Seasonaly adjusted",
"O": "Original",
},
},
"dimensions_codes_order": ["frequency", "seasonal_adjustment",],
"dimensions_codes_order": [
"frequency",
"seasonal_adjustment",
],
"series": [],
}
......@@ -336,8 +346,8 @@ def write_dataset_json(
def clean_csv_files(source_dir: Path):
""" Fix CSV files found in given source_dir and store fixed versions in temp directory
return temp directory path """
"""Fix CSV files found in given source_dir and store fixed versions in temp directory
return temp directory path"""
import tempfile
temp_dir = Path(tempfile.mkdtemp(prefix="sanzi"))
......
......@@ -48,7 +48,10 @@ def write_dataset_json_file(file_path, dataset_info, datasets_info):
def compute_series_info(series_info):
""" Computes series info """
data = dict(code=series_info[0], name=series_info[1],)
data = dict(
code=series_info[0],
name=series_info[1],
)
if series_info[2]:
data["dimensions"] = series_info[2]
if len(series_info) == 4:
......
Supports Markdown
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