Ejemplo n.º 1
0
    def _get_genom_data(self, db_session, res_id):
        query = OrmGdbModel(db_session).get_query()
        query = query.join(OrmGdbModel.GdbMapper.pooldb)
        query = query.filter(OrmGdbModel.GdbMapper.ID == res_id)

        geno_row = query.first()

        if geno_row is None:
            return {}

        data = {
            "id": res_id,
            "name": geno_row.NAME,
            "gene_pool": geno_row.pooldb.POOLNAME,
            "author_contact": geno_row.CONTACT,
            "author": geno_row.AUTHORNAME,
            "date_submitted": "" if geno_row.DATE is None else geno_row.DATE.isoformat(),
            "description": geno_row.SHORTINFO,
            "origin": geno_row.ORIGIN,
            "origin_story": geno_row.ORIGINSTORY,
            "size": {
                "parts": geno_row.COUNT_P,
                "joints": geno_row.COUNT_J,
                "neurons": geno_row.COUNT_N,
                "neural_connections": geno_row.COUNT_C,
            },
            "geno_html": Markup(geno_row.GENO_HTML),
            "notes": geno_row.NOTES,
            "geno_f0": geno_row.GENO_F0,
            "genotype": geno_row.GENO,
            "performance": self._get_performances(db_session, res_id),
        }

        return data
Ejemplo n.º 2
0
def get_genoms_data(session, cond, pagination=None):

    query = OrmGdbModel(session).get_query()
    query = query.join(OrmPooldbModel.PooldbMapper)
    query = query.join(OrmPerformancedbModel.PerformancedbMapper)

    if 'pools[]' in cond:
        query = query.filter(OrmGdbModel.GdbMapper.POOL_ID.in_(cond['pools[]']))

    if 'search' in cond and 'columns[]' in cond:
        complex_or = None
        for el in cond['columns[]']:
            if complex_or is None:
                complex_or = getattr(OrmGdbModel.GdbMapper, el).like(
                    '%{0}%'.format(cond['search']))
            else:
                complex_or = or_(
                    complex_or, getattr(OrmGdbModel.GdbMapper, el).like(
                        '%{0}%'.format(cond['search']))
                )
        if complex_or is not None:
            query = query.filter(complex_or)

    if pagination is not None:
        pagination.num_of_pages = query.count()
        query = pagination.paginate(query)

    if 'sort' in cond:
        if hasattr(OrmGdbModel.GdbMapper, cond['sort']):
            query = query.from_self().join(OrmPooldbModel.PooldbMapper).order_by(
                getattr(OrmGdbModel.GdbMapper, cond['sort'])
            )
        elif hasattr(OrmPooldbModel.PooldbMapper, cond['sort']):
            query = query.from_self().join(OrmPooldbModel.PooldbMapper).order_by(
                getattr(OrmPooldbModel.PooldbMapper, cond['sort'])
            )
        elif hasattr(OrmPerformancedbModel.PerformancedbMapper, cond['sort']):
            query = query.from_self().join(
                OrmPerformancedbModel.PerformancedbMapper
            ).filter(
                OrmPerformancedbModel.PerformancedbMapper.ENV_ID == cond['env_id']
            ).order_by(
                getattr(OrmPerformancedbModel.PerformancedbMapper, cond['sort'])
            )

    data = query.all()
    rows = list()

    for row in data:

        query = OrmPerformancedbModel(session).get_query().join(
            OrmPerformancedbModel.PerformancedbMapper.envdb
        ).filter(
            OrmPerformancedbModel.PerformancedbMapper.GENO_ID == row.ID
        ).order_by(OrmEnvdbModel.EnvdbMapper.NAME)

        tmp_perf = []
        for perf in query.all():
            tmp_perf.append(perf.PERFORMANCE)

        rows.append({
            'id': row.ID,
            'name': row.NAME,
            'gene_pool': row.pooldb.POOLNAME,
            'author': row.AUTHORNAME,
            'description': row.SHORTINFO,
            'size': {
                    'parts': row.COUNT_P,
                    'joints': row.COUNT_J,
                    'neurons': row.COUNT_N,
                    'neural_connections': row.COUNT_C
                    },
            'geno_html': Markup(row.GENO_HTML),
            'geno_html_short': Markup(row.GENO_HTML_SHORT),
            'performance': tmp_perf,
            'genotype': row.GENO,
            'origin': row.ORIGIN,
            'date_submitted': '' if row.DATE is None else row.DATE.isoformat(),
            'origin_story': row.ORIGINSTORY,
            'notes': row.NOTES
        })

    res = dict()
    env_names = OrmEnvdbModel(session).get_query().order_by(
        OrmEnvdbModel.EnvdbMapper.NAME
    ).all()
    res['env_names'] = [el.NAME for el in env_names]
    res['genotypes'] = rows
    return res