class derivedKPI(object):
    """ Class to implement derived KPIs calculation"""
    
    def __init__(self):
        """ Initialize  frequently used parameters"""
        file_name = os.path.basename(__file__).split('.')[0]
        self.logger = log_function(file_name)
        self.config_obj = Config()
        user_authentication = self.config_obj.user_authentication()
        gateway = self.config_obj.gateway()
        derived_KPI = self.config_obj.derived_KPI()
        self.auth_URL = user_authentication['Auth_URL']
        self.derivedKPI_url = derived_KPI['DerivedKPI_url']
        self.derivedKPI_fetch_interval = derived_KPI['DerivedKPI_fetch_interval']
        self.access_key = user_authentication['access_key']
        self.user_key = user_authentication['user_key']
        self.user_id = user_authentication['user_id']
        self.token = user_authentication['token']
        self.application_id = user_authentication['application_id']
        self.auth_password = user_authentication['password']
        self.gateway_id = gateway['gateway_id']
        self.redis_obj_perf_data = redis_conn(db_name = 'REDIS_PERF_DATA')
        redis_obj_derived_kpi_data = redis_conn(db_name ='REDIS_DERIVED_KPI')
        try :
            self.api_response = eval(redis_obj_derived_kpi_data.get("Derived_KPI"))
        except Exception,error :
            self.api_response = None
        self.redis_obj_derived_kpi_data = redis_conn(db_name ='REDIS_DERIVED_KPI')
 def __init__(self):
     """
     From config file, get and initialization all variables.
     """
     file_name = os.path.basename(__file__).split('.')[0]
     self.logger = log_function(file_name)
     self.redis_obj_register = redis_conn(db_name='REDIS_REGISTER')
     self.config_obj = Config()
 def __init__(self):
     file_name = os.path.basename(__file__).split('.')[0]
     #self.logger = log_function(file_name)
     self.config_obj = Config()
     iothub = self.config_obj.iothub()
     self.IoTHub_IP = iothub['IP']
     self.IoTHub_port = iothub['Port']
     self.publisher = False
     self.derivedKPI_obj = derivedKPI()
     self.redis_obj_perf_data = redis_conn('REDIS_PERF_DATA')
     connection_lost = self.config_obj.wait_for_connection()
     self.DataSource = connection_lost['data_source']
     self.ServiceName = connection_lost['service_name']
Ejemplo n.º 4
0
'''
Created on 20-Dec-2016

@author: TERAMATRIX/siddhika.nag

Script to format data as recognized by xFusion Platform and
store in in-memory DB for further computation
'''
from logger import log_function
from datetime import datetime
import os
from IotGateway.connection import redis_conn
from IotGateway.config import Config
file_name = (os.path.basename(__file__)).split('.')[0]
redis_obj_perf_data = redis_conn('REDIS_PERF_DATA')
logger = log_function(file_name)

#Python class to format data
class Formatter():
    
    def __init__(self):
        self.config_obj = Config()
        self.restrict_data = self.config_obj.gateway()['restrict_data']

    def format_data(self,formatted_data,device_id = None,service_name = None, data_source = None,\
                     current_value = None,check_timestamp= None,sys_timestamp = None,\
                     is_lat = False, is_long = False,is_host_state = False,\
                      on_state_value = None, off_state_value = None):
        
        """
        Format data in list of JSON format including keys for 
Ejemplo n.º 5
0
from dateutil.parser import parse

file_name = os.path.basename(__file__).split('.')[0]
from logger import log_function

logger = log_function(file_name)
#haversine used for calculate distance between two lat_lng
from haversine import haversine

# SDK Imports
from IotGateway.publishData.publisher import PublisherIOTHub
from IotGateway.registerDevice import registration
from IotGateway.protocol.data_formatter import Formatter
from IotGateway.connection import redis_conn

redis_obj_perf_data_register = redis_conn(db_name='REDIS_REGISTER')
redis_obj_perf_data = redis_conn('REDIS_PERF_DATA')
registrationObj = registration.registration()
formatter_obj = Formatter()
pub_obj = PublisherIOTHub()
host = '192.168.1.38'
port = 9000

threadcounter = 0
count = 0


class service(SocketServer.BaseRequestHandler):
    def __init__(self, request, client_address, server):
        SocketServer.BaseRequestHandler.__init__(self, request, client_address,
                                                 server)