Commit cd8f04bb authored by Bruno Duyé's avatar Bruno Duyé

Make series name better + minor code comments

parent 1bf6a3ed
......@@ -154,17 +154,28 @@ def treat_dataset(dataset_dict, appendix_path, appendix_dict):
return series_code
def get_series_name(observation_dict, series_dimensions, dimensions_values_labels):
def get_series_name(observation_dict, series_dimensions, dimensions_values_labels, dataset_dict, dataset_source_file_info):
"""Get or compute series name"""
if 'LineDescription' in observation_dict:
return observation_dict['LineDescription']
if dataset_dict.get('dimension_code') == 'FREQ' and len(dataset_dict['files']) > 1:
return observation_dict['LineDescription'] + ' - ' + dimensions_values_labels['FREQ'][dataset_source_file_info["dimension_value_code"]]
return observation_dict['LineDescription']
return '-'.join(dimensions_values_labels[dimension_code][dimension_value_code]
for dimension_code, dimension_value_code in series_dimensions.items()
# Compute series name
if 'FREQ' in series_dimensions.keys():
# - make FREQ dimension to be at the end
ordered_series_dimensions = list((k,v) for k,v in series_dimensions.items() if k != 'FREQ')
if len(dataset_dict['files']) > 1:
# There's more than one Frequency, add freq value to the end of the name
ordered_series_dimensions.append(('FREQ', series_dimensions['FREQ']))
ordered_series_dimensions = tuple(series_dimensions.items())
return ' - '.join(dimensions_values_labels[dimension_code][dimension_value_code]
for dimension_code, dimension_value_code in ordered_series_dimensions
# prefix dataset_code with appendix_code because there's datasets names collisions between appendix
# Prefix dataset_code with appendix_code because there's datasets names collisions between appendix
dataset_code = appendix_dict['code'] + '-' + dataset_dict["dataset_code"]
log.debug('- Dataset {!r}'.format(dataset_code))
# Create dataset dir
......@@ -190,12 +201,12 @@ def treat_dataset(dataset_dict, appendix_path, appendix_dict):
# if current_series_code and series_code != current_series_code or current_series_code is None:
if not series_code in current_observations_files.keys():
# This is the beginning of a new series
# Init file
# - init file
observations_filename = find_available_name_for_series_file(series_code, target_dataset_path)
observations_filepath = os.path.join(target_dataset_path, observations_filename)
observations_file = open(observations_filepath, "w")
# Add this file to current_observations_files
# - add this file to current_observations_files
current_observations_files[series_code] = observations_file
# Do the dimensional stuff
series_dimensions = {}
......@@ -217,7 +228,7 @@ def treat_dataset(dataset_dict, appendix_path, appendix_dict):
# Add series information to future series list of dataset.json file
'code': series_code,
'name': get_series_name(observation_dict, series_dimensions, dimensions_values_labels),
'name': get_series_name(observation_dict, series_dimensions, dimensions_values_labels, dataset_dict, dataset_source_file_info),
'dimensions': series_dimensions
# # If this file is a duplicate of another (two series with same code), check that they're equals
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment