Esempio n. 1
0
def get_distribution(benchmark_result, limit):
    from ..entities.benchmark_result import BenchmarkResult

    commits_up = (get_commits_up(benchmark_result.run.commit,
                                 limit).subquery().alias("commits_up"))

    return (Session.query(
        func.text(benchmark_result.case_id).label("case_id"),
        func.text(benchmark_result.context_id).label("context_id"),
        func.text(benchmark_result.run.commit_id).label("commit_id"),
        Hardware.hash.label("hash"),
        func.max(BenchmarkResult.unit).label("unit"),
        func.avg(BenchmarkResult.mean).label("mean_mean"),
        func.stddev(BenchmarkResult.mean).label("mean_sd"),
        func.avg(BenchmarkResult.min).label("min_mean"),
        func.stddev(BenchmarkResult.min).label("min_sd"),
        func.avg(BenchmarkResult.max).label("max_mean"),
        func.stddev(BenchmarkResult.max).label("max_sd"),
        func.avg(BenchmarkResult.median).label("median_mean"),
        func.stddev(BenchmarkResult.median).label("median_sd"),
        func.min(commits_up.c.timestamp).label("first_timestamp"),
        func.max(commits_up.c.timestamp).label("last_timestamp"),
        func.count(BenchmarkResult.mean).label("observations"),
    ).group_by(
        BenchmarkResult.case_id,
        BenchmarkResult.context_id,
        Hardware.hash,
    ).join(Run, Run.id == BenchmarkResult.run_id).join(
        Hardware, Hardware.id == Run.hardware_id).join(
            commits_up, commits_up.c.id == Run.commit_id).filter(
                Run.name.like("commit: %"),
                BenchmarkResult.case_id == benchmark_result.case_id,
                BenchmarkResult.context_id == benchmark_result.context_id,
                Hardware.hash == benchmark_result.run.hardware.hash,
            ))
Esempio n. 2
0
def get_requests():
    """
    Get all project requests
    """
    filters = []
    if 'project_name' in request.args:
        filters.append(Request.project_name == request.args['project_name'])
    if 'reference_id' in request.args:
        filters.append(func.text(Request.reference_id) == request.args['reference_id'])

    all_requests = flask.g.session.query(Request, User.username
        ).join(User, Request.user_id == User.id
        ).filter(*filters
        ).order_by(case(((Request.status == 'pending', 1),
                        (Request.status == 'approved', 2),
                        (Request.status == 'declined', 3)))
        ).all()

    requests = []
    row2dict = lambda row: {
        column.name: str(getattr(row, column.name))
        for column in row.__table__.columns 
        if column.name in ['reference_id', 'project_name', 'status', 'project_desc']
        }
    
    for req, requested_by in all_requests:
        request_obj = row2dict(req)
        request_obj['requested_by'] = requested_by
        requests.append(request_obj)

    return jsonify({'message': 'success', 'requests': requests}), 200
class Human(Base):
    '''
    Human accesses the Association as a One to Many relationship
    '''
    __tablename__ = 'humans'
    id = Column(Integer, primary_key=True)
    name = Column(String)
    carsAssoc = relationship('HumanCarAssociation')
    e =  func.date_add(func.now(), bindparam('e', func.text('INTERVAL 5 day')))
Esempio n. 4
0
def hashed_uid_factory(request):
    if request.matchdict is not None and 'hash' in request.matchdict:
        context = models.TalkPreference.query.filter(
            func.encode(
                func.digest(func.text(models.TalkPreference.uid), 'sha256'),
                'hex') == request.matchdict['hash']).first()
        if context is None:
            raise NotFound()
        return context
    return object()
Esempio n. 5
0
def postgresql_non_ascii_and_lower(column, as_text=True):
    if hasattr(column, 'property'):
        columns = column.property.columns
        if len(columns) > 1:
            column = func.concat(*columns)
        else:
            column = column.property.columns[0]

    if isinstance(column.type, Enum):
        return column
    elif isinstance(column.type, String):
        return func.lower_and_clear(column)
    elif isinstance(column.type, Numeric):
        return column
    elif as_text:
        return func.text(column)
    else:
        return column
Esempio n. 6
0
 def test_namespacing_conflicts(self):
     self.assert_compile(func.text('foo'), 'text(:text_1)')
