Commit 318ff115 authored by Bruno Duyé's avatar Bruno Duyé

convert: adapt code to "non-cutted" datasets

parent 16f3a180
......@@ -157,7 +157,11 @@ def treat_dataset(dataset_dict, appendix_path):
current_series_code = None
current_observations_file = None
for observation_dict in observations_source_json["Data"]:
series_code = observation_dict["SeriesCode"] + '-' + dataset_source_file_info["dimension_value_code"]
if "dimension_code" in dataset_dict:
# There's a "cut" on a dimension
series_code = observation_dict["SeriesCode"] + '-' + dataset_source_file_info["dimension_value_code"]
else:
series_code = observation_dict["SeriesCode"]
if current_series_code and series_code != current_series_code or current_series_code is None:
# This is the beginning of a new series
log.debug(" - series {!r}".format(series_code))
......@@ -165,14 +169,14 @@ def treat_dataset(dataset_dict, appendix_path):
# This is the end of a series (so, not the beginning of the first one)
current_observations_file.close()
# Do the dimensional stuff
dataset_dimension_code = dataset_dict["dimension_code"]
dataset_dimension_value_code = dataset_source_file_info["dimension_value_code"]
dimensions = {}
if "dimension_code" in dataset_dict:
dataset_dimension_code = dataset_dict["dimension_code"]
dataset_dimension_value_code = dataset_source_file_info["dimension_value_code"]
dimensions[dataset_dimension_code] = dataset_dimension_value_code # Ex: 'FREQ': 'Q'
# dimensions_values_labels[dataset_dimension_code][dataset_dimension_value_code] = DIMENSIONS_VALUES_LABELS[dataset_dimension_code][dataset_dimension_value_code]
concept_code = slugify(observation_dict["LineDescription"])
dimensions = {
dataset_dimension_code: dataset_dimension_value_code, # Ex: 'FREQ': 'Q'
"concept": concept_code,
}
dimensions_values_labels[dataset_dimension_code][dataset_dimension_value_code] = DIMENSIONS_VALUES_LABELS[dataset_dimension_code][dataset_dimension_value_code]
dimensions["concept"] = concept_code
dimensions_values_labels['concept'][concept_code] = observation_dict["LineDescription"]
dataset_json_series_list.append({
'code': series_code,
......@@ -192,17 +196,20 @@ def treat_dataset(dataset_dict, appendix_path):
current_observations_file.write(observation_dict["TimePeriod"] + "\t" + observation_value_str + "\n")
# Write dataset.json
write_json_file(os.path.join(target_dataset_path, "dataset.json"), {
dataset_json = {
'code': dataset_code,
'name': dataset_name,
'series': dataset_json_series_list,
'dimensions_codes_order': [dataset_dict["dimension_code"], 'concept'],
'dimensions_labels': {
dataset_dict["dimension_code"]: dataset_dict["dimension_label"],
'concept': 'Concept',
},
'dimensions_values_labels': dimensions_values_labels,
})
}
if "dimension_code" in dataset_dict:
# "cut" in dataset on a dimension
dataset_json['dimensions_codes_order'] = [dataset_dict["dimension_code"], 'concept']
dataset_json['dimensions_labels'][dataset_dict["dimension_code"]] = dataset_dict["dimension_label"]
write_json_file(os.path.join(target_dataset_path, "dataset.json"), dataset_json)
return dataset_code, dataset_name
......
Markdown is supported
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