Esempio n. 1
0
def run(loc, topic, id):
    print("AC control Algorithm running")
    global display

    mess = {}
    mess['UserId'] = sys.argv[1]
    mess['AppName'] = sys.argv[2]
    mess['ServiceName'] = sys.argv[3]

    for val in communication_module.Sersor_Stream(topic, id):

        temp = int(val['data'])

        if temp <= 59 and temp >= 10:
            mess["ActionType"] = "Conrol"
            mess["Action"] = str('LOW_TEMP :' + (str(val['data'])))

        elif temp >= 60 and temp <= 100:
            mess["ActionType"] = "Conrol"
            mess["Action"] = str('NORMAL_TEMP :' + str(val['data']))

        elif temp >= 101 and temp <= 120:
            mess["ActionType"] = "Conrol"
            mess["Action"] = str('HIGH_TEMP :' + str(val['data']))

        display = mess["Action"]
        curpath = str(os.path.dirname(os.path.realpath(__file__)))
        file = open(curpath + "/display.txt", "w+")
        file.write(display)

        # print(mess["Action"])
        communication_module.RuntimeServer_to_ActionServer_Producer_interface(
            mess)
def run(topic, id, loc):
    # lis=[]

    # for val in communication_module.Sersor_Stream(topic,id):
    # 		lis.append(int(val['data']))
    lis = []
    mess = {}
    mess['UserID'] = sys.argv[1]
    mess['App_Name'] = sys.argv[2]
    mess['Action_type'] = sys.argv[3]
    mess['Output'] = None
    for val in communication_module.Sersor_Stream(topic, id):
        lis.append(int(val['data']))
        print(len(lis), val)
        if (len(lis) % 120 == 0):
            x = statistics.mean(lis)
            if x >= 35:
                mess['algorithm'] = str('algorithm1')
                mess['Action'] = str('OFF_AC_' + loc)
                #print("Sending",mess)
                communication_module.RuntimeServer_to_ActionServer_Producer_interface(
                    mess)
            elif x < 35 and x >= 25:
                mess['algorithm'] = str('algorithm1')
                mess['Action'] = None
                #print("Sending",mess)
                communication_module.RuntimeServer_to_ActionServer_Producer_interface(
                    mess)
            else:
                mess['algorithm'] = str('algorithm1')
                mess['Action'] = str('ON_AC_' + loc)
                #print("Sending",mess)
                communication_module.RuntimeServer_to_ActionServer_Producer_interface(
                    mess)
def run(loc, topic, id):

    lis = []
    mess = {}
    mess['UserId'] = sys.argv[1]
    mess['AppName'] = sys.argv[2]
    mess['ServiceName'] = sys.argv[3]

    global count
    count = 0
    print(topic, id)
    for val in communication_module.Sersor_Stream(topic, id):
        if int(val['data']) + 100 > 200:  #For 5 value > 200 F
            count += 1
            # print(len(lis),val)
            if (count >= 5):
                curpath = str(os.path.dirname(os.path.realpath(__file__)))
                cmd = "python3 '" + curpath + "/dashboard.py' &"
                os.system(cmd)
                mess["ActionType"] = "Control"
                mess["Output"] = str('ON_FIRE_ALRAM_' + loc)
                #print("Sending",mess)
                communication_module.RuntimeServer_to_ActionServer_Producer_interface(
                    mess)
        else:
            # count-=1
            if (count < 5):
                mess["ActionType"] = "Control"
                mess["Output"] = str('OFF_FIRE_ALRAM_' + loc)
                #print("Sending",mess)
                communication_module.RuntimeServer_to_ActionServer_Producer_interface(
                    mess)
Esempio n. 4
0
def run(loc, topic, id):
    global display
    print("Toxic level detection algorithm is running")
    curpath = str(os.path.dirname(os.path.realpath(__file__)))
    cmd = "python3 '" + curpath + "/dashboard.py' &"
    os.system(cmd)

    mess = {}
    mess['UserId'] = sys.argv[1]
    mess['AppName'] = sys.argv[2]
    mess['ServiceName'] = sys.argv[3]
    curpath = str(os.path.dirname(os.path.realpath(__file__)))

    for val in communication_module.Sersor_Stream(topic, id):

        scale = int(val['data'])

        if scale >= 3 and scale <= 6:
            mess["ActionType"] = "Control"
            mess["Output"] = str("Toxic content in air is moderate at " +
                                 str(loc) + " and scale value is" + str(scale))
            f = open(curpath + "/display.txt", 'w')
            f.write(mess["Output"])
            f.close()

        elif scale >= 1 and scale <= 2:
            mess["ActionType"] = "Control"
            mess["Output"] = str("Toxic content in air is very low at " +
                                 str(loc) + " and scale value is" + str(scale))
            f = open(curpath + "/display.txt", 'w')
            f.write(mess["Output"])
            f.close()

        elif scale >= 7 and scale <= 8:
            mess["ActionType"] = "Notification"
            mess["Action"] = ["email"]
            mess["Output"] = str("Toxic content in air is high " + str(loc) +
                                 " and scale value is" + str(scale))
            f = open(curpath + "/display.txt", 'w')
            f.write(mess["Output"])
            f.close()

        elif scale >= 9:
            mess["ActionType"] = "Notification"
            mess["Action"] = ["email"]
            mess["Output"] = str("Toxic content in air is very high " +
                                 str(loc) + " and scale value is" + str(scale))
            f = open(curpath + "/display.txt", 'w')
            f.write(mess["Output"])
            f.close()

        # print(mess["Action"])
        communication_module.RuntimeServer_to_ActionServer_Producer_interface(
            mess)
def run(loc,topic,id):
	print("Water level Algo Started",topic,id)
	curpath=str(os.path.dirname(os.path.realpath(__file__)))
	cmd="python3 '"+curpath+"/dashboard.py' &"
	os.system(cmd)

	mess={}
	mess['UserId']=sys.argv[1]
	mess['AppName']=sys.argv[2]
	mess['ServiceName']=sys.argv[3]

	for val in communication_module.Sersor_Stream(topic,id):
		# print(int(val['data']))
		if(int(val['data'])==1):
			mess["ActionType"]="Notification"
			mess["Action"]=["email"]
			status = "Overflow "
			mess["Output"]=str("Water Level Status at "+loc+" is "+status+" kindly take neccessary action")

			print("Action Initiated : - ",mess)

			f=open(curpath+"/display.txt",'w')
			f.write(mess["Output"])
			f.close()
			
			communication_module.RuntimeServer_to_ActionServer_Producer_interface(mess)

		elif(int(val['data'])==0):
			mess["ActionType"]="Control"
			mess["Action"]=["email"]
			status = "Normal "
			mess["Output"]=str("Water Level Status at "+loc+" is "+status+" kindly take neccessary action")

			print("Action Initiated : - ",mess)
			f=open(curpath+"/display.txt",'w')
			f.write(mess["Output"])
			f.close()
			communication_module.RuntimeServer_to_ActionServer_Producer_interface(mess)

		elif(int(val['data'])==2):
			mess["ActionType"]="Notification"
			mess["Action"]=["email"]
			status = " Quite Low "
			mess["Output"]=str("Water Level Status at "+loc+" is "+status+" kindly take neccessary action")

			print("Action Initiated : - ",mess)
			f=open(curpath+"/display.txt",'w')
			f.write(mess["Output"])
			f.close()
			communication_module.RuntimeServer_to_ActionServer_Producer_interface(mess)
Esempio n. 6
0
def run(loc, topic, id):
    print("Algo Started", topic, id)
    mess = {}
    mess['UserId'] = sys.argv[1]
    mess['AppName'] = sys.argv[2]
    mess['ServiceName'] = sys.argv[3]

    for val in communication_module.Sersor_Stream(topic, id):
        # print(int(val['data']))
        if (int(val['data']) == 1):
            mess["ActionType"] = "Notification"
            mess["Action"] = ["email", "notification"]
            mess["Output"] = str("Illegal Access Detection at " + loc)

            print("Action Initiated : - ", mess)
            communication_module.RuntimeServer_to_ActionServer_Producer_interface(
                mess)
def run(topic,id,loc):
	lis=[]
	for val in communication_module.Sersor_Stream(topic,id):
		lis.append(int(val['data']))

		if(len(lis)%120==0):
			x = statistics.mean(lis)
			if x>=35:
				mess={}
				mess['algorithm']=str('algorithm1')
				mess['command']=str('OFF_AC_'+loc)
				communication_module.Algorithm_to_ActionManager_Producer_interface(mess)
			elif x<35 and x>=25:
				mess={}
				mess['algorithm']=str('algorithm1')
				mess['command']=None
				communication_module.Algorithm_to_ActionManager_Producer_interface(mess)
			else:
				mess={}
				mess['algorithm']=str('algorithm1')
				mess['command']=str('ON_AC_'+loc)
				communication_module.Algorithm_to_ActionManager_Producer_interface(mess)
print("Algo Started")
# print("argsss",len(sys.argv))
# for i in range(sys.argv):
sensor_count = int(sys.argv[5])
print("sensor_ct", sensor_count)

sensor_data = []
x = 6
y = 7
for i in range(sensor_count):
    topic = sys.argv[x]
    id = sys.argv[y]
    x = x + 2
    y = y + 2
    # print("in 1st for loop:")
    for val in communication_module.Sersor_Stream(topic, id):
        print("val:::", val, type(val))
        val1 = val["data"]
        lis = val1.split(":")
        lis.append(id)
        #lis= [atnd, cap, senid]
        sensor_data.append(lis)
        break

read_init_data(sensor_data)
# print("init data readed sucess!!!")
# start_new_thread(threaded_cls_detaisl,())

# for i in range(len(sys.argv)):
# 	print(i,"=============",sys.argv[i])
x = 6
import communication_module
import sensor

print('Algorithm1')

for val in communication_module.Sersor_Stream('temperature'):
    print(val)