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

Improved logger strings with identifying information #899

Merged
merged 1 commit into from
Oct 13, 2023
Merged
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
69 changes: 45 additions & 24 deletions src/csvcubed/writers/helpers/qbwriter/urihelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ def get_unit_uri(self, unit: QbUnit) -> str:

def get_attribute_uri(self, attribute: QbAttribute) -> str:
if isinstance(attribute, NewQbAttribute):
_logger.debug("The attribute is a new attribute")
_logger.debug("The attribute %s is a new attribute", attribute.label)
attribute_uri = self._new_resource_uri_generator.get_attribute_uri(
attribute.uri_safe_identifier
)
_logger.debug(
"The attribute is a new attribute with uri '%s'",
"The attribute %s is a new attribute with uri '%s'",
attribute.label,
attribute_uri,
)
return attribute_uri
Expand All @@ -164,33 +165,35 @@ def get_about_url(self) -> str:
else self._get_observation_uri_for_standard_shape_data_set()
)

_logger.debug("About url template is %s", about_url_template)
_logger.debug("aboutUrl template is %s", about_url_template)
return about_url_template

def get_about_url_for_csvw_col_in_pivoted_shape_cube(
self, column: QbColumn
) -> Optional[str]:
obs_val_cols = self.cube.get_columns_of_dsd_type(QbObservationValue)
_logger.debug(
"Getting about url for column with title '%s'", column.csv_column_title
"Getting aboutUrl for column with title '%s'", column.csv_column_title
)

obs_val_col: Optional[QbColumn[QbObservationValue]]
# If the column represents a QbObservationValue, then simply assign the obs_val_column to this column.
if isinstance(column.structural_definition, QbObservationValue):
_logger.debug("Column is a observation value column")
_logger.debug(
"Column %s is a observation value column", column.csv_column_title
)
obs_val_col = column
elif isinstance(column.structural_definition, QbAttribute):
# If the column represents an attribute, set the valueUrl using the _get_observation_value_col_for_title
# function
_logger.debug("Column is a an attribute column")
_logger.debug("Column %s is an attribute column", column.csv_column_title)
col_title = column.structural_definition.get_observed_value_col_title()
obs_val_col = self._get_obs_val_col_described_by_csv_col(
col_title, obs_val_cols
)
# If the column represents units, set the valueUrl using the _get_observation_value_col_for_title function
elif isinstance(column.structural_definition, QbMultiUnits):
_logger.debug("Column is a a multi-units column")
_logger.debug("Column %s is a multi-units column", column.csv_column_title)
col_title = column.structural_definition.observed_value_col_title
obs_val_col = self._get_obs_val_col_described_by_csv_col(
col_title, obs_val_cols
Expand All @@ -214,24 +217,28 @@ def get_default_property_value_uris_for_column(
the column.
"""
_logger.debug(
"Getting default property value uris for column with title '%s'",
"Getting default propertyUrl and valueUrl for column with title '%s'",
column.csv_column_title,
)

if isinstance(column.structural_definition, QbDimension):
_logger.debug("Column is a dimension column")
_logger.debug("Column %s is a dimension column", column.csv_column_title)
return self._get_default_property_value_uris_for_dimension(column)
elif isinstance(column.structural_definition, QbAttribute):
_logger.debug("Column is an attribute column")
_logger.debug("Column %s is an attribute column", column.csv_column_title)
return self._get_default_property_value_uris_for_attribute(column)
elif isinstance(column.structural_definition, QbMultiUnits):
_logger.debug("Column is a multi-units column")
_logger.debug("Column %s is a multi-units column", column.csv_column_title)
return self._get_default_property_value_uris_for_multi_units(column)
elif isinstance(column.structural_definition, QbMultiMeasureDimension):
_logger.debug("Column is a multi-measure dimension column")
_logger.debug(
"Column %s is a multi-measure dimension column", column.csv_column_title
)
return self._get_default_property_value_uris_for_multi_measure(column)
elif isinstance(column.structural_definition, QbObservationValue):
_logger.debug("Column is an observation value column")
_logger.debug(
"Column %s is an observation value column", column.csv_column_title
)
return self._get_default_property_value_uris_for_observation_value(
column.structural_definition
)
Expand Down Expand Up @@ -266,7 +273,7 @@ def get_observation_uri_for_pivoted_shape_data_set(

obs_val_measure = obs_val_column.structural_definition.measure
assert obs_val_measure is not None
_logger.debug("Observation value column has a measure")
_logger.debug("Observation value column has a measure %s.", obs_val_measure)

if isinstance(obs_val_measure, NewQbMeasure):
measure_id = obs_val_measure.uri_safe_identifier
Expand Down Expand Up @@ -406,10 +413,10 @@ def _get_obs_val_col_described_by_csv_col(

if len(obs_val_cols) == 1:
# Only one obs val column so it's clear which one our column describes.
_logger.debug("The cube has a single obs val column.")
_logger.debug("The cube has a single obs val column %s.", obs_val_cols[0])
obs_val_col = obs_val_cols[0]
else:
_logger.debug("The cube has multiple obs val columns.")
_logger.debug("The cube has multiple obs val columns %s.", obs_val_cols)
if col_title is not None:
obs_val_col = self._get_observation_value_col_for_title(col_title)

Expand Down Expand Up @@ -483,11 +490,13 @@ def _get_default_property_value_uris_for_dimension(
value_uri = self._get_column_uri_template_fragment(column)
if dimension.code_list is None:
_logger.debug(
"Dimension does not have code list; valueUrl defaults directly to column's value."
"Dimension %s does not have code list; valueUrl defaults directly to column's value.",
dimension.label,
)
else:
_logger.debug(
"Dimension valueUrl determined by code list %s.",
"Dimension %s valueUrl determined by code list %s.",
dimension.label,
dimension.code_list,
)
value_uri = self._get_default_value_uri_for_code_list_concepts(
Expand All @@ -507,25 +516,31 @@ def _get_default_property_value_uris_for_attribute(
attribute_uri = self.get_attribute_uri(attribute)

if isinstance(attribute, ExistingQbAttribute):
_logger.debug("Existing Attribute does not have new attribute values.")
_logger.debug(
"Existing Attribute %s does not have new attribute values.",
column.csv_column_title,
)
return attribute_uri, value_uri
elif isinstance(attribute, NewQbAttribute):
if attribute.code_list is None:
_logger.debug(
"Attribute does not have a code list; valueUrl defaults directly to column value"
"New Attribute %s does not have a code list; valueUrl defaults directly to column value",
column.csv_column_title,
)
else:
if feature_flags.ATTRIBUTE_VALUE_CODELISTS:
_logger.debug(
"Attribute valueUrl determined by code list %s",
"Attribute %s valueUrl determined by code list %s",
column.csv_column_title,
attribute.code_list,
)
value_uri = self._get_default_value_uri_for_code_list_concepts(
column, attribute.code_list
)
else:
_logger.debug(
"New Attribute has new attribute values which define the valueUrl."
"New Attribute %s has new attribute values which define the valueUrl.",
column.csv_column_title,
)
value_uri = self.get_new_attribute_value_uri(
attribute.uri_safe_identifier, column_uri_fragment
Expand Down Expand Up @@ -594,7 +609,10 @@ def _get_unit_column_unit_template_uri(self, column: QbColumn[QbMultiUnits]):
)
unit_value_uri: str
if all_units_new:
_logger.debug("All units are new; they define the column's valueUrl.")
_logger.debug(
"All units are new; they define the %s column's valueUrl.",
column.csv_column_title,
)
unit_value_uri = self._new_resource_uri_generator.get_unit_uri(
column_template_fragment
)
Expand Down Expand Up @@ -623,7 +641,10 @@ def _get_measure_dimension_column_measure_template_uri(

column_template_fragment = self._get_column_uri_template_fragment(column)
if all_measures_new:
_logger.debug("All measures are new; they define the column's valueUrl.")
_logger.debug(
"All measures are new; they define the %s column's valueUrl.",
column.csv_column_title,
)
return self._new_resource_uri_generator.get_measure_uri(
column_template_fragment
)
Expand Down
29 changes: 19 additions & 10 deletions src/csvcubed/writers/qbwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,9 @@ def _generate_virtual_columns_for_obs_val_in_pivoted_shape_cube(

if dimension_col.csv_column_uri_template is not None:
_logger.debug(
"Dimension column with title '%s'has a csv column uri template defined",
"Dimension column with title '%s'has a csv column uri template '%s' defined",
dimension_col.csv_column_title,
dimension_col.csv_column_uri_template,
)
value_url = dimension_col.csv_column_uri_template

Expand Down Expand Up @@ -399,7 +400,7 @@ def _generate_virtual_columns_for_obs_val_in_standard_shape_cube(
]
unit = obs_val.unit
if unit is not None:
_logger.debug("Adding virtual unit column.")
_logger.debug("Adding virtual unit column for '%s'.", unit)
virtual_columns.append(
{
"name": VIRT_UNIT_COLUMN_NAME,
Expand Down Expand Up @@ -451,9 +452,9 @@ def _define_csvw_column_for_qb_column(
column
)
_logger.debug(
"About url for column with tile '%s' is '%s'",
about_url,
"aboutUrl for column with title '%s' is '%s'",
column.csv_column_title,
about_url,
)
if about_url is not None:
csvw_col["aboutUrl"] = about_url
Expand All @@ -464,7 +465,8 @@ def _define_csvw_column_for_qb_column(
) = self._uris.get_default_property_value_uris_for_column(column)

_logger.debug(
"Column has default propertyUrl '%s' and default valueUrl '%s'.",
"Column '%s' has default propertyUrl '%s' and default valueUrl '%s'.",
column.csv_column_title,
property_url,
default_value_url,
)
Expand All @@ -476,26 +478,33 @@ def _define_csvw_column_for_qb_column(
# User-specified value overrides our default guess.
csvw_col["valueUrl"] = column.csv_column_uri_template
elif isinstance(column.structural_definition, QbAttributeLiteral):
_logger.debug("Column is Attribute Literal; valueUrl is left unset.")
_logger.debug(
"Column '%s' is Attribute Literal; valueUrl is left unset.",
column.csv_column_title,
)
elif default_value_url is not None:
csvw_col["valueUrl"] = default_value_url

if isinstance(column.structural_definition, QbObservationValue):
_logger.debug(
"Setting CSV-W datatype to %s.", column.structural_definition.data_type
"Setting CSV-W datatype for %s to %s.",
column.csv_column_title,
column.structural_definition.data_type,
)
csvw_col["datatype"] = column.structural_definition.data_type
elif isinstance(column.structural_definition, QbAttributeLiteral):
_logger.debug(
"Setting CSV-W datatype to %s.", column.structural_definition.data_type
"Setting CSV-W datatype for %s to %s.",
column.csv_column_title,
column.structural_definition.data_type,
)
csvw_col["datatype"] = column.structural_definition.data_type

is_required = self._determine_whether_column_is_required(column)
if is_required:
_logger.debug("Column is required.")
_logger.debug("Column %s is required.", column.csv_column_title)
else:
_logger.debug("Column is not required.")
_logger.debug("Column %s is not required.", column.csv_column_title)

csvw_col["required"] = is_required

Expand Down
2 changes: 1 addition & 1 deletion src/csvcubed/writers/skoscodelistwriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _get_csvw_table_schema(self) -> dict:
self.new_code_list, CompositeQbCodeList
) or self.has_duplicated_qb_concepts(self.new_code_list):
_logger.debug(
"Code list is composite has a duplicated concept. Linking to original concept URIs."
"Code list is composite and has duplicated concepts. Linking to original concept URIs."
)

csvw_columns.append(
Expand Down
Loading