Ejemplo n.º 1
0
def assign_contract(agent_id, target_id, bounty):
    with connection.cursor() as cursor:
        cursor.execute(sql.ASSIGN_CONTRACT,
                       args={
                           'agent_id': agent_id,
                           'target_id': target_id,
                           'bounty': bounty
                       })
    connection.commit()
Ejemplo n.º 2
0
def get_available_targets_lookup():
    with connection.cursor() as cursor:
        cursor.execute(sql.GET_AVAILABLE_TARGETS_FOR_ALL_AGENTS)
        results = cursor.fetchall()

    return {
        agent_id: set(pt[1] for pt in possible_targets)
        for agent_id, possible_targets in groupby(results, key=lambda x: x[0])
    }
Ejemplo n.º 3
0
def create_agents(bucket, key):
    logger.info('Loading player data from s3://%s/%s', bucket, key)
    obj = s3.Object(bucket_name=bucket, key=key)
    lines = obj.get()['Body'].read().split('\n')
    data = [line for line in DictReader(lines)]

    logger.info('Inserting %s players', len(data))

    with connection.cursor() as cursor:
        cursor.executemany(sql.ADD_PLAYERS, data)
    connection.commit()

    logger.info('Player load complete')
Ejemplo n.º 4
0
def assign_codenames(agents_and_codenames):
    logger.info('Beginning codename assignment')
    case_clause_template = 'WHEN {agent_id} THEN "{codename}"'
    case_clauses = []
    agent_ids = []
    for agent, codename in agents_and_codenames:
        logger.info('Attempting to assign codename "%s" to agent %s', codename,
                    agent.id)
        agent_ids.append(agent.id)
        case_clauses.append(
            case_clause_template.format(agent_id=agent.id, codename=codename))

    case_clauses = ' '.join(case_clauses)

    update_sql = sql.ASSIGN_CODENAMES_TO_AGENTS.format(cases=case_clauses)
    with connection.cursor() as cursor:
        cursor.execute(update_sql, args={'agent_ids': agent_ids})
    connection.commit()

    logger.info('Codename assignment was successful')
Ejemplo n.º 5
0
def get_current_max_bounty():
    with connection.cursor() as cursor:
        cursor.execute(sql.GET_MAX_BOUNTY)
        results = cursor.fetchone()

    return results[0]
Ejemplo n.º 6
0
def assign_multiple_contracts(contract_params):
    with connection.cursor() as cursor:
        cursor.executemany(sql.ASSIGN_CONTRACT, args=contract_params)
    connection.commit()
Ejemplo n.º 7
0
def _get_existing_codenames():
    with connection.cursor() as cursor:
        cursor.execute(sql.GET_EXISITING_CODENAMES)
        return [row[0] for row in cursor.fetchall()]
Ejemplo n.º 8
0
def revive_assassinated_agents():
    logger.info('Reviving all assassinated agents')
    with connection.cursor() as cursor:
        cursor.execute(sql.REVIVE_ASSASSINATED_AGENTS)
    connection.commit()
    logger.info('Player revival was successful')
Ejemplo n.º 9
0
def get_assassinated_players():
    with connection.cursor() as cursor:
        cursor.execute(sql.GET_ASSASSINATED_PLAYERS)
        results = cursor.fetchall()

    return (Agent(*row) for row in results)
Ejemplo n.º 10
0
def get_all():
    with connection.cursor() as cursor:
        cursor.execute(sql.GET_ALL_AGENTS)
        results = cursor.fetchall()

    return (Agent(*row) for row in results)