Esempio n. 7
0
 def test_namespacing_conflicts(self):
     self.assert_compile(func.text("foo"), "text(:text_1)")
Esempio n. 8
0
 def test_namespacing_conflicts(self):
     self.assert_compile(func.text("foo"), "text(:text_1)")
Esempio n. 9
0
        .join(Host.interfaces)
        .join(Host.room)
        .join(Room.connected_patch_ports)
        .join(SwitchPort)
        .join(Switch)
        .statement,
    ),
)
hades_view_ddl.add_view(radius_property, radusergroup)

radcheck = View(
    name='radcheck',
    query=(
        # This adds all existing interfaces.
        Query([
            func.text(Interface.mac).label('UserName'),
            func.host(Switch.management_ip).label('NASIPAddress'),
            SwitchPort.name.label('NASPortId'),
            literal("User-Name").label('Attribute'),
            literal("=*").label('Op'),
            null().label('Value'),
            literal(10).label('Priority'),
        ]).select_from(Interface)
        .join(Host)
        .join(Room)
        .join(Room.connected_patch_ports)
        .join(SwitchPort)
        .join(Switch)
        .statement
    ),
)
Esempio n. 10
0
def test_get_talk_by_hashed_uid(models, talk_preference):
    from sqlalchemy import func
    assert models.TalkPreference.query.filter(
        func.encode(func.digest(func.text(models.TalkPreference.uid), 'sha256'), 'hex')
        == talk_preference.hashed_uid).one() == talk_preference
def get_distribution(
    summary_table,
    run_table,
    machine_table,
    commit_table,
    commit,
    summary,
    machine_hash,
    limit,
):
    commits_up = (
        get_commits_up(commit_table, commit, limit).subquery().alias("commits_up")
    )
    return (
        select(
            func.text(summary.case_id).label("case_id"),
            func.text(summary.context_id).label("context_id"),
            func.text(commit.id).label("commit_id"),
            func.concat(
                machine_table.c.name,
                "-",
                machine_table.c.gpu_count,
                "-",
                machine_table.c.cpu_core_count,
                "-",
                machine_table.c.cpu_thread_count,
                "-",
                machine_table.c.memory_bytes,
            ).label("hash"),
            func.max(summary_table.c.unit).label("unit"),
            func.avg(summary_table.c.mean).label("mean_mean"),
            func.stddev(summary_table.c.mean).label("mean_sd"),
            func.avg(summary_table.c.min).label("min_mean"),
            func.stddev(summary_table.c.min).label("min_sd"),
            func.avg(summary_table.c.max).label("max_mean"),
            func.stddev(summary_table.c.max).label("max_sd"),
            func.avg(summary_table.c.median).label("median_mean"),
            func.stddev(summary_table.c.median).label("median_sd"),
            func.min(commits_up.c.timestamp).label("first_timestamp"),
            func.max(commits_up.c.timestamp).label("last_timestamp"),
            func.count(summary_table.c.mean).label("observations"),
        )
        .group_by(
            summary_table.c.case_id,
            summary_table.c.context_id,
            machine_table.c.name,
            machine_table.c.gpu_count,
            machine_table.c.cpu_core_count,
            machine_table.c.cpu_thread_count,
            machine_table.c.memory_bytes,
        )
        .join(run_table, run_table.c.id == summary_table.c.run_id)
        .join(machine_table, machine_table.c.id == run_table.c.machine_id)
        .join(commits_up, commits_up.c.id == run_table.c.commit_id)
        .filter(
            run_table.c.name.like("commit: %"),
            summary_table.c.case_id == summary.case_id,
            summary_table.c.context_id == summary.context_id,
            func.concat(
                machine_table.c.name,
                "-",
                machine_table.c.gpu_count,
                "-",
                machine_table.c.cpu_core_count,
                "-",
                machine_table.c.cpu_thread_count,
                "-",
                machine_table.c.memory_bytes,
            )
            == machine_hash,
        )
    )
Esempio n. 12
0
def test_get_talk_by_hashed_uid(models, talk_preference):
    from sqlalchemy import func
    assert models.TalkPreference.query.filter(func.encode(func.digest(func.text(models.TalkPreference.uid), 'sha256'), 'hex') == talk_preference.hashed_uid).one() == talk_preference