def robot_detail(robot_id, inputs=None):
    robot = r.get_registry()['ROBOTS'].get_robot(robot_id)
    if not robot:
        return render_template("not_found.html")

    runs = r.get_registry()['RUNS'].get_runs(robot_id)
    run_levels = [run['id'] for run in runs]

    # check if disqualifited and eligibility to advnace to next level
    eligibility = LevelProgressHandler.get_eligibility_for_next_run(
        runs, robot['level'])
    # get current best scores
    best_scores, attempted_levels, total_score, num_successful = (
        ScoreCalculator.get_best_scores(runs))
    return render_template(
        "robot.html",
        attempted_levels=attempted_levels,
        total_score=total_score,
        robot_id=robot_id,
        robot=robot,
        disqualified=eligibility['disqualified'],
        eligible=eligibility['can_level_up'],
        best_scores=best_scores,
        robot_runs=runs,
        applied_factors=[applied_factors(id, robot_id) for id in run_levels],
        inputs=inputs)
def robot_detail(robot_id, inputs=None):
    robot = r.get_registry()['ROBOTS'].get_robot(robot_id)
    if not robot:
        return render_template("not_found.html")

    runs = r.get_registry()['RUNS'].get_runs(robot_id)
    run_levels = [run['id'] for run in runs]

    # check if disqualifited and eligibility to advnace to next level
    eligibility = LevelProgressHandler.get_eligibility_for_next_run(
        runs, robot['level']
    )
    # get current best scores
    best_scores, attempted_levels, total_score, num_successful = (
        ScoreCalculator.get_best_scores(runs)
    )
    return render_template(
        "robot.html",
        attempted_levels=attempted_levels,
        total_score=total_score,
        robot_id=robot_id,
        robot=robot,
        disqualified=eligibility['disqualified'],
        eligible=eligibility['can_level_up'],
        best_scores=best_scores,
        robot_runs=runs,
        applied_factors=[applied_factors(id, robot_id) for id in run_levels],
        inputs=inputs
    )
def export_to_csv():
    divisions = ['junior', 'walking', 'high_school', 'senior']

    all_robots = {}

    for division in divisions:
        all_robots[division] = r.get_registry()['ROBOTS'].get_all_robots_division(division)

    si = StringIO.StringIO()
    cw = csv.writer(si)
    cw.writerow(['Rank', 'Division', 'Name', '# of Successful Runs',
                 'Current Level', 'LS1', 'LS2', 'LS3', 'TFS', 'From CT', 'From NA', 'Is unique'])

    for div in all_robots:
        for robot in all_robots[div]:
            runs = r.get_registry()['RUNS'].get_runs(robot['id'])
            # get current best scores
            best_scores, attempted_levels, total_score, num_successful = (
                ScoreCalculator.get_best_scores(runs)
            )
            robot.update(best_scores)
            robot['TFS'] = total_score
            robot['num_successful'] = num_successful
            # calculate lowes scores for each level and TFS, returns tuple
            robot['completed'] = attempted_levels

        # sort based on name then total score
        sorted_robots = sorted(
            list(all_robots[div]),
            key=lambda k: k['name']
        )
        sorted_robots = sorted(
            list(sorted_robots),
            key=lambda k: k['TFS']
        )

        for index, sorted_r in enumerate(sorted_robots, start=1):
            cw.writerow([
                index,
                sorted_r['division'],
                sorted_r['name'],
                sorted_r['num_successful'],
                sorted_r['level'],
                sorted_r['LS1'],
                sorted_r['LS2'],
                sorted_r['LS3'],
                sorted_r['TFS'],
                sorted_r['from_ct'],
                sorted_r['from_na'],
                sorted_r['is_unique']
            ])

        cw.writerow('\n')

    output = make_response(si.getvalue())
    si.close()
    output.headers["Content-Disposition"] = "attachment; filename=scoreboard.csv"
    output.headers["Content-type"] = "text/csv"
    return output
 def add_scoreboard_params(robots):
     # adds necessary parameters to be displayed on the scoreboard
     for robot in robots:
         runs = r.get_registry()['RUNS'].get_runs(robot['id'])
         best_scores, attempted_levels, total_score, num_successful = (
             ScoreCalculator.get_best_scores(runs)
         )
         robot.update(best_scores)
         robot['TFS'] = total_score
         robot['completed'] = attempted_levels
         robot['num_successful'] = num_successful
     return robots
Esempio n. 5
0
 def add_scoreboard_params(robots):
     # adds necessary parameters to be displayed on the scoreboard
     for robot in robots:
         runs = r.get_registry()['RUNS'].get_runs(robot['id'])
         best_scores, attempted_levels, total_score, num_successful = (
             ScoreCalculator.get_best_scores(runs)
         )
         robot.update(best_scores)
         robot['TFS'] = total_score
         robot['completed'] = attempted_levels
         robot['num_successful'] = num_successful
     return robots
def export_to_csv():
    divisions = ['junior', 'walking', 'high_school', 'senior']

    all_robots = {}

    for division in divisions:
        all_robots[division] = r.get_registry()['ROBOTS'].get_all_robots_division(division);

    si = StringIO.StringIO()
    cw = csv.writer(si)
    cw.writerow(['Rank', 'Division', 'Name', '# of Successful Runs',
                 'Current Level', 'LS1', 'LS2', 'LS3', 'TFS', 'Volume',
                 'From NA', 'From CT', 'Unique'])

    for div in all_robots:
        for robot in all_robots[div]:
            runs = r.get_registry()['RUNS'].get_runs(robot['id'])
            # get current best scores
            best_scores, attempted_levels, total_score, num_successful = (
                ScoreCalculator.get_best_scores(runs)
            )
            robot.update(best_scores)
            robot['TFS'] = total_score
            robot['num_successful'] = num_successful
            # calculate lowes scores for each level and TFS, returns tuple
            robot['completed'] = attempted_levels

        # sort based on name then total score
        sorted_robots = sorted(list(all_robots[div]), key=lambda k: k['name'])
        sorted_robots = sorted(list(sorted_robots), key=lambda k: k['TFS'])

        for index, sorted_r in enumerate(sorted_robots, start=1):
            cw.writerow([index, sorted_r['division'], sorted_r['name'], sorted_r['num_successful'],
                        sorted_r['level'], sorted_r['LS1'], sorted_r['LS2'], sorted_r['LS3'],
                         sorted_r['TFS'], sorted_r['volume'],
                         sorted_r['from_na'], sorted_r['from_ct'],
                         sorted_r['is_unique']])

        cw.writerow('\n')

    output = make_response(si.getvalue())
    si.close()
    output.headers["Content-Disposition"] = "attachment; filename=scoreboard.csv"
    output.headers["Content-type"] = "text/csv"
    return output
def robot_detail(robot_id, inputs=None):
    robot = r.get_registry()['ROBOTS'].get_robot(robot_id)
    if not robot:
        return render_template("not_found.html")

    runs = r.get_registry()['RUNS'].get_runs(robot_id)
    run_levels = [run['id'] for run in runs]

    # check if disqualifited and eligibility to advnace to next level
    eligibility = LevelProgressHandler.get_eligibility_for_next_run(
        runs, robot['level']
    )
    # get current best scores
    best_scores, attempted_levels, total_score, num_successful = (
        ScoreCalculator.get_best_scores(runs)
    )

    # check how many runs robot did on sunday (sunday = 1)
    # TODO: this logic needs to be rewritten after the competition
    sunday = 1
    filtered = filter_runs_day(runs, sunday)
    already_run_three = False
    if len(filtered) >= 3:
        already_run_three = True


    return render_template(
        "robot.html",
        attempted_levels=attempted_levels,
        total_score=total_score,
        robot_id=robot_id,
        robot=robot,
        disqualified=eligibility['disqualified'],
        eligible=eligibility['can_level_up'],
        best_scores=best_scores,
        robot_runs=runs,
        applied_factors=[applied_factors(id, robot_id) for id in run_levels],
        inputs=inputs,
        already_run_three=already_run_three
    )
Esempio n. 8
0
def robot_detail(robot_id, inputs=None):
    robot = r.get_registry()['ROBOTS'].get_robot(robot_id)
    if not robot:
        return render_template("not_found.html")

    runs = r.get_registry()['RUNS'].get_runs(robot_id)
    run_levels = [run['id'] for run in runs]

    # check if disqualifited and eligibility to advnace to next level
    eligibility = LevelProgressHandler.get_eligibility_for_next_run(
        runs, robot['level'])
    # get current best scores
    best_scores, attempted_levels, total_score, num_successful = (
        ScoreCalculator.get_best_scores(runs))

    # check how many runs robot did on sunday (sunday = 1)
    # TODO: this logic needs to be rewritten after the competition
    sunday = 1
    filtered = filter_runs_day(runs, sunday)
    already_run_three = False
    if len(filtered) >= 3:
        already_run_three = True

    return render_template(
        "robot.html",
        attempted_levels=attempted_levels,
        total_score=total_score,
        robot_id=robot_id,
        robot=robot,
        disqualified=eligibility['disqualified'],
        eligible=eligibility['can_level_up'],
        best_scores=best_scores,
        robot_runs=runs,
        applied_factors=[applied_factors(id, robot_id) for id in run_levels],
        inputs=inputs,
        already_run_three=already_run_three)