def __init__(self, gamma_initial_value, beta_initial_value, eps=1e-5, momentum=0.9): ''' This layer is inherited from the Layer class in utils.py. ''' super(BatchNormalization, self).__init__() self.params = {} self.eps = eps self.momentum = momentum self.running_mean = self.running_var = np.zeros_like(gamma_initial_value) self.params['gamma'] = Parameter('gamma', gamma_initial_value) self.params['beta'] = Parameter('beta', beta_initial_value)
def __init__(self, initial_value_w, initial_value_b, reg=0.): ''' This layer is inherited from the class Layer in utils.py. initial_value_w: The inital value of weights initial_value_b: The initial value of biases reg: Regularization coefficient or strength used for L2-regularization Parameter class (in utils.py) is used for defining paramters ''' super(FullyConnected, self).__init__() self.reg = reg self.params = {} self.params['w'] = Parameter('w', initial_value_w) self.params['b'] = Parameter('b', initial_value_b)
def onMotion(self): # users = self.dbconn.users.find({"active":1},{"userid":1}) # users_account = self.dbconn.users_account.find({"type":"%s"%self.name,"userid":{"$in":users["userid"]}}) users = self.dbconn.users.find({"active":1},{"userid":1,"_id":0}) for user in users: users_account = self.dbconn.users_account.find({"active":1,"type":"%s" % self.name,"userid":{"$in":[user["userid"]]}}) for account in users_account: self.sendMessage(account["account_id"], Parameter.getValue(self.dbconn,"alarm_message"))
def __init__(self, config): super(MotionSensor, self).__init__() self.active = True self.config = config self.callback = {} self.counter = 0 self.params = {} self.Pin = config["pin"] self.dbconn = config["dbconn"] self.params["gpio_setup"] = "in" self.ghandler = GPIOHandler(self.Pin.split(","),self.params,gpio.PUD_DOWN) self.ghandler.Add_Event_Handler(pin=self.Pin.split(","),gpiosetup=gpio.BOTH,callback=self.OnMotion,bounce_time=50) buzzerpin = Parameter.getValuebyFieldname(self.dbconn,"sensor_motion","buzzer") # print buzzerpin self.params["gpio_setup"] = "out" self.buzzerHandler = GPIOHandler(buzzerpin.split(","),self.params)
def onMotion(self): # users = self.dbconn.users.find({"active":1},{"userid":1}) # users_account = self.dbconn.users_account.find({"type":"%s"%self.name,"userid":{"$in":users["userid"]}}) users = self.dbconn.users.find({"active": 1}, {"userid": 1, "_id": 0}) for user in users: users_account = self.dbconn.users_account.find({ "active": 1, "type": "%s" % self.name, "userid": { "$in": [user["userid"]] } }) for account in users_account: self.sendMessage( account["account_id"], Parameter.getValue(self.dbconn, "alarm_message"))
def __init__(self, config): super(MotionSensor, self).__init__() self.active = True self.config = config self.callback = {} self.counter = 0 self.params = {} self.Pin = config["pin"] self.dbconn = config["dbconn"] self.params["gpio_setup"] = "in" self.ghandler = GPIOHandler(self.Pin.split(","), self.params, gpio.PUD_DOWN) self.ghandler.Add_Event_Handler(pin=self.Pin.split(","), gpiosetup=gpio.BOTH, callback=self.OnMotion, bounce_time=50) buzzerpin = Parameter.getValuebyFieldname(self.dbconn, "sensor_motion", "buzzer") # print buzzerpin self.params["gpio_setup"] = "out" self.buzzerHandler = GPIOHandler(buzzerpin.split(","), self.params)
import sys import os sys.path.append("backend/gateway/") sys.path.append("backend/") sys.path.append("utils/") from utils import Parameter import utils from telegw import ryTelegramGw from pymongo import MongoClient from sensor import MotionSensor import json with open("config.json") as jsonf: cfg = json.load(jsonf) client = MongoClient() db = client.ramey # # config = {} cfg["pin"] = Parameter.getValue(db, "sensor_motion") cfg["dbconn"] = db motion = MotionSensor(cfg) utils.newThread(motion.Execute) cfg["name"] = "telegram" bot = ryTelegramGw(cfg, db, motion) bot.connect()
import sys import os sys.path.append("backend/gateway/") sys.path.append("backend/") sys.path.append("utils/") from utils import Parameter import utils from telegw import ryTelegramGw from pymongo import MongoClient from sensor import MotionSensor import json with open("config.json") as jsonf: cfg = json.load(jsonf) client = MongoClient() db = client.ramey # # config = {} cfg["pin"] = Parameter.getValue(db,"sensor_motion") cfg["dbconn"] = db motion = MotionSensor(cfg) utils.newThread(motion.Execute) cfg["name"] = "telegram" bot = ryTelegramGw(cfg,db,motion) bot.connect()