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

fixed shortest path bug #28

Merged
merged 1 commit into from
Jun 23, 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
26 changes: 22 additions & 4 deletions src/trackteroid/entities/relationships_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,36 @@ def parse_session_schemas(self):

def create_entity_network(self, ftrack_entity):
self._tmp_exclude_types = set(self._exclude_types)
# entity type must be excluded, as finding it in one of its children would lead to an endless recursion
self._tmp_exclude_types.add(ftrack_entity)
return self.recurse_entity_connections(ftrack_entity, ancestors=set())

def recurse_entity_connections(self, ftrack_entity, ancestors=None):
# ancestors are the entities, in sequence, linking to the current entity
# the top entity of course has none
if ancestors is None:
ancestors = set()
# refs - reference type attributes on the current entity
# type - current entity's type
network = {"refs": {}, "type": ftrack_entity}
# return otherwise recursion will be endless
if ftrack_entity in ancestors:
return network

# get all array or non-array reference attributes of the current entity
refs = self._entities.get(ftrack_entity).get(self._ref_key)
if refs:
# first iteration - validate props
valid_props = {}
for prop_name, prop_type in refs.items():
if prop_name in self._attributes_blacklist or prop_type in self._tmp_exclude_types or prop_type == ftrack_entity:
continue
if prop_name not in self._attributes_blacklist and prop_type not in self._tmp_exclude_types and prop_type != ftrack_entity:
valid_props[prop_name] = prop_type
# add valid prop types to exclude list for deeper recursions
self._tmp_exclude_types.update(valid_props.values())

# second iteration, recurse all valid props
for prop_name, prop_type in valid_props.items():
if prop_type in self._entities:
self._tmp_exclude_types.add(ftrack_entity)
ancestors.add(ftrack_entity)
network["refs"][prop_name] = self.recurse_entity_connections(prop_type, ancestors)
return network
Expand All @@ -124,15 +139,18 @@ def extract_all_entity_relations(self):
for entity_name in self._entities:
self._relationships[entity_name] = {}

# create network of non-array references
self.use_array_refs = False
asset_network = self.create_entity_network(entity_name)

# extract non-collection relations
self._relationships[entity_name]["non_collection"] = self.extract_entity_relations(asset_network)

# extract collection relations
# create network of array references
self.use_array_refs = True
asset_network = self.create_entity_network(entity_name)

# extract collection relations
self._relationships[entity_name]["collection"] = self.extract_entity_relations(asset_network)

def parse_project_structure(self, project):
Expand Down
9 changes: 7 additions & 2 deletions src/trackteroid/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,15 @@ def __ne__(self, other):
def parsed_relationships(self):
if not self._session.server_url in _PARSED_RELATIONSHIPS_CACHE:
relationship_parser = RelationshipsParser(ftrack_session=self._session)
# TODO: why do we have to exclude certain types?
# types such as "Context" are ambiguous and cannot be used to extract direct relationships
# example structure - Seq -> Folder -> Shot
# in this case, establishing a relationship from Seq to Shot is impossible as would any other
# that went through "parent" or "children" for example
relationship_parser.exclude_types = {"Context"}
relationship_parser.parse_session_schemas()
# TODO: why do we have to exclude certain attributes?
# attributes that group things cannot be used to extract relationships
# as an example, "descendants" lists all children and children of children and so on,
# so they are all flattened with their relationships removed
relationship_parser.attributes_blacklist = {"descendants", "ancestors", "status_changes"}
relationship_parser.extract_all_entity_relations()
_PARSED_RELATIONSHIPS_CACHE[self._session.server_url] = relationship_parser
Expand Down