def get_closest_struc_django(distinct=True): nodes = ParameterData.query().with_entities('id') struc_type = StructureData._query_type_string depth = (sa.session.query(DbPath.depth).filter( DbPath.child_id.in_(nodes)).join(DbNode, DbPath.parent).filter( DbNode.type.like("{}%".format(struc_type))).order_by(DbPath.depth)) if distinct: depth = depth.distinct() depth = depth[0][0] q = (DbPath.query.filter(DbPath.child_id.in_(nodes)).join( DbNode, DbPath.parent).filter(DbNode.type.like( "{}%".format(struc_type))).filter(DbPath.depth == depth)) q = q.distinct() q = q.with_entities(DbPath.id) res = (StructureData.query().join(DbPath, DbNode.child_paths).filter( DbPath.child_id.in_(nodes)).filter(DbPath.id.in_(q))) res = res.distinct() res = res.order_by(DbNode.ctime) if not with_attr: res = res.options(defer(DbNode.attributes), defer(DbNode.extras)) return res.all()
def mounet1(with_key_filter=False): pw_calc = Group.get(pk=1139193).nodes.next() structure = pw_calc.out.output_structure qstruc = StructureData.query(children__pk=structure.pk) attr_filters = models.DbAttribute.objects.filter(tval__endswith='alvarez') # Because we can't reproduce a filter on the value only with a JSON table, # a fairer comparison would be with a filter on the key too. if with_key_filter: attr_filters = attr_filters.filter( Q(key="radii_source") | Q(key="lowdim_dict.radii_source")) qic = InlineCalculation.query(inputs__in=qstruc).filter( inputs__dbattributes__in=attr_filters).distinct() return qic.count()
def mounet1(): pw_calc = Group.get(pk=1139193).nodes.next() structure = pw_calc.out.output_structure qstruc = StructureData.query(children__pk=structure.pk).with_entities( DbNode.id) n_children = aliased(DbNode) qic = (InlineCalculation.query( ).join(DbLink, DbNode.id == DbLink.output_id).filter( DbLink.input_id.in_(qstruc)).join(n_children, DbNode.inputs).filter( or_( n_children.attributes["radii_source"].astext.like("%alvarez"), n_children.attributes[( "lowdim_dict", "radii_source")].astext.like("%alvarez"))).distinct()) return qic.with_entities(func.count(DbNode.id)).scalar()
def get_closest_struc(): nodes = ParameterData.query() struc_type = StructureData._query_type_string depth = models.DbPath.objects.filter( child__in=nodes, parent__type__contains=struc_type).distinct().order_by( 'depth').values_list('depth')[0][0] q = models.DbPath.objects.filter(parent__type__contains=struc_type, child__in=nodes, depth=depth).distinct() res = StructureData.query(children__in=nodes, child_paths__in=q).distinct().order_by('ctime') return list(res)
def mounet2(): StructureData = DataFactory('structure') structure = load_node(2304207) qstruc = StructureData.query(children__pk=structure.pk).with_entities( DbNode.id) n_children = aliased(DbNode) qic = (InlineCalculation.query().filter( DbNode.attributes["function_name"].astext == "lowdimfinder_inline" ).join(DbLink, DbNode.id == DbLink.output_id).filter( DbLink.input_id.in_(qstruc)).join(n_children, DbNode.inputs).filter( or_( n_children.attributes["radii_source"].astext.like("%alvarez"), n_children.attributes[( "lowdim_dict", "radii_source")].astext.like("%alvarez"))).distinct()) return qic.with_entities(func.count(DbNode.id)).scalar()
def mounet2(with_key_filter=False): StructureData = DataFactory('structure') structure = load_node(2304207) qstruc = StructureData.query(children__pk=structure.pk) qattr = models.DbAttribute.objects.filter(key='function_name', tval='lowdimfinder_inline', dbnode__inputs__in=qstruc) attr_filters = models.DbAttribute.objects.filter(tval__endswith='alvarez') if with_key_filter: attr_filters = attr_filters.filter( Q(key="radii_source") | Q(key="lowdim_dict.radii_source")) qic = InlineCalculation.query( inputs__in=qstruc, dbattributes__in=qattr).filter( inputs__dbattributes__in=attr_filters).distinct() return qic.count()