Ejemplo n.º 1
0
def round(round_id):
    round_puzzle_ids = ROUND_PUZZLE_MAP.get(round_id, []) + [round_id]

    round_visibility_async = cube.get_puzzle_visibility_async(app, round_id)
    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)
    puzzle_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, round_puzzle_ids)
    puzzle_properties_async = cube.get_all_puzzle_properties_for_list_async(
        app, round_puzzle_ids)

    round_visibility = round_visibility_async.result().json()
    if round_visibility['status'] not in ['UNLOCKED', 'SOLVED']:
        abort(403)

    core_display_data = make_core_display_data(core_visibilities_async,
                                               core_team_properties_async)
    puzzle_visibilities = {
        v["puzzleId"]: v
        for v in puzzle_visibilities_async.result().json().get(
            "visibilities", [])
    }
    puzzle_properties = {
        puzzle.get('puzzleId'): puzzle
        for puzzle in puzzle_properties_async.result().json().get(
            'puzzles', [])
    }

    with metrics.timer("present.round_render"):
        return render_template("rounds/%s.html" % round_id,
                               core_display_data=core_display_data,
                               round_id=round_id,
                               puzzle_properties=puzzle_properties,
                               puzzle_visibilities=puzzle_visibilities)
Ejemplo n.º 2
0
def activity_log():
    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)
    team_visibility_changes_async = cube.get_team_visibility_changes_async(app)
    team_submissions_async = cube.get_team_submissions_async(app)
    all_puzzles_async = cube.get_all_puzzle_properties_async(app)

    core_display_data = make_core_display_data(core_visibilities_async,
                                               core_team_properties_async)

    visibility_changes = [
        vc for vc in team_visibility_changes_async.result()
        if vc["status"] in ['UNLOCKED', 'SOLVED']
        and not vc["puzzleId"].startswith("event")
    ]
    activity_entries = visibility_changes + team_submissions_async.result()
    activity_entries.sort(key=lambda entry: entry["timestamp"], reverse=True)

    all_puzzles = {
        v["puzzleId"]: v
        for v in all_puzzles_async.result().json()["puzzles"]
    }

    return render_template("activity_log.html",
                           core_display_data=core_display_data,
                           activity_entries=activity_entries,
                           all_puzzles=all_puzzles)
Ejemplo n.º 3
0
def puzzle_list():
    if not cube.is_hunt_started_async(app).result():
        abort(403)

    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)
    all_visibilities_async = cube.get_puzzle_visibilities_async(app)
    all_puzzles_async = cube.get_all_puzzle_properties_async(app)

    core_display_data = make_core_display_data(core_visibilities_async,
                                               core_team_properties_async)
    all_visibilities = {
        v["puzzleId"]: v
        for v in all_visibilities_async.result().json()["visibilities"]
    }
    all_puzzles = {
        v["puzzleId"]: v
        for v in all_puzzles_async.result().json()["puzzles"]
    }

    with metrics.timer("present.puzzle_list_render"):
        return render_template("puzzle_list.html",
                               core_display_data=core_display_data,
                               all_visibilities=all_visibilities,
                               all_puzzles=all_puzzles,
                               round_puzzle_map=ROUND_PUZZLE_MAP)
Ejemplo n.º 4
0
def puzzle_solution(puzzle_id):
    if app.config["SITE_MODE"] != 'solution':
        abort(403)

    puzzle_visibility_async = cube.get_puzzle_visibility_async(app, puzzle_id)
    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)
    puzzle_async = cube.get_puzzle_async(app, puzzle_id)

    puzzle_visibility = puzzle_visibility_async.result().json()
    if puzzle_visibility['status'] not in ['UNLOCKED', 'SOLVED']:
        abort(403)

    core_display_data = make_core_display_data(core_visibilities_async,
                                               core_team_properties_async)
    puzzle = puzzle_async.result().json()
    canonical_puzzle_id = puzzle.get('puzzleId')
    puzzle_round_id = [
        r_id for r_id, round_puzzle_ids in ROUND_PUZZLE_MAP.iteritems()
        if canonical_puzzle_id in round_puzzle_ids
    ]
    puzzle_round_id = puzzle_round_id[0] if len(puzzle_round_id) > 0 else None

    with metrics.timer("present.puzzle_render"):
        return render_template("solutions/%s.html" % puzzle_id,
                               core_display_data=core_display_data,
                               puzzle_id=puzzle_id,
                               puzzle_round_id=puzzle_round_id,
                               puzzle=puzzle,
                               puzzle_visibility=puzzle_visibility)
