Skip to content

Commit 66a6ff1

Browse files
committed
Improve __repr__()
1 parent 75c05ee commit 66a6ff1

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

flixopt/structure.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -975,15 +975,23 @@ def __contains__(self, name: str) -> bool:
975975

976976
def __repr__(self) -> str:
977977
"""Simple representation of the submodels collection."""
978-
title = 'flixopt.structure.Submodels:'
978+
if not self.data:
979+
return 'flixopt.structure.Submodels:\n----------------------------\n <empty>\n'
980+
981+
total_vars = sum(len(submodel.variables) for submodel in self.data.values())
982+
total_cons = sum(len(submodel.constraints) for submodel in self.data.values())
983+
984+
title = f'flixopt.structure.Submodels ({total_vars} vars, {total_cons} constraints, {len(self.data)} submodels):'
979985
underline = '-' * len(title)
980986

981987
if not self.data:
982988
return f'{title}\n{underline}\n <empty>\n'
983-
984989
sub_models_string = ''
985990
for name, submodel in self.data.items():
986-
sub_models_string += f'\n * {name} ({submodel.__class__.__name__}) [{len(submodel.variables)} Vars + {len(submodel.constraints)} Cons)'
991+
type_name = submodel.__class__.__name__
992+
var_count = len(submodel.variables)
993+
con_count = len(submodel.constraints)
994+
sub_models_string += f'\n * {name} [{type_name}] ({var_count}v/{con_count}c)'
987995

988996
return f'{title}\n{underline}{sub_models_string}\n'
989997

0 commit comments

Comments
 (0)