Ejemplo n.º 1
0
def visualize_trace(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        'SELECT problem_id, data '
        'FROM traces WHERE id = %s',
        [id])
    [problem_id, trace_data] = cur.fetchone()
    trace_data = zlib.decompress(trace_data)
    trace_data = list(map(int, trace_data))

    cur.execute(
        'SELECT src_data, tgt_data '
        'FROM problems WHERE id = %s',
        [problem_id])
    [src_data, tgt_data] = cur.fetchone()
    if src_data is not None:
        src_data = zlib.decompress(src_data)
        src_data = list(map(int, src_data))
    if tgt_data is not None:
        tgt_data = zlib.decompress(tgt_data)
        tgt_data = list(map(int, tgt_data))

    return flask.render_template(
        'visualize_trace.html',
        src_data=src_data,
        tgt_data=tgt_data,
        trace_data=trace_data)
def list_solutions():
    name_filter = flask.request.args.get('name', '%')
    rev = flask.request.args.get('reversed', '0')
    assert rev in ('0', '1')
    rev = rev == '1'

    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        f'''
        SELECT
            tasks.id, tasks.name,
            solutions.id, solutions.scent, solutions.status, solutions.score,
            solutions.invocation_id, solutions.data IS NOT NULL,
            solutions.extra
        FROM tasks
        LEFT OUTER JOIN solutions ON solutions.task_id = tasks.id
        WHERE tasks.name SIMILAR TO %s AND solutions.status != 'PASS'
        ORDER BY tasks.id {'DESC' if rev else 'ASC'}, solutions.id DESC
    ''', [name_filter])
    rows = cur.fetchall()
    best_by_task = defaultdict(lambda: float('+inf'))
    for [task_id, _, _, _, _, score, _, _, _] in rows:
        if score is not None:
            best_by_task[task_id] = min(best_by_task[task_id], score)

    return memoized_render_template_string(LIST_SOLUTIONS_TEMPLATE, **locals())
Ejemplo n.º 3
0
def list_invocations():
    conn = get_conn()
    cur = conn.cursor()
    cur.execute('SELECT id, data FROM invocations ORDER BY id DESC')

    return memoized_render_template_string(LIST_INVOCATIONS_TEMPLATE,
                                           **locals())
Ejemplo n.º 4
0
def list_problems():
    prefix = flask.request.args.get('prefix', '')

    conn = get_conn()
    cur = conn.cursor()
    cur.execute('''
        SELECT
            problems.id, problems.name,
            problems.src_data IS NOT NULL, problems.tgt_data IS NOT NULL,
            problems.stats, problems.invocation_id,
            traces.id, traces.scent, traces.status, traces.energy, traces.invocation_id,
            traces.data IS NOT NULL,
            traces.extra
        FROM problems
        LEFT OUTER JOIN traces ON traces.problem_id = problems.id
        WHERE problems.name LIKE %s
        ORDER BY problems.id DESC, traces.id DESC
    ''', [prefix + '%'])
    rows = cur.fetchall()
    best_by_problem = defaultdict(lambda: float('+inf'))
    for [problem_id, _, _, _, _, _, _, _, _,  energy, _, _, _] in rows:
        if energy is not None:
            best_by_problem[problem_id] = min(best_by_problem[problem_id], energy)

    return memoized_render_template_string(LIST_PROBLEMS_TEMPLATE, **locals())
Ejemplo n.º 5
0
def list_invocations():
    conn = get_conn()
    cur = conn.cursor()
    cur.execute('''
    SELECT
        id,
        CASE
            WHEN status = 'RUN' AND update_time < NOW() THEN 'LOST'
            ELSE status
        END,
        start_time,
        update_time,
        data
    FROM invocations
    ''')
    rows = list(cur)

    def key(row):
        status = row[1]
        start_time = row[2]
        end_time = row[3]
        if status == 'RUN':
            return 2, start_time
        else:
            return 1, end_time

    rows.sort(key=key, reverse=True)

    t = type
    return memoized_render_template_string(LIST_INVOCATIONS_TEMPLATE,
                                           **locals())
def view_car(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        'SELECT name, data, invocation_id, timestamp FROM cars WHERE id = %s',
        [id])
    [car_name, car_data, inv_id, timestamp] = cur.fetchone()
    cur.execute(
        'SELECT data FROM invocations WHERE id = %s',
        [inv_id])
    [inv_data] = cur.fetchone()

    cur.execute('''
        SELECT
            fuels.id, fuels.score, fuels.timestamp, fuels.invocation_id,
            fuel_submissions.id, fuel_submissions.data IS NOT NULL
        FROM fuels
        LEFT OUTER JOIN fuel_submissions
        ON fuels.id = fuel_submissions.fuel_id
        WHERE fuels.car_id = %s
        ORDER BY fuels.id DESC, fuel_submissions.id DESC
        ''',
        [id])
    fuels = cur.fetchall()

    return memoized_render_template_string(VIEW_CAR_TEMPLATE, **locals())
