Esempio n. 1
0
def plate_runtimes_for_operator_range(start, end):
    plate_query = QLBPlate.filter_by_host_datetime(Session.query(QLBPlate,
                                                                 func.count(QLBWell).label('wells'),
                                                                 func.sum(func.if_(QLBWell.event_count >= 1000, 1, 0)).label('data_wells'),
                                                                 func.sum(QLBWell.event_count).label('data_well_events')).
                                                           join(QLBWell).\
                                                           join(QLBPlate.plate).\
                                                           join(Plate.box2).\
                                                           filter(and_(QLBPlate.plate_id != None,
                                                                       QLBWell.file_id != None)),
                                                   start, end).group_by(QLBWell.plate_id).options(joinedload_all('plate.box2', innerjoin=True),
                                                                                                  joinedload_all('plate.operator'))
    if wowo('contractor'):
        plate_query = plate_query.filter(Box2.prod_query())
    return plate_query.all()
Esempio n. 2
0
    def source_counts(self, children=False, limit=4):
        # source counts per document
        subq = db.session\
            .query(
                Medium.name.label('medium'),
                func.count(1).label('n_sources'))\
            .join(Document)\
            .join(DocumentSource)\
            .group_by(Medium.name, DocumentSource.doc_id)

        if children:
            subq = subq.filter(DocumentSource.source_type == 'child')

        subq = self.filter(subq).subquery()

        return db.session\
            .query(
                subq.c.medium,
                func.if_(subq.c.n_sources > limit, ">%s" % limit, subq.c.n_sources).label('bucket'),
                func.count(1))\
            .select_from(subq)\
            .group_by(subq.c.medium, 'bucket')\
            .all()