Ejemplo n.º 5
0
def inventory():
    if not cube.is_hunt_started_async(app).result():
        abort(403)

    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)

    core_display_data = make_core_display_data(core_visibilities_async,
                                               core_team_properties_async)
    return render_template("inventory.html",
                           core_display_data=core_display_data)
Ejemplo n.º 6
0
def safety():
    is_hunt_started_async = cube.is_hunt_started_async(app)
    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)

    if is_hunt_started_async.result():
        core_display_data = make_core_display_data(core_visibilities_async,
                                                   core_team_properties_async)
        return render_template("safety.html",
                               core_display_data=core_display_data)
    else:
        return render_template("safety.html")
Ejemplo n.º 7
0
def index():
    if not cube.is_hunt_started_async(app).result():
        return prehunt_index()
    round_puzzle_ids = ROUND_PUZZLE_MAP.get('index')

    core_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, CHARACTER_IDS + QUEST_IDS + ['merchants', 'battle'])
    core_team_properties_async = cube.get_team_properties_async(app)
    puzzle_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, round_puzzle_ids)
    puzzle_properties_async = cube.get_all_puzzle_properties_for_list_async(
        app, round_puzzle_ids)

    core_display_data = make_core_display_data(core_visibilities_async,
                                               core_team_properties_async)
    puzzle_visibilities = {
        v["puzzleId"]: v
        for v in puzzle_visibilities_async.result().json().get(
            "visibilities", [])
    }
    puzzle_properties = {
        puzzle.get('puzzleId'): puzzle
        for puzzle in puzzle_properties_async.result().json().get(
            'puzzles', [])
    }
    visible_puzzle_ids = set([
        key for key in puzzle_visibilities
        if puzzle_visibilities.get(key, {}).get('status', '') != 'INVISIBLE'
    ])
    fog_number = len([map_item for map_item in \
        ['dynast','dungeon','thespians','bridge','criminal','minstrels','cube','warlord','rescue_the_linguist','rescue_the_chemist','rescue_the_economist','merchants','fortress']\
        if map_item in visible_puzzle_ids])

    with metrics.timer("present.index_render"):
        return render_template("index.html",
                               core_display_data=core_display_data,
                               visible_puzzle_ids=visible_puzzle_ids,
                               fog_number=fog_number,
                               puzzle_visibilities=puzzle_visibilities)
Ejemplo n.º 8
0
def bulk_team_action():
    if request.method == "POST":
        responses = []
        for team_id in request.form.getlist("team_ids"):
            if request.form.has_key("gold"):
                responses.append(cube.create_event_async(app, {
                    "eventType": "GrantGold",
                    "teamId": team_id,
                    "gold": request.form["gold"],
                }))
            elif request.form.has_key("solvePuzzle"):
                responses.append(cube.update_puzzle_visibility_async(
                    app,
                    team_id,
                    request.form["solvePuzzle"],
                    "SOLVED"))
            else:
                abort(400)
        for response in responses:
            response.result()

    teams = cube.get_teams(app)

    team_ids = [team["teamId"] for team in teams]
    team_ids.sort()

    team_names = {team["teamId"]: team.get("teamName","") for team in teams}

    team_gold = { team["teamId"]: team.get("teamProperties",{}).get("GoldProperty",{}).get("gold",0) for team in teams }

    team_visibility_futures = {}
    for team_id in team_ids:
        team_visibility_futures[team_id] = cube.get_puzzle_visibilities_for_list_async(
            app,
            ["eventa", "eventb", "eventc", "eventd"],
            team_id)

    team_visibilities = {}
    for team_id, future in team_visibility_futures.iteritems():
        visibilities = future.result().json()["visibilities"]
        team_visibilities[team_id] = { v["puzzleId"]: v for v in visibilities }

    return render_template(
        "bulk_team_action.html",
        team_ids=team_ids,
        team_names=team_names,
        team_gold=team_gold,
        team_visibilities=team_visibilities)
Ejemplo n.º 9
0
def index():
    core_team_properties_async = cube.get_team_properties_async(app)
    is_hunt_started_async = cube.is_hunt_started_async(app)

    core_display_data = make_core_display_data(core_team_properties_async)

    if not is_hunt_started_async.result():
        return prehunt_index(core_display_data=core_display_data)

    round_puzzle_ids = ROUND_PUZZLE_MAP.get('round1')

    puzzle_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, round_puzzle_ids)
    puzzle_properties_async = cube.get_all_puzzle_properties_for_list_async(
        app, round_puzzle_ids)

    puzzle_visibilities = {
        v["puzzleId"]: v
        for v in puzzle_visibilities_async.result().json().get(
            "visibilities", [])
    }
    puzzle_properties = {
        puzzle.get('puzzleId'): puzzle
        for puzzle in puzzle_properties_async.result().json().get(
            'puzzles', [])
    }

    with metrics.timer("present.index_render"):
        r = make_response(
            render_template("index.html",
                            core_display_data=core_display_data,
                            is_hunt_started=True,
                            puzzle_properties=puzzle_properties,
                            puzzle_visibilities=puzzle_visibilities))
        r.headers.set('Cache-Control',
                      'private, max-age=0, no-cache, no-store')
        return r
Ejemplo n.º 10
0
def objectives():
    is_hunt_started_async = cube.is_hunt_started_async(app)
    objective_visibilities_async = cube.get_puzzle_visibilities_for_list_async(
        app, [])
    puzzle_properties_async = cube.get_all_puzzle_properties_for_list_async(
        app, ALL_PUZZLES)
    core_team_properties_async = cube.get_team_properties_async(app)

    core_display_data = make_core_display_data(core_team_properties_async)

    if is_hunt_started_async.result():
        is_hunt_started = True
        objective_visibilities = {
            r['puzzleId']: r
            for r in objective_visibilities_async.result().json()
            ['visibilities']
        }
        puzzle_properties = {
            puzzle.get('puzzleId'): puzzle
            for puzzle in puzzle_properties_async.result().json().get(
                'puzzles', [])
        }
    else:
        is_hunt_started = False
        objective_visibilities = {}
        puzzle_properties = {}

    objective_visibilities = collections.defaultdict(
        lambda: {'status': 'INVISIBLE'}, objective_visibilities)
    statuses = {p: objective_visibilities[p]['status'] for p in []}
    answers = {
        p: ', '.join(objective_visibilities[p].get('solvedAnswers', []))
        for p in []
    }

    puzzle_properties = {
        puzzle.get('puzzleId'): puzzle
        for puzzle in puzzle_properties_async.result().json().get(
            'puzzles', [])
    }
    names = {
        p: puzzle_properties.get(p, {}).get('puzzleProperties',
                                            {}).get('DisplayNameProperty',
                                                    {}).get('displayName', '')
        for p in []
    }
    display_ids = {
        p: puzzle_properties.get(p, {}).get('puzzleProperties',
                                            {}).get('DisplayIdProperty',
                                                    {}).get('displayId', '')
        for p in []
    }

    def count_solved(puzzles):
        return sum(1 for p in puzzles if statuses[p] == 'SOLVED')

    # Much less messy to calculate these here than inside templates
    counts = {}

    r = make_response(
        render_template("mission_objectives.html",
                        core_display_data=core_display_data,
                        names=names,
                        display_ids=display_ids,
                        is_hunt_started=is_hunt_started,
                        counts=counts,
                        statuses=statuses,
                        answers=answers))
    r.headers.set('Cache-Control', 'private, max-age=0, no-cache, no-store')
    return r
Ejemplo n.º 11
0
def puzzle(puzzle_id):
    puzzle_visibility_async = cube.get_puzzle_visibility_async(app, puzzle_id)
    core_team_properties_async = cube.get_team_properties_async(app)
    puzzle_async = cube.get_puzzle_async(app, puzzle_id)

    puzzle_visibility = puzzle_visibility_async.result().json()
    if puzzle_visibility['status'] not in [
            'UNLOCKED', 'SOLVED'
    ] and app.config["SITE_MODE"] != 'solution':
        abort(403)

    interactions_and_finales_async = cube.get_all_puzzle_properties_for_list_async(
        app, [])
    interactions_finales = interactions_and_finales_async.result().json().get(
        "puzzles")
    interactions_finales = {v["puzzleId"]: v for v in interactions_finales}
    interactions_finales = [
        interactions_finales[interaction_finale].get(
            'puzzleProperties', {}).get('DisplayIdProperty',
                                        {}).get('displayId',
                                                interaction_finale)
        for interaction_finale in interactions_finales
    ]
    if puzzle_id in interactions_finales and app.config[
            "SITE_MODE"] != 'solution':
        abort(403)

    core_display_data = make_core_display_data(core_team_properties_async)
    puzzle = puzzle_async.result().json()

    # This pretends to be generic, but is actually just used for the Pokemon submetas
    feeders_solved = []
    feeder_properties = {}
    feeders = puzzle.get('puzzleProperties', {}).get('FeedersProperty',
                                                     {}).get('feeders', [])
    if feeders:
        feeder_properties_async = cube.get_all_puzzle_properties_for_list_async(
            app, feeders)
        feeder_visibility_async = cube.get_puzzle_visibilities_for_list_async(
            app, feeders)
        feeder_properties = {
            v['puzzleId']: v
            for v in feeder_properties_async.result().json().get(
                'puzzles', [])
        }
        feeders_solved = [
            v['puzzleId'] for v in feeder_visibility_async.result().json().get(
                'visibilities', []) if v['status'] == 'SOLVED'
        ]
        feeders_solved.sort(key=lambda puzzleId: feeder_properties[puzzleId].
                            get('SymbolProperty', {}).get('symbol', ''))

    canonical_puzzle_id = puzzle.get('puzzleId')
    puzzle_round_id = [
        r_id for r_id, round_puzzle_ids in ROUND_PUZZLE_MAP.iteritems()
        if canonical_puzzle_id in round_puzzle_ids
    ]
    puzzle_round_id = puzzle_round_id[0] if len(puzzle_round_id) > 0 else None
    emotions = puzzle.get('puzzleProperties', {}).get('EmotionsProperty',
                                                      {}).get('emotions', [])

    pages_without_solutions_async = cube.get_all_puzzle_properties_for_list_async(
        app, [])
    pages_without_solutions = [
        v.get('puzzleProperties', {}).get('DisplayIdProperty',
                                          {}).get('displayId', '')
        for v in pages_without_solutions_async.result().json().get(
            "puzzles", [])
    ]

    with metrics.timer("present.puzzle_render"):
        r = make_response(
            render_template("puzzles/%s.html" % puzzle_id,
                            core_display_data=core_display_data,
                            is_hunt_started=True,
                            puzzle_id=puzzle_id,
                            puzzle_round_id=puzzle_round_id,
                            emotions=emotions,
                            puzzle=puzzle,
                            interactions_finales=interactions_finales,
                            puzzle_visibility=puzzle_visibility,
                            pages_without_solutions=pages_without_solutions,
                            feeders_solved=feeders_solved,
                            feeder_count=len(feeders),
                            feeder_properties=feeder_properties))
        r.headers.set('Cache-Control',
                      'private, max-age=0, no-cache, no-store')
        return r
Ejemplo n.º 12
0
def bulk_team_action():
    if request.method == "POST":
        responses = []
        for team_id in request.form.getlist("team_ids"):
            if request.form.has_key("brainpower"):
                responses.append(
                    cube.create_event_async(
                        app, {
                            "eventType": "GrantScore",
                            "teamId": team_id,
                            "scoreType": "BRAINPOWER",
                            "scoreAmount": request.form["brainpower"],
                        }))
            elif request.form.has_key("buzzyBucks"):
                responses.append(
                    cube.create_event_async(
                        app, {
                            "eventType": "GrantScore",
                            "teamId": team_id,
                            "scoreType": "BUZZY_BUCKS",
                            "scoreAmount": request.form["buzzyBucks"],
                        }))
            elif request.form.has_key("solvePuzzle"):
                responses.append(
                    cube.update_puzzle_visibility_async(
                        app, team_id, request.form["solvePuzzle"], "SOLVED"))
            else:
                abort(400)
        for response in responses:
            response.result()

    teams = cube.get_teams(app)

    team_ids = [team["teamId"] for team in teams]
    team_ids.sort()

    team_names = {team["teamId"]: team.get("teamName", "") for team in teams}

    team_scores = {
        team["teamId"]: team.get("teamProperties",
                                 {}).get("ScoresProperty",
                                         {}).get("scores", {})
        for team in teams
    }

    team_visibility_futures = {}
    for team_id in team_ids:
        team_visibility_futures[
            team_id] = cube.get_puzzle_visibilities_for_list_async(
                app, round_puzzle_map.EVENTS, team_id)

    team_visibilities = {}
    for team_id, future in team_visibility_futures.iteritems():
        visibilities = future.result().json()["visibilities"]
        team_visibilities[team_id] = {v["puzzleId"]: v for v in visibilities}

    return render_template("bulk_team_action.html",
                           team_ids=team_ids,
                           team_names=team_names,
                           team_scores=team_scores,
                           team_visibilities=team_visibilities,
                           round_puzzle_map=round_puzzle_map)