MCPcopy Index your code
hub / github.com/diffgram/diffgram / get_label_list

Method get_label_list

shared/database/project.py:549–621  ·  view source on GitHub ↗
(self, session, directory, schema_id = None)

Source from the content-addressed store, hash-verified

547 return LabelSchema.get_default(session = session, project_id = self.id)
548
549 def get_label_list(self, session, directory, schema_id = None):
550 working_dir_sub_query = session.query(WorkingDirFileLink).filter(
551 WorkingDirFileLink.working_dir_id == directory.id,
552 WorkingDirFileLink.type == "label").subquery('working_dir_sub_query')
553
554 # Caution, don't do "state != "removed" here,
555 # Since we may have removed label files
556 # With active instances, and still need this for colour map
557
558 working_dir_file_list_query = session.query(File).filter(
559 File.id == working_dir_sub_query.c.file_id)
560
561 if schema_id is not None:
562 schema = LabelSchema.get_by_id(session = session, id = schema_id, project_id = self.id)
563 link_file_id_list = schema.get_label_files(session = session, ids_only = True)
564 working_dir_file_list_query = working_dir_file_list_query.filter(
565 File.id.in_(link_file_id_list)
566 )
567 t1 = time.time()
568 working_dir_file_list = working_dir_file_list_query.all()
569 labels_out = []
570
571 colour_map = directory.label_file_colour_map
572 rebuild_colour_map = False
573
574 if not colour_map:
575 rebuild_colour_map = True
576
577 if rebuild_colour_map is True:
578 colour_map = {}
579
580 file_id_list = [f.id for f in working_dir_file_list]
581 # Fetch Labels Data
582 label_ids = [file.label_id for file in working_dir_file_list]
583 labels = session.query(Label).filter(
584 Label.id.in_(label_ids)
585 )
586 labels_serialized_dict = {}
587 for label in labels:
588 labels_serialized_dict[label.id] = label.serialize()
589 # Fetch Attributes
590 group_relations = Attribute_Template_Group.get_group_relations_list(session = session,
591 file_id_list = file_id_list)
592
593 group_rel_ids = [rel.attribute_template_group_id for rel in group_relations]
594 attribute_groups_serialized_dict = {}
595 # for rel in group_relations:
596 # if not attribute_groups_serialized_dict.get(rel.file_id):
597 # attribute_groups_serialized_dict[rel.file_id] = [rel.attribute_template_group.serialize_with_attributes(session = session)]
598 # else:
599 # attribute_groups_serialized_dict[rel.file_id].append(rel.attribute_template_group.serialize_with_attributes(session = session))
600
601 # In context of a Label File!!
602 for file in working_dir_file_list:
603
604 if file.state != "removed":
605 serialized_file_data = file.serialize_base_file()
606 serialized_file_data['colour'] = file.colour

Callers 3

api_get_labelsFunction · 0.80
get_suggestionsMethod · 0.80

Calls 8

get_label_filesMethod · 0.80
serialize_base_fileMethod · 0.80
get_by_idMethod · 0.45
serializeMethod · 0.45
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected