def sendRequest(self, query):
        """
        Description : Accesses the new relic query end point and fetches the data

        Parameters : 1. self
                     2. query - to query the new relic data

        Return Value : Response of the New Relic Query
        """
        logging.debug("Getting daily data from New Relic API")
        

        #Accessing NewRelic API with Query
        try:
            
            data = {"nrql":query} 
            constants = Constants()
            response = requests.get(url = constants.NEWRELIC_API_ENDPOINT,headers= constants.HEADERS, params=data) 
           
        except requests.exceptions.Timeout as e:
            logging.error("Timeout Error: \n {0}".format(e))
        except requests.exceptions.TooManyRedirects as e:
            logging.error("Bad URL: \n {0}".format(e))
        except requests.exceptions.HTTPError as e:
            logging.error("HTTP Error: \n {0}".format(e))
        except requests.exceptions.RequestException as e:
            logging.error("Error occured while connecting to New Relic: \n {0}".format(e))

        return response
	def __init__(self):
		"""
		Description : Constructor to class FeedbackLoop, initializes the connection to COS

		Parameters : 1. self

		"""
		constants = Constants()
		self.client = ibm_boto3.client(service_name='s3',ibm_api_key_id=constants.API_KEY,ibm_auth_endpoint=constants.AUTH_ENDPOINT,config=Config(signature_version='oauth'),endpoint_url=constants.COS_API_ENDPOINT)
		column_names = ['Timestamp','CPU','Instances']
		util = COSUtils()
		self.bucketName = 'getcsvdata'
		self.data = {}
		self.score = {}
		self.modelSelector = {}
		self.response = {}
		for region in ['Dallas', 'London', 'Tokyo']:
			self.initialDataset = 'initial_'+region+'.csv'
			self.fetchedDataset = 'data_'+region+'.csv'
			
			self.data[region] = util.get_dataframe(column_names,  self.bucketName, self.initialDataset)
			self.data[region].columns = column_names

			self.data[region] = self.convertTimestampToFloat(self.data[region])
			self.modelSelector[region] = RegressionSelector()
			self.score[region] = self.getScore(self.data[region], region)['Best Score']
		logging.info("Score:" + str(self.score[region]))
		logging.debug("Response:")
		logging.debug(self.response)
예제 #3
0
    def __init__(self):
        """
        Description : Constructor to class COSUtils, initializes the connection to COS

        Parameters : 1. self

        """
        constants = Constants()
        self.client = ibm_boto3.client(
            service_name='s3',
            ibm_api_key_id=constants.API_KEY,
            ibm_auth_endpoint=constants.AUTH_ENDPOINT,
            config=Config(signature_version='oauth'),
            endpoint_url=constants.COS_API_ENDPOINT)
예제 #4
0
def create_app(platform_):

    # Load user settings and components
    user = UserContent()
    user_settings = user.get_user_settings()
    user_tabs = user.load_user_tabs()

    conf = Constants(
        user_settings["app_title"],
        user_settings["app_subtitle"],
        user_settings["contact_email"],
    )

    page_layout = AppLayout(
        conf.APP_TITLE,
        conf.APP_SUBTITLE,
        conf.PATH_LOGO,
        conf.EMAIL,
        conf.FOOTER_TEXT,
        conf.CONTACT_MAIL_SUBJECT,
        user_tabs,
    )
    page_layout.create_layout()

    # Create the app instance
    external_stylesheets = [
        'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css',
    ]

    app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
    app.title = conf.APP_TITLE
    app.config.suppress_callback_exceptions = True
    if platform_ == "local":
        requests_prefix = ''
        app.config.update({'requests_pathname_prefix': requests_prefix})
    else:
        requests_prefix = ''
    app.layout = page_layout.layout
    cc = CallbackControls(app)
    cc.load_tab_callbacks(user_tabs)
    return app
예제 #5
0
simplefilter(action='ignore', category=DeprecationWarning)
from numpy import array
import pandas as pd
import numpy as np
import os
from sklearn import metrics, svm
import threading
import time, json
import urllib
import csv
import datetime
from numpy.random import seed
import logging
seed(500)

constants = Constants()


class RegressionSelector():
    def __init__(self):
        """
		Description : Constructor to class RegressionSelector

		Parameters : 1. self

		"""
        self.bestModel = None
        self.models = None

    def getResponse(self):
        """
예제 #6
0
import tweepy
import logging
from app.config import create_api
from app.aws_services import AWSConnection
import time

from app.constants import Constants

from app.logger import LoggerService

ls = LoggerService()
_log = ls.get_logger()

con = Constants()
awsc = AWSConnection()

def follow_followers(api):
    _log.info("Retrieving and following followers")
    for follower in tweepy.Cursor(api.followers).items():
        if not follower.following:
            _log.info(f"Following {follower.name}")
            follower.follow()


def validate_friend(api, user):
    try:
        api.show_friendship(target_screen_name=user)
        _log.info(f'{user} exists!')
        return True
    except Exception as e:
        _log.error(f"User {user} does not exist. Response {e}", exc_info=True)