Skip to content

Commit

Permalink
Remove code related to scenario active flag import/export (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
soininen authored May 13, 2024
2 parents f146f6a + 52735e4 commit b6b31ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 3 additions & 3 deletions spine_items/exporter/mvcmodels/mapping_editor_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
ParameterValueTypeMapping,
DimensionMapping,
ElementMapping,
ScenarioActiveFlagMapping,
ScenarioAlternativeMapping,
ScenarioBeforeAlternativeMapping,
ScenarioDescriptionMapping,
Expand Down Expand Up @@ -380,7 +379,9 @@ def _is_non_leaf_pivoted(self):
Returns:
bool: True if one or more non-leaf mappings are pivoted, False otherwise
"""
return any(is_pivoted(m.position) for m in self._mappings[: value_index(self._mappings)])
return len(self._mappings) > 1 and any(
is_pivoted(m.position) for m in self._mappings[: value_index(self._mappings)]
)

def can_compact(self):
"""Checks if the mapping can be compacted.
Expand Down Expand Up @@ -446,7 +447,6 @@ def compact(self):
ParameterValueMapping: "Parameter values",
ParameterValueTypeMapping: "Value types",
DimensionMapping: "Dimensions",
ScenarioActiveFlagMapping: "Active flags",
ScenarioAlternativeMapping: "Alternatives",
ScenarioBeforeAlternativeMapping: "Before alternatives",
ScenarioDescriptionMapping: "Scenarios description",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ def _new_mapping_specification(mapping_type):
if mapping_type == MappingType.scenario_alternatives:
return MappingSpecification(mapping_type, True, True, NoGroup.NAME, False, scenario_alternative_export(0, 1))
if mapping_type == MappingType.scenarios:
return MappingSpecification(mapping_type, True, True, NoGroup.NAME, False, scenario_export(0, 1))
return MappingSpecification(mapping_type, True, True, NoGroup.NAME, False, scenario_export(0))
raise NotImplementedError()


Expand Down
11 changes: 6 additions & 5 deletions spine_items/importer/flattened_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def display_position_type(self, row):
Returns:
str: display position
"""
if self._components[0].is_pivoted() and row == len(self._display_names) - 1:
if self._is_component_pivoted(row):
return "Pivoted"
component = self._components[self._display_to_logical[row]]
if component.position == Position.hidden:
Expand All @@ -312,6 +312,9 @@ def display_position_type(self, row):
return "Column"
return "Row"

def _is_component_pivoted(self, row):
return len(self._components) > 1 and self._components[0].is_pivoted() and row == len(self._display_names) - 1

def set_display_position_type(self, row, position_type):
"""Sets component's position 'type'.
Expand Down Expand Up @@ -353,7 +356,7 @@ def display_position(self, row):
"""
component = self._components[self._display_to_logical[row]]
# A) Handle two special cases for value mappings
if self._components[0].is_pivoted() and row == len(self._display_names) - 1:
if self._is_component_pivoted(row):
# 1. Pivoted data
return "Pivoted values"
if self._display_names[row].endswith("values"):
Expand All @@ -364,10 +367,8 @@ def display_position(self, row):
return SpineDBManager.display_data_from_parsed(value)
except ParameterValueFormatError:
return None
# B) Handle all other cases cases
# B) Handle all other cases
if component.position == Position.hidden:
if self._display_names[row].endswith("flags") and not isinstance(component.value, bool):
return string_to_bool(str(component.value))
return component.value
if component.position == Position.header:
if component.value is None:
Expand Down
3 changes: 2 additions & 1 deletion spine_items/importer/mvcmodels/mappings_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ def _mapping_flags(flattened_item, index):
return non_editable
if flattened_item.root_mapping.is_pivoted():
# special case where we have pivoted data
if index.row() == len(flattened_item.display_names) - 1:
row = index.row()
if row > 0 and row == len(flattened_item.display_names) - 1:
return non_editable
if column == FlattenedColumn.POSITION:
component = flattened_item.component_at(index.row())
Expand Down

0 comments on commit b6b31ff

Please sign in to comment.