Ejemplo n.º 7
0
def view_problem(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute('''
        SELECT
            name,
            src_data IS NOT NULL,
            tgt_data IS NOT NULL,
            stats, extra, invocation_id, timestamp
        FROM problems WHERE id = %s''',
        [id])
    [name, has_src, has_tgt, stats, extra, inv_id, timestamp] = cur.fetchone()

    cur.execute('''
        SELECT id, scent, status, energy, invocation_id, timestamp
        FROM traces
        WHERE problem_id = %s
        ORDER BY id DESC
        ''',
        [id])
    traces = cur.fetchall()
    best_energy = min(
        (energy for _, _, _, energy, _, _ in traces if energy is not None),
        default=-1)
    return memoized_render_template_string(VIEW_PROBLEM_TEMPLATE, **locals())
Ejemplo n.º 8
0
def view_trace(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        'SELECT problem_id, scent, status, energy, extra, invocation_id '
        'FROM traces WHERE id = %s',
        [id])
    [problem_id, scent, status, energy, extra, inv_id] = cur.fetchone()

    return memoized_render_template_string(VIEW_TRACE_TEMPLATE, **locals())
def list_tasks():
    conn = get_conn()
    cur = conn.cursor()
    cur.execute('''
        SELECT
            tasks.invocation_id,
            tasks.id, tasks.name,
            tasks.stats,
            tasks.extra
        FROM tasks
        ORDER BY tasks.id ASC
    ''')
    return memoized_render_template_string(LIST_TASKS_TEMPLATE, **locals())
def list_cars():
    conn = get_conn()
    cur = conn.cursor()
    cur.execute('''
        SELECT
            cars.id, cars.name, cars.invocation_id, cars.timestamp,
            fuels.id, fuels.score,
            fuel_submissions.id, fuel_submissions.data IS NOT NULL
        FROM cars
        LEFT OUTER JOIN fuels ON fuels.car_id = cars.id
        LEFT OUTER JOIN fuel_submissions ON fuel_submissions.fuel_id = fuels.id
        ORDER BY cars.id DESC, fuels.id DESC, fuel_submissions.id DESC
    ''')
    return memoized_render_template_string(LIST_CARS_TEMPLATE, **locals())
def view_solution(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        'SELECT task_id, scent, status, score, data, extra, invocation_id '
        'FROM solutions WHERE id = %s', [id])
    [task_id, scent, status, score, data, extra, inv_id] = cur.fetchone()
    if data is not None:
        data = zlib.decompress(data)

    cur.execute('SELECT name, data ' 'FROM tasks WHERE id = %s', [task_id])
    [task_name, task_data] = cur.fetchone()
    task_data = zlib.decompress(task_data)

    return memoized_render_template_string(VIEW_SOLUTION_TEMPLATE, **locals())
Ejemplo n.º 12
0
def view_invocation(id):
    conn = get_conn()
    cur = conn.cursor()

    cur.execute('SELECT data FROM invocations WHERE id=%s', [id])
    [inv] = cur.fetchone()

    cur.execute('''
        SELECT
            problems.id, traces.energy
        FROM problems
        LEFT OUTER JOIN traces ON traces.problem_id = problems.id
    ''')
    best_by_problem = defaultdict(lambda: float('+inf'))
    for [problem_id, energy] in cur:
        if energy is not None:
            best_by_problem[problem_id] = min(best_by_problem[problem_id],
                                              energy)

    cur.execute(
        '''
        SELECT
            id, status, energy, problem_id, scent, timestamp
        FROM traces
        WHERE invocation_id = %s
    ''', [id])
    traces = cur.fetchall()

    cur.execute(
        'SELECT id, name, timestamp FROM cars WHERE invocation_id=%s ORDER BY id DESC',
        [id])
    cars = cur.fetchall()

    cur.execute(
        'SELECT id, car_id, score, timestamp '
        'FROM fuels WHERE invocation_id = %s '
        'ORDER BY id DESC', [id])
    fuels = cur.fetchall()

    cur.execute(
        'SELECT id, fuel_id, data IS NOT NULL, timestamp '
        'FROM fuel_submissions WHERE invocation_id = %s '
        'ORDER BY id DESC', [id])
    fuel_submissions = cur.fetchall()

    return memoized_render_template_string(VIEW_INVOCATION_TEMPLATE,
                                           **locals())
def list_fuel_submissions():
    conn = get_conn()
    cur = conn.cursor()
    cur.execute('''
        SELECT
            fuel_submissions.id,
            fuel_submissions.fuel_id,
            fuels.car_id,
            fuels.score,
            fuel_submissions.data IS NOT NULL,
            fuel_submissions.invocation_id,
            fuel_submissions.timestamp
        FROM fuel_submissions
        JOIN fuels ON fuel_submissions.fuel_id = fuels.id
        ORDER BY fuel_submissions.id DESC
        ''')
    return memoized_render_template_string(LIST_FUEL_SUBMISSIONS_TEMPLATE, **locals())
Ejemplo n.º 14
0
def view_invocation(id):
    conn = get_conn()
    cur = conn.cursor()

    cur.execute('SELECT data FROM invocations WHERE id=%s', [id])
    [inv] = cur.fetchone()

    cur.execute(
        '''
        SELECT
            id, status, score, task_id, scent, time, extra
        FROM solutions
        WHERE invocation_id = %s
    ''', [id])
    solutions = cur.fetchall()

    return memoized_render_template_string(VIEW_INVOCATION_TEMPLATE,
                                           **locals())
def view_fuel_submission(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        'SELECT data, extra, fuel_id, invocation_id, timestamp '
        'FROM fuel_submissions WHERE id = %s',
        [id])
    [data, extra, fuel_id, inv_id, timestamp] = cur.fetchone()
    cur.execute(
        'SELECT data FROM invocations WHERE id = %s',
        [inv_id])
    [inv_data] = cur.fetchone()
    cur.execute(
        'SELECT car_id FROM fuels WHERE id = %s',
        [fuel_id])
    [car_id] = cur.fetchone()

    return memoized_render_template_string(VIEW_FUEL_SUBMISSION_TEMPLATE, **locals())
Ejemplo n.º 16
0
def visualize_model(id):
    which = flask.request.args['which']
    conn = get_conn()
    cur = conn.cursor()

    if which == 'src':
        cur.execute(
            'SELECT src_data '
            'FROM problems WHERE id = %s',
            [id])
    elif which == 'tgt':
        cur.execute(
            'SELECT tgt_data '
            'FROM problems WHERE id = %s',
            [id])
    else:
        assert False, which

    [data] = cur.fetchone()
    data = zlib.decompress(data)

    return flask.render_template('visualize_model.html', data=list(map(int, data)))
def view_task(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        '''
        SELECT
            name,
            data,
            stats,
            extra
        FROM tasks WHERE id = %s''', [id])
    [name, data, stats, extra] = cur.fetchone()

    s = zlib.decompress(data).decode()
    task = Task.parse(s)

    bb = poly_bb(task.border)

    grid = [['#'] * (bb.x2 - bb.x1) for y in range(bb.y1, bb.y2)]

    for row in rasterize_poly(task.border):
        for x in range(row.x1, row.x2):
            assert grid[row.y - bb.y1][x - bb.x1] == '#'
            grid[row.y - bb.y1][x - bb.x1] = '.'

    for obstacle in task.obstacles:
        for row in rasterize_poly(obstacle):
            for x in range(row.x1, row.x2):
                assert grid[row.y - bb.y1][x - bb.x1] == '.'
                grid[row.y - bb.y1][x - bb.x1] = '#'

    grid[task.start.y - bb.y1][task.start.x - bb.x1] = '!'

    for booster in task.boosters:
        grid[booster.pos.y - bb.y1][booster.pos.x - bb.x1] = booster.code

    grid = '\n'.join(' '.join(row) for row in reversed(grid))

    return memoized_render_template_string(VIEW_TASK_TEMPLATE, **locals())
def view_fuel(id):
    conn = get_conn()
    cur = conn.cursor()
    cur.execute(
        'SELECT data, score, extra, car_id, invocation_id, timestamp '
        'FROM fuels WHERE id = %s',
        [id])
    [fuel_data, fuel_score, extra, car_id, inv_id, timestamp] = cur.fetchone()
    cur.execute(
        'SELECT data FROM invocations WHERE id = %s',
        [inv_id])
    [inv_data] = cur.fetchone()

    cur.execute('''
        SELECT id, data IS NOT NULL, timestamp
        FROM fuel_submissions
        WHERE fuel_id = %s
        ORDER BY id DESC
        ''',
        [id])
    submissions = cur.fetchall()

    return memoized_render_template_string(VIEW_FUEL_TEMPLATE, **locals())