def update_api_documentation(api_doc: ApiDoc, doc: dict, portal_name: str):
    """Updates an existing Portal API Documentation to be in sync with the latest API spec and
       also includes any changes done in the JSON file."""
    print(
        "Updating API documentation on portal '{}' for spec '{}' with doc_id {}"
        .format(portal_name, api_doc.spec_name, api_doc.doc_id))

    response = REQUEST.put(
        'https://apigee.com/portals/api/sites/{}/apidocs/{}/snapshot'.format(
            portal_name, api_doc.doc_id))

    print("snapshot response code: {} and content : {}".format(
        response.status_code, response.content))

    if response.status_code != 200:
        raise RestException(utils.print_error(response))

    response = REQUEST.put(
        'https://apigee.com/portals/api/sites/{}/apidocs/{}'.format(
            portal_name, api_doc.doc_id),
        json=doc)

    if response.status_code != 200:
        raise RestException(utils.print_error(response))

    print(
        "Successfully updated API documentation on portal '{}' for spec '{}'".
        format(portal_name, api_doc.spec_name))
Example #2
0
def add_menu_item(session, portal_id: str, org_name: str, name: str,
                  menu_url: str, page_id: int, priority: int, indented: bool,
                  menu_item_type: MenuItemType):
    """Add a menu item to the portal."""
    url = 'https://apigee.com/portals/api/sites/{}/menuitems'.format(portal_id)

    menu_type_id = menu_item_type.menuTypeId
    css_class = menu_item_type.name

    data = {
        'cssClass': css_class,
        'menuTypeId': menu_type_id,
        'name': name,
        'orgname': org_name,
        'pageId': page_id,
        'priority': priority,
        'url': menu_url,
        'isNested': indented
    }
    response = session.post(url, json=data)

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    menu_item_id = response.json()['data']['menuItemId']
    print('Successfully added menu_item:' + name + ' page to Apigee portal!')
Example #3
0
def update_theme(session, portal_id: str, theme: Theme):
    """Updates theme."""
    url = 'https://apigee.com/portals/api/sites/{}/customcss'.format(portal_id)

    response = session.put(url, data=json.dumps(theme.__dict__))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully uploaded theme to Apigee portal!')
def add_update_remote_page(session, portal_id: str, org_name: str,
                           page_id: int, friendly_id: str, content: str):
    """Upload an html page to the portal."""
    if page_id is None:
        url = 'https://apigee.com/portals/api/sites/{}/pages'.format(portal_id)

        data = {
            'showActionButtons': 'false',
            'type': 'GENERIC',
            'generatedContent': [],
            'name': re.sub('([-]+)', r' ', friendly_id).lower().title(),
            'friendlyId': friendly_id,
            'description': '',
            'orgname': org_name
        }
        response = session.post(url, json=data)

        if response.status_code != 200:
            raise Exception(utils.print_error(response))

        page_id = response.json()['data']['id']
        print('Successfully added ' + friendly_id + ' page to Apigee portal!')

    #Update the content of the page
    content_url = 'https://apigee.com/portals/api/sites/{}/pages/{}/content'.format(
        portal_id, str(page_id))
    put_response = session.put(content_url,
                               json={
                                   'orgname': org_name,
                                   'content': content
                               })

    if put_response.status_code != 200:
        raise Exception(utils.print_error(put_response))

    publish_url = 'https://apigee.com/portals/api/sites/{}/pages/{}/publish'.format(
        portal_id, str(page_id))
    publish_response = session.post(publish_url, json={'orgname': org_name})

    if publish_response.status_code != 200:
        raise Exception(utils.print_error(publish_response))

    print('Successfully published ' + friendly_id + ' page to Apigee portal!')
Example #5
0
def publish_theme(session, portal_id: str, org_name: str):
    """Publish all changes to the theme theme."""
    url = 'https://apigee.com/portals/api/sites/{}/customcss/publish'.format(portal_id)

    response = session.post(url, json={'orgname': org_name})

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully published theme to Apigee portal!')
Example #6
0
def publish_menu_items(session, org_name: str, portal_id: str):
    """Rest call to pulish any changes done to menu items."""
    publish_url = 'https://apigee.com/portals/api/sites/{}/menuitems/publish'.format(
        portal_id)
    publish_response = session.post(publish_url, json={'orgname': org_name})

    if publish_response.status_code != 200:
        raise Exception(utils.print_error(publish_response))

    print('Successfully published all menu items to Apigee portal!')
def delete_remote_page(session, portal_id: str, page_id: int):
    """Delete a page from the remote site."""
    url = 'https://apigee.com/portals/api/sites/{}/pages/{}'.format(
        portal_id, page_id)

    response = session.delete(url)

    if response.status_code != 200:
        print(utils.print_error(response))
    else:
        print('Successfully deleted ' + str(page_id) + ' from Apigee portal!')
Example #8
0
def main():

    searcher = Searcher()
    docs = None
    qe = QueryExecutor(searcher)

    for line in fileinput.input():
        # TODO всю строку сразу в uft-8 и lower
        line = line.replace("\n", "")
        request = line.split('.....')[0]
        request = unicode(request, 'utf-8').lower()

        doc_result = qe.query(request)
        print line
        print len(doc_result)
        if docs is None:
            docs = load_obj("documents")
        for doc_id in doc_result:
            print_error(doc_id)
            print docs[doc_id]
def add_remote_asset(session, portal_id: str, local_file_path: str):
    """Upload an asset to the portal."""
    url = 'https://apigee.com/portals/api/sites/{}/file/post'.format(portal_id)

    # Make sure the the dictionary's key is 'file'.
    file = open(local_file_path, 'rb')
    response = session.post(url, files={'file': file})

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully uploaded ' + local_file_path + ' to Apigee portal!')
def update_portal(session, portal: Portal, new_settings: dict):
    """Updates a portal to the current organization."""

    # Update description.
    url = str.format('https://apigee.com/portals/api/sites/{}/portal',
                     portal.id)

    portal.description = new_settings["description"]

    data = json.dumps(portal.__dict__)

    response = session.put(url, data=data)

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    response = response.json()['data']

    print('Portal description successfully added at: ' +
          response['defaultDomain'])

    # Update analytics.
    analytics = {
        "analyticsScript": new_settings["analyticsScript"],
        "analyticsTrackingId": new_settings["analyticsTrackingId"],
        "orgname": portal.orgName
    }

    analytics_url = str.format(
        'https://apigee.com/portals/api/sites/{}/site/analytics', portal.id)
    data = json.dumps(analytics)

    response = session.post(analytics_url, data=data)

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Portal analytics successfully updated at: ' + portal.defaultDomain)
def get_query_status(session, query_url: str) -> Query:
    """Get the current status of an Apigee async query."""

    response = session.get(
        'https://api.enterprise.apigee.com/v1{}'.format(query_url))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    data = response.json()
    query = Query(data['self'], data['state'], data['created'])
    print('Query status: {}.'.format(query.state))

    return query
Example #12
0
def delete_all_menu_items(session, portal_id: str):
    """Retrieves a list of current menu items."""
    response = session.get(
        'https://apigee.com/portals/api/sites/{}/menuitems'.format(portal_id))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched all menu items.')

    menu_items = response.json()['data']

    # Delete all menu items from the remote site.
    for menu_item in menu_items:
        url = 'https://apigee.com/portals/api/sites/{}/menuitems/{}'.format(
            portal_id, str(menu_item['menuItemId']))

        response = session.delete(url)

        if response.status_code != 200:
            print(utils.print_error(response))
        else:
            print('Successfully deleted menu_item:' +
                  str(menu_item['menuItemId']) + ' from Apigee portal!')
def delete_remote_asset(session, portal_id: str, org_name: str,
                        file_name: str):
    """Delete an asset from the remote site."""
    url = 'https://apigee.com/portals/api/sites/{}/file/delete'.format(
        portal_id)

    response = session.post(url,
                            json={
                                'orgname': org_name,
                                'filename': file_name
                            })

    if response.status_code != 200:
        print(utils.print_error(response))
    else:
        print('Successfully deleted ' + file_name + ' from Apigee portal!')
def documentation_exists(spec_name: str, portal_name: str) -> ApiDoc:
    """Retrieves a list of API Products exposed on a portal and checks if
       there is an existing one using the given spec name."""

    response = REQUEST.get(
        'https://apigee.com/portals/api/sites/{}/apidocs'.format(portal_name))

    if response.status_code != 200:
        raise RestException(utils.print_error(response))

    for doc in response.json()['data']:
        # Spec ID returned by the API is actually the spec name.
        if doc['specId'] == spec_name:
            return ApiDoc(doc['id'], doc['specId'], doc['specContent'])

    return None
Example #15
0
def get_current_theme(session, portal_id: str) -> Theme:
    """Retrieves the current theme settings for the current portal."""
    response = session.get(
        'https://apigee.com/portals/api/sites/{}/customcss'.format(portal_id))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched Theme.')

    theme = response.json()['data']
    return Theme(theme['variablesPublished'],
                 theme['overridesPublished'],
                 theme['customScssPublished'],
                 theme['logoUrlPublished'],
                 theme['mobileLogoUrlPublished'],
                 theme['faviconUrlPublished'])
def spec_exists(org_name: str, spec_name: str) -> bool:
    """Checks whether a given spec exists inside a given Apigee organization.
       Returns the spec ID if it exists."""
    response = REQUEST.get(
        'https://apigee.com/dapi/api/organizations/{}/specs/folder/home'.
        format(org_name))

    if response.status_code != 200:
        raise RestException(utils.print_error(response))

    print('Successfully fetched OpenAPI Specs from Apigee.')

    for spec in response.json()['contents']:
        if spec['name'] == spec_name:
            return spec['id']

    return None
def generate_async_query(session, org_name: str, env: str, data: str) -> Query:
    """Instructs Apigee to start processing an async query with the data provided."""

    response = session.post(
        'https://api.enterprise.apigee.com/v1/organizations/{}/environments/{}/queries'
        .format(org_name, env),
        json=data)

    if response.status_code != 201:
        raise Exception(utils.print_error(response))

    data = response.json()
    query = Query(data['self'], data['state'], data['created'])

    print('Successfully created an async query. Query status: {}.'.format(
        query.state))

    return query
def create_api_documentation(doc: dict, portal_name: str):
    """Creates documentation in the given Apigee API Portal
       with the specified details in the JSON file."""

    spec_id = doc['specId']

    print("Creating API documentation on portal '{}' for spec '{}'".format(
        portal_name, spec_id))

    response = REQUEST.post(
        'https://apigee.com/portals/api/sites/{}/apidocs'.format(portal_name),
        json=doc)

    if response.status_code != 200:
        raise RestException(utils.print_error(response))

    print(
        "Successfully created API documentation on portal '{}' for spec '{}'".
        format(portal_name, spec_id))
def get_query_result(session, query_url: str, output_path=os.getcwd()) -> str:
    """Get the Apigee async query result in zip format. This is then extracted
    and the output is saved as '.csv.gz' either in the current directory or 
    in the one provided."""

    response = session.get(
        'https://api.enterprise.apigee.com/v1{}/result'.format(query_url))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched query result.')

    z = zipfile.ZipFile(io.BytesIO(response.content))
    z.extractall(output_path)

    location = output_path + '/' + z.filelist[0].filename
    print('File stored in: {}'.format(location))

    return location
Example #20
0
def get_all_menu_item_types(session, portal_id: str) -> {}:
    """Retrieves a list of all menu items types.  These are usually primary and footer."""

    response = session.get(
        'https://apigee.com/portals/api/sites/{}/menutypes'.format(portal_id))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched all menu items.')

    all_menu_types = response.json()['data']

    menu_items = {}

    for list_item in all_menu_types:
        menu_items[list_item['friendlyId']] = MenuItemType(
            list_item['friendlyId'], list_item['menuTypeId'],
            list_item['name'])

    return menu_items
def get_remote_pages(session, portal_id: str) -> {}:
    """Retrieves a list of current pages."""

    response = session.get(
        'https://apigee.com/portals/api/sites/{}/pages'.format(portal_id))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched all pages.')

    all_pages = response.json()['data']

    pages = {}

    for list_item in all_pages:
        pages[list_item['friendlyId']] = Page(list_item['content'],
                                              list_item['description'],
                                              list_item['friendlyId'],
                                              list_item['id'],
                                              list_item['name'])

    return pages
def add_portal(session, org_name: str, portal_name: str,
               description: str) -> Portal:
    """Adds a portal to the current organization."""
    url = 'https://apigee.com/portals/api/sites'

    data = {
        'name': portal_name,
        'description': description,
        'id': '',
        'orgName': org_name,
        'analyticsScript': '',
        'analyticsTrackingId': '',
        'customDomain': '',
        'currentDomain': '',
        'lastPublished': 0,
        'idpEnabled': False,
        'portalVersion': 2,
        'migrationSrcSiteId': '',
        'migrationDestSiteId': '',
        'teams': [],
        'zoneId': ''
    }
    response = session.post(url, json=data)

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    response = response.json()['data']

    print('Portal successfully added at: ' + response['defaultDomain'])

    return Portal(response['id'], response['name'], response['orgName'],
                  response['description'], response['analyticsScript'],
                  response['analyticsTrackingId'], response['customDomain'],
                  response['currentDomain'], response['defaultDomain'],
                  response['idpEnabled'], response['portalVersion'],
                  response['teams'])
def get_all_portals(session, org_name: str) -> {}:
    """Retrieves a list of current pages."""
    response = session.get(
        'https://apigee.com/portals/api/sites?orgname={}'.format(org_name))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched all portals.')

    data = response.json()['data']

    all_portals = {}

    for list_item in data:
        all_portals[list_item['name']] = Portal(
            list_item['id'], list_item['name'], list_item['orgName'],
            list_item['description'], list_item['analyticsScript'],
            list_item['analyticsTrackingId'], list_item['customDomain'],
            list_item['currentDomain'], list_item['defaultDomain'],
            list_item['idpEnabled'], list_item['portalVersion'],
            list_item['teams'])

    return all_portals
def get_remote_assets(session, portal_id: str) -> {}:
    """Retrieves a list of current assets."""

    response = session.get(
        'https://apigee.com/portals/api/sites/{}/file/list'.format(portal_id))

    if response.status_code != 200:
        raise Exception(utils.print_error(response))

    print('Successfully fetched all assets.')

    fetched_assets = response.json()['data']

    assets = {}

    for list_item in fetched_assets:
        assets[list_item['filename']] = Asset(
            list_item['filename'], list_item['fullUrl'],
            list_item['extension'], list_item['relUrl'], list_item['thumbUrl'],
            list_item['width'], list_item['height'], list_item['size'],
            list_item['modified'], list_item['image'],
            list_item['versionedRelUrl'])

    return assets
Example #25
0
        world_fpath, subj_fpath, peds_fpath = world.get_paths()

        subject = ACTOR.format("subject", subj_fpath)
        # nm[-1] gives the pedestrian number; nm ~= P1, P0, ..
        pedestrians = " ".join([ACTOR.format(nm[-1], txt) for (nm, txt) in peds_fpath])

        try:
            BackgroundTask(
                "sphinx {} {} {} {}".format(world_fpath, DRONE_FPATH, subject, pedestrians),
                log=True, log_file="", wait=5
            )

            BackgroundTask("roscore", log=True, log_file="", wait=5)
            
            BackgroundTask(
                "roslaunch bebop_driver bebop_node.launch",
                log=True, log_file="", wait=5
            )
            
            RunTask("rostopic pub --once /bebop/takeoff std_msgs/Empty", wait=5)

            for i in range(5):
                RunTask("rostopic pub --once /bebop/cmd_vel geometry_msgs/Twist {}".format(RANDOM_HEIGHT))

            # Run until CTRL+C is pressed (presumably at the end of the simulation)
            MasterNode(CONFIG)

        except KeyboardInterrupt as e:
            print_error("CTRL+C has been pressed! Exiting")
Example #26
0
    def colour_code_usa_country(self,
                                data,
                                title="Title",
                                desc=None,
                                level='county'):
        """
        add colours to the us map at a chosen level

        :param data: dict with category names as the keys
        :param title: tile of the plot
        :param desc: description to be added to the plot
        :param level: level at which we have to fill colors county or state
        :return:
        """
        base_map = self._initialize_map()
        categories = data.keys()
        assert len(categories) < 5, "Cannot handle more than 5 categories"
        category_colour = {
            category: colour
            for category, colour in zip(
                categories, self.available_colours[:len(categories)])
        }

        # get current axes instance
        ax = plt.gca()

        # sets the colour of the county based on its category, if no category is given for a county then its colour is
        # white as white is the default colour assigned.
        if level == 'county':
            level_info = base_map.counties_info
            level_xy = base_map.counties
        elif level == 'state':
            level_info = base_map.states_info
            level_xy = base_map.states
        else:
            print_error(error='level')

        for level_index, level_info in enumerate(level_info):
            seg = level_xy[level_index]
            st_code = level_info['STATEFP']
            fp_code = level_info['COUNTYFP']
            for category in categories:
                if (st_code, fp_code) in data[category]:
                    poly = Polygon(seg, facecolor=category_colour[category])
                    ax.add_patch(poly)
                    break
                else:
                    poly = Polygon(seg, facecolor=self.available_colours[-1])
                    ax.add_patch(poly)

        patch_list = [
            Patch(color=category_colour[category],
                  label=str(category) + " " + str(len(data[category])))
            for category in categories
        ] + [Patch(color=self.available_colours[-1])]

        legend = plt.legend(handles=patch_list)
        legend.get_frame().set_color('grey')

        title = plt.title(title)
        title.set_color('grey')

        if desc is not None:
            plt.figtext(x=0.5,
                        y=0,
                        s=desc,
                        wrap=True,
                        horizontalalignment='center',
                        fontsize=8)

        plt.show()
#X_train, y_train =  correcao_data(X_train) , correcao_data(y_train)
#X_test, y_test = correcao_data(X_test) , correcao_data(y_test)

model_x.fit(X_train, y_train[:, 0])
_y_pred_x = model_x.predict(X_test)

model_y.fit(X_train, y_train[:, 1])
_y_pred_y = model_y.predict(X_test)

y_pred = np.vstack((_y_pred_x, _y_pred_y))
y_pred = y_pred.T

test = np.vstack((test, y_test))
pred = np.vstack((pred, y_pred))

print_error(test, pred)
metrica(test, pred)
#%%

_resultTrain_x = model_x.predict(X_train)
_resultTrain_y = model_y.predict(X_train)
resultTrain = np.vstack((_resultTrain_x, _resultTrain_y))
resultTrain = resultTrain.T

matriz = np.concatenate((resultTrain, y_train), axis=1)
matriz2 = np.concatenate((pred, test), axis=1)

erro_euclideano_data(matriz, matriz2)

#%% Testar com videos -- Correção
## Aqui será treinado um frame por vez e utilizado a respota para o frame seguinte