def get(): tags = [ {"name": "YEAR", "address": "%MW0", "type": "value", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "MONTH", "address": "%MW1", "type": "value", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "DAY", "address": "%MW2", "type": "value", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "HOUR", "address": "%MW3", "type": "value", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "MINUTE", "address": "%MW4", "type": "value", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "SECOND", "address": "%MW5", "type": "value", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "ALARM_MINUTE", "address": "%MW4:X0", "type": "alarm", "controller_ip": "192.168.0.1", "installation":"66002174487292"}, {"name": "WARNING_SECOND", "address": "%MW5:X1", "type": "warning", "controller_ip": "192.168.0.1", "installation":"66002174487292"} ] res = [] for tag in tags: res.append(tagHandler.insert(tag)) for i in range(0,255): addr_num = i % 12 name = "gen_tag_%s"%(i,) address = "%%MW%s" % (addr_num,) type = "value" controller_ip = "192.168.0.1" installation = "66002174487292" gen_tag = {"name": name, "address": address, "type": type, "controller_ip": controller_ip, "installation": installation} res.append(tagHandler.insert(gen_tag)) if not (False in res or None in res): return OkResponse("Successfully added the new tag") else: return ConflictResponse("Could not insert the tag for that controller/installation/customer")
def get(): d2 = datetime.now() res = [] for i in range(4, 9): name = "customer-%d" % (i,) customer = {"name":name} res.append(customerHandler.insert(customer)) for j in range(0, 5): installation_name = "installation-%d" % (j,) serial_number = "%s66002174487%d" % (customer.get('name'),j) installation = {"name":installation_name, "serial_number":serial_number, "customer": i} res.append(installationHandler.register(serial_number, "", "")) installationHandler.update_installation(installation) for k in range(0, 5): ip = "192.168.0.0.%d" % (k,) controller_name = "controller-%d" % (k,) controller = {"ip":ip, "installation": serial_number, "name":controller_name} res.append(controllerHandler.insert(controller)) for l in range(0, 100): address = "%%MW%d" % (l,) tag_name = "LOAD_%d"% (l,) tag = {"controller_ip":ip, "installation":serial_number, "type":"value", "address": address, "name": tag_name} res.append(tagHandler.insert(tag, True)) tag['time'] = d2 tag['value'] = str(l) res.append(logHandler.create_log_entry(tag, serial_number)) if not (False in res or None in res): return OkResponse("Successfully added the data") else: return ConflictResponse("Could not insert the data..")
def handleInsert(msg): table, data, installation = msg['table'], json.loads(msg['data']), msg['installation'] if table == 'tags': if not tagHandler.insert(data): LOG.error("Failed to insert a new tag!") else: print("ERROR: Unsupported table: %s" % (table)) return True
def post(tag): res = tagHandler.insert(tag) if res: return OkResponse("Successfully added the new tag") else: return ConflictResponse("Could not insert the tag for that controller/installation/customer")