def getDevice(cluster): sql = "select subgroup_name from " + cluster subcluster_list = [] sql_result = pydb.db_get(sql, "Group_data") for item in sql_result: subcluster_list.append(item[0]) status_sum = 0 device_sum = 0 for item in subcluster_list: sql = "select e_status from " + item sql_result = pydb.db_get(sql, cluster) for core in sql_result: status_sum += int(core[0]) device_sum += 1 return device_sum, status_sum
def get_AcDev(group, sub_group): """ 获取所有在线设备的ip地址 """ sql = "select e_ip, e_class from " + sub_group + " where e_status = 1" cur_result = pydb.db_get(sql, group) return cur_result
def getValue(): cluster_id_list = json.loads(request.form['cluster_id']) cluster_id = cluster_id_list[0] sql = "select group_value from group_table where group_name = '" + cluster_id + "'" value = pydb.db_get(sql, "Group_data")[0][0] response = value return response, 200
def getSubgroup(): sql = "select group_name from group_table" cluster_list = [] sql_result = pydb.db_get(sql, "Group_data") for item in sql_result: cluster_list.append(item[0]) return cluster_list
def get_subGroup(): sql = "select subgroup_name from " + os.getenv('GROUP_NAME') cur_result = pydb.db_get(sql, 'Group_data') subGroup_list = [] if cur_result: for item in cur_result: subGroup_list.append(item[0]) return subGroup_list
def getAcDevIp(sub_group): sql = "select e_ip from " + sub_group + " where e_status = 1" ip_result = pydb.db_get(sql, os.getenv('GROUP_NAME')) ip_list = [] if ip_result: for item in ip_result: ip_list.append(item[0]) return ip_list
def get_AcDevIp(group, sub_group): """ 获取所有在线设备的ip地址 """ sql = "select equip_ip from " + sub_group + " where equip_status =1" cur_result = pydb.db_get(sql, group) ip_list = [] if cur_result: for item in cur_result: ip_list.append(item[0]) return ip_list
def handle(self): logger = logging.getLogger("TCPServer") command = self.request.recv(1024).decode() if command == "health_command": # 暂时不用 """ 查询群体状态模块 """ sql = "select health_degree from attributes where group_name = '" + "G_001" + "'" dresp = pydb.db_get(sql, "Group_data")[0][0] elif command == 'on' or command == 'off': """ 调用模块 """ # 新建字典,存储各个子群体的指令处理结果 subGroup_list = get_subGroup() # 子群体列表 if len(subGroup_list) > 0: for sub_group in subGroup_list: sub_data = groupCommandProcess( sub_group, command) # 对于所有子群体,得到子群体的指令处理结果 #dresp[sub_group] = sub_data dresp = sub_data else: dresp = "No sub_group available" sql = "update group_table set group_value = '" + str( dresp) + "' where group_name = '" + os.getenv( 'GROUP_NAME') + "'" pydb.db_exe(sql, "Group_data") else: """ 查询模块 """ # 新建字典,存储各个子群体的信息处理结果 subGroup_list = get_subGroup() # 子群体列表 if len(subGroup_list) > 0: for sub_group in subGroup_list: sub_data = groupDataProcess( sub_group) # 对于所有子群体,得到子群体的信息处理结果 #dresp[sub_group] = sub_data dresp = sub_data else: dresp = "No sub_group available" sql = "update group_table set group_value = '" + str( dresp) + "' where group_name = '" + os.getenv( 'GROUP_NAME') + "'" pydb.db_exe(sql, "Group_data") jresp = json.dumps(dresp) self.request.sendall(jresp.encode())
def class_api(cluster_id): sql = "select group_class from group_table where group_name = '" + cluster_id + "'" cluster_class = pydb.db_get(sql, 'Group_data')[0][0] return cluster_class
import pydb import time sql_popu = "select population_density from attributes where group_name = '" + "G_001" + "'" sql_birth = "select online_number from attributes where group_name = '" + "G_001" + "'" sql_death = "select offline_number from attributes where group_name = '" + "G_001" + "'" if __name__ == "__main__": while True: popu1 = pydb.db_get(sql_popu, "Group_data")[0][0] bir1 = pydb.db_get(sql_birth, "Group_data")[0][0] dea1 = pydb.db_get(sql_death, "Group_data")[0][0] time.sleep(600) popu2 = pydb.db_get(sql_popu, "Group_data")[0][0] time.sleep(600) popu3 = pydb.db_get(sql_popu, "Group_data")[0][0] time.sleep(600) popu4 = pydb.db_get(sql_popu, "Group_data")[0][0] time.sleep(600) popu5 = pydb.db_get(sql_popu, "Group_data")[0][0] time.sleep(600) popu6 = pydb.db_get(sql_popu, "Group_data")[0][0] bir2 = pydb.db_get(sql_birth, "Group_data")[0][0] dea2 = pydb.db_get(sql_death, "Group_data")[0][0] average_popu = (popu1 + popu2 + popu3 + popu4 + popu5 + popu6)/6