Commit 7d2bf082 authored by 张晓彤's avatar 张晓彤

数据库迁移优化

parent c6d18b36
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
"excavator_target_mass": 5000 "excavator_target_mass": 5000
}, },
"mysql": { "mssql": {
"host": "192.168.9.152", "host": "192.168.88.52",
"port": "3306", "port": "1433",
"user": "root", "user": "sa",
"password": "Huituo@123", "password": "Huituo@123",
"database": "waytous" "database": "waytous"
}, },
"postgresql": { "postgresql": {
"host": "192.168.9.152", "host": "192.168.9.197",
"port": "5432", "port": "5432",
"user": "postgres", "user": "postgres",
"password": "Huituo@123", "password": "Huituo@123",
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
}, },
"redis": { "redis": {
"host": "192.168.9.152", "host": "192.168.9.197",
"password": "Huituo@123" "password": "Huituo@123"
} }
} }
\ No newline at end of file
...@@ -323,116 +323,116 @@ class DispatchInfo: ...@@ -323,116 +323,116 @@ class DispatchInfo:
cls.load_area_uuid_to_index_dict = {} cls.load_area_uuid_to_index_dict = {}
cls.unload_area_uuid_to_index_dict = {} cls.unload_area_uuid_to_index_dict = {}
# try: try:
groups = cls.group_excavator_dict.keys() groups = cls.group_excavator_dict.keys()
for item in groups: for item in groups:
try: try:
# 每个组的 excavator_id 及对应 load_area_id # 每个组的 excavator_id 及对应 load_area_id
excavator_ids = cls.group_excavator_dict[item] excavator_ids = cls.group_excavator_dict[item]
load_areas = [] load_areas = []
for excavator_id in excavator_ids: for excavator_id in excavator_ids:
load_areas.append(cls.excavator_load_dict[excavator_id]) load_areas.append(cls.excavator_load_dict[excavator_id])
# 每个组的unload_areas # 每个组的unload_areas
unload_areas = cls.group_unload_area_dict[item] unload_areas = cls.group_unload_area_dict[item]
except Exception as es: except Exception as es:
logger.error("装卸载区统计异常") logger.error("装卸载区统计异常")
logger.error(es) logger.error(es)
group_excavator_uuid_to_index = {} group_excavator_uuid_to_index = {}
group_dump_uuid_to_index = {} group_dump_uuid_to_index = {}
group_load_area_uuid_to_index = {} group_load_area_uuid_to_index = {}
group_unload_area_uuid_to_index = {} group_unload_area_uuid_to_index = {}
try: try:
# # unload->load distance # # unload->load distance
# unload_load_distance = np.zeros((len(unload_areas), len(load_areas))) # unload_load_distance = np.zeros((len(unload_areas), len(load_areas)))
# for truck_id in range(len(unload_areas)): # for truck_id in range(len(unload_areas)):
# for j in range(len(load_areas)): # for j in range(len(load_areas)):
# distance = int(session_postgre.query(WalkTime).filter_by(unload_area_id=unload_areas[truck_id], load_area_id=load_areas[j]).first().to_load_distance) # distance = int(session_postgre.query(WalkTime).filter_by(unload_area_id=unload_areas[truck_id], load_area_id=load_areas[j]).first().to_load_distance)
# unload_load_distance[truck_id][j] = distance # unload_load_distance[truck_id][j] = distance
# cls.load_distance[item] = unload_load_distance # cls.load_distance[item] = unload_load_distance
group_excavator_count = 0 group_excavator_count = 0
group_dump_count = 0
group_load_area_count = 0
group_unload_area_count = 0
# unload->load distance
unload_load_distance = np.zeros((len(cls.group_dump_dict[item]), len(cls.group_excavator_dict[item])))
for excavator_id in cls.group_excavator_dict[item]:
group_dump_count = 0 group_dump_count = 0
group_load_area_count = 0
group_unload_area_count = 0 group_unload_area_count = 0
for dump_id in cls.group_dump_dict[item]:
unload_area_id = cls.dump_unload_area_dict[dump_id] # unload->load distance
load_area_id = cls.excavator_load_dict[excavator_id] unload_load_distance = np.zeros((len(cls.group_dump_dict[item]), len(cls.group_excavator_dict[item])))
distance = int(session_postgre.query(WalkTime).filter_by( for excavator_id in cls.group_excavator_dict[item]:
unload_area_id=unload_area_id, group_dump_count = 0
load_area_id=load_area_id).first().to_load_distance) group_unload_area_count = 0
for dump_id in cls.group_dump_dict[item]:
unload_load_distance[group_dump_count][group_excavator_count] = distance unload_area_id = cls.dump_unload_area_dict[dump_id]
load_area_id = cls.excavator_load_dict[excavator_id]
if excavator_id not in group_excavator_uuid_to_index: distance = int(session_postgre.query(WalkTime).filter_by(
group_excavator_uuid_to_index[excavator_id] = group_excavator_count unload_area_id=unload_area_id,
load_area_id=load_area_id).first().to_load_distance)
if dump_id not in group_dump_uuid_to_index:
group_dump_uuid_to_index[dump_id] = group_dump_count unload_load_distance[group_dump_count][group_excavator_count] = distance
if load_area_id not in group_load_area_uuid_to_index: if excavator_id not in group_excavator_uuid_to_index:
group_load_area_uuid_to_index[load_area_id] = group_load_area_count group_excavator_uuid_to_index[excavator_id] = group_excavator_count
if unload_area_id not in group_unload_area_uuid_to_index: if dump_id not in group_dump_uuid_to_index:
group_unload_area_uuid_to_index[unload_area_id] = group_unload_area_count group_dump_uuid_to_index[dump_id] = group_dump_count
group_excavator_uuid_to_index = bidict(group_excavator_uuid_to_index) if load_area_id not in group_load_area_uuid_to_index:
group_dump_uuid_to_index = bidict(group_dump_uuid_to_index) group_load_area_uuid_to_index[load_area_id] = group_load_area_count
group_load_area_uuid_to_index = bidict(group_load_area_uuid_to_index)
group_unload_area_uuid_to_index = bidict(group_unload_area_uuid_to_index) if unload_area_id not in group_unload_area_uuid_to_index:
group_unload_area_uuid_to_index[unload_area_id] = group_unload_area_count
cls.excavator_uuid_to_index_dict[item] = group_excavator_uuid_to_index
cls.dump_uuid_to_index_dict[item] = group_dump_uuid_to_index group_dump_count += 1
cls.load_area_uuid_to_index_dict[item] = group_load_area_uuid_to_index group_unload_area_count += 1
cls.unload_area_uuid_to_index_dict[item] = group_unload_area_uuid_to_index
group_excavator_count += 1
group_dump_count += 1 group_load_area_count += 1
group_unload_area_count += 1
group_excavator_uuid_to_index = bidict(group_excavator_uuid_to_index)
group_excavator_count += 1 group_dump_uuid_to_index = bidict(group_dump_uuid_to_index)
group_load_area_count += 1 group_load_area_uuid_to_index = bidict(group_load_area_uuid_to_index)
group_unload_area_uuid_to_index = bidict(group_unload_area_uuid_to_index)
cls.load_distance[item] = unload_load_distance
cls.excavator_uuid_to_index_dict[item] = group_excavator_uuid_to_index
except Exception as es: cls.dump_uuid_to_index_dict[item] = group_dump_uuid_to_index
logger.warning(f'{item} 分组装载路网异常') cls.load_area_uuid_to_index_dict[item] = group_load_area_uuid_to_index
cls.load_distance[item] = np.full((len(unload_areas), len(load_areas)), 10000) cls.unload_area_uuid_to_index_dict[item] = group_unload_area_uuid_to_index
logger.warning(es)
session_postgre.rollback() cls.load_distance[item] = unload_load_distance
session_mysql.rollback()
except Exception as es:
try: logger.warning(f'{item} 分组装载路网异常')
cls.load_distance[item] = np.full((len(unload_areas), len(load_areas)), 10000)
# load->unload distance logger.warning(es)
load_unload_distance = np.zeros((len(load_areas), len(unload_areas))) session_postgre.rollback()
for i in range(len(load_areas)): session_mysql.rollback()
for j in range(len(unload_areas)):
distance = int(session_postgre.query(WalkTime).filter_by(load_area_id=load_areas[i], unload_area_id=unload_areas[j]).first().to_unload_distance) try:
load_unload_distance[i][j] = distance
cls.unload_distance[item] = load_unload_distance # load->unload distance
load_unload_distance = np.zeros((len(load_areas), len(unload_areas)))
except Exception as es: for i in range(len(load_areas)):
logger.warning(f'{item} 分组卸载路网异常') for j in range(len(unload_areas)):
cls.unload_distance[item] = np.full((len(load_areas), len(unload_areas)), 10000) distance = int(session_postgre.query(WalkTime).filter_by(load_area_id=load_areas[i], unload_area_id=unload_areas[j]).first().to_unload_distance)
logger.warning(es) load_unload_distance[i][j] = distance
session_postgre.rollback() cls.unload_distance[item] = load_unload_distance
session_mysql.rollback()
except Exception as es:
# except Exception as es: logger.warning(f'{item} 分组卸载路网异常')
# logger.error("路网距离更新异常-调度部分和路网部分不一致") cls.unload_distance[item] = np.full((len(load_areas), len(unload_areas)), 10000)
# logger.error(es) logger.warning(es)
session_postgre.rollback()
session_mysql.rollback()
except Exception as es:
logger.error("路网距离更新异常-调度部分和路网部分不一致")
logger.error(es)
# @classmethod # @classmethod
# def update_device_dict(cls): # def update_device_dict(cls):
......
...@@ -86,7 +86,7 @@ def build_truck_uuid_name_map(): ...@@ -86,7 +86,7 @@ def build_truck_uuid_name_map():
try: try:
for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=1).all(): for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=1).all():
truck_id = item.EQUIPMENT_ID truck_id = str(item.EQUIPMENT_ID)
truck_name = item.EQUIPMENT_NAME.encode("latin-1").decode("GBK", "ignore") truck_name = item.EQUIPMENT_NAME.encode("latin-1").decode("GBK", "ignore")
truck_name_to_uuid_dict[truck_name] = truck_id truck_name_to_uuid_dict[truck_name] = truck_id
...@@ -108,7 +108,7 @@ def build_equipment_uuid_name_map(): ...@@ -108,7 +108,7 @@ def build_equipment_uuid_name_map():
try: try:
for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=2).all(): for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=2).all():
truck_id = item.EQUIPMENT_ID truck_id = str(item.EQUIPMENT_ID)
truck_name = item.EQUIPMENT_NAME truck_name = item.EQUIPMENT_NAME
excavator_uuid_to_name_dict[truck_id] = truck_name excavator_uuid_to_name_dict[truck_id] = truck_name
...@@ -122,7 +122,7 @@ def build_equipment_uuid_name_map(): ...@@ -122,7 +122,7 @@ def build_equipment_uuid_name_map():
try: try:
for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=3).all(): for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=3).all():
truck_id = item.EQUIPMENT_ID truck_id = str(item.EQUIPMENT_ID)
truck_name = item.EQUIPMENT_NAME truck_name = item.EQUIPMENT_NAME
dump_uuid_to_name_dict[truck_id] = truck_name dump_uuid_to_name_dict[truck_id] = truck_name
...@@ -245,7 +245,7 @@ def update_total_truck(): ...@@ -245,7 +245,7 @@ def update_total_truck():
# if is_online: # if is_online:
# truck_list.append(item.id) # truck_list.append(item.id)
for item in query: for item in query:
truck_list.append(item.EQUIPMENT_ID) truck_list.append(str(item.EQUIPMENT_ID))
if len(truck_list) < 1: if len(truck_list) < 1:
raise Exception("无矿卡设备可用-矿卡集合读取异常") raise Exception("无矿卡设备可用-矿卡集合读取异常")
......
...@@ -185,7 +185,7 @@ class ExcavatorInfo(WalkManage): ...@@ -185,7 +185,7 @@ class ExcavatorInfo(WalkManage):
try: try:
load_ability = session_mysql.query(EquipmentSpec.MINING_ABILILTY).\ load_ability = session_mysql.query(EquipmentSpec.MINING_ABILILTY).\
join(Equipment, Equipment.EQUIPMENT_MODEL_ID == EquipmentSpec.EQUIPMENT_MODEL_ID).\ join(Equipment, Equipment.EQUIPMENT_MODEL_ID == EquipmentSpec.EQUIPMENT_MODEL_ID).\
filter(Equipment.EQUIPMENT_ID == self.excavator_index_to_uuid_dict[excavator_index]).first() filter(Equipment.EQUIPMENT_ID == int(self.excavator_index_to_uuid_dict[excavator_index])).first()
self.excavator_strength[excavator_index] = load_ability.MINING_ABILILTY self.excavator_strength[excavator_index] = load_ability.MINING_ABILILTY
# if load_ability.mining_abililty < 200: # if load_ability.mining_abililty < 200:
......
...@@ -140,35 +140,24 @@ class TruckInfo(WalkManage): ...@@ -140,35 +140,24 @@ class TruckInfo(WalkManage):
def update_truck_current_task(self): def update_truck_current_task(self):
self.truck_current_task = {} self.truck_current_task = {}
self.truck_current_state = {} self.truck_current_state = {}
device_name_set = redis2.keys()
truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict") truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict")
for item in device_name_set: for truck_id in self.dynamic_truck_set:
# try: try:
item = item.decode(encoding="utf-8") # truck_id = truck_id.decode(encoding="utf-8")
key_value_dict = redis2.hgetall(item) # reids str可以自动转为bytes key_value_dict = redis2.hgetall(truck_id) # reids str可以自动转为bytes
if str_to_byte("type") in key_value_dict:
device_type = int(key_value_dict[str_to_byte("type")]) device_type = int(key_value_dict[str_to_byte("type")])
else: if device_type == 1:
continue if truck_id in self.dynamic_truck_set:
if device_type == 1:
if item not in truck_name_to_uuid_dict:
continue
else:
if truck_name_to_uuid_dict[item] in self.dynamic_truck_set:
# currentTask = int(key_value_dict[str_to_byte("currentTask")]) # currentTask = int(key_value_dict[str_to_byte("currentTask")])
currentTask = int(byte_to_str(key_value_dict[str_to_byte("currentTask")])) currentTask = int(byte_to_str(key_value_dict[str_to_byte("currentTask")]))
self.truck_current_task[ self.truck_current_task[truck_id] = currentTask
truck_name_to_uuid_dict[item]
] = currentTask
currentState = int(float(byte_to_str(key_value_dict[str_to_byte("state")]))) currentState = int(float(byte_to_str(key_value_dict[str_to_byte("state")])))
self.truck_current_state[ self.truck_current_state[truck_id] = currentState
truck_name_to_uuid_dict[item] except Exception as es:
] = currentState self.logger.error("读取矿卡任务异常-reids读取异常")
# except Exception as es: self.logger.error(es)
# self.logger.error("读取矿卡任务异常-reids读取异常")
# self.logger.error(es)
self.logger.info("矿卡当前任务:") self.logger.info("矿卡当前任务:")
self.logger.info(self.truck_current_task) self.logger.info(self.truck_current_task)
...@@ -240,80 +229,81 @@ class TruckInfo(WalkManage): ...@@ -240,80 +229,81 @@ class TruckInfo(WalkManage):
self.relative_last_load_time = {} self.relative_last_load_time = {}
self.relative_last_unload_time = {} self.relative_last_unload_time = {}
try: # try:
truck_uuid_to_name_dict = get_value("truck_uuid_to_name_dict") for truck_id in self.dynamic_truck_set:
for item in self.dynamic_truck_set: # truck_name = truck_uuid_to_name_dict[item]
key_value_dict = redis2.hgetall(truck_uuid_to_name_dict[item]) key_value_dict = redis2.hgetall(truck_id)
device_type = int(key_value_dict[str_to_byte("type")]) device_type = int(key_value_dict[str_to_byte("type")])
# 判断是否为矿卡 # 判断是否为矿卡
if device_type == 1: if device_type == 1:
task = self.truck_current_task[item] print(self.truck_current_task)
if task in [3, 4, 5]: # 矿卡重载行驶或仍未出场 task = self.truck_current_task[truck_id]
if str_to_byte("lastLoadTime") in key_value_dict.keys(): # 若最后装载时间存在 if task in [3, 4, 5]: # 矿卡重载行驶或仍未出场
last_load_time_tmp = eval(byte_to_str(key_value_dict[str_to_byte("lastLoadTime")])) if str_to_byte("lastLoadTime") in key_value_dict.keys(): # 若最后装载时间存在
tmp_time = datetime.strptime(last_load_time_tmp, "%Y-%m-%d %H:%M:%S") last_load_time_tmp = eval(byte_to_str(key_value_dict[str_to_byte("lastLoadTime")]))
if tmp_time > datetime.strptime("2000-01-01 01:01:01", "%Y-%m-%d %H:%M:%S"): # 若最后装载时间异常 tmp_time = datetime.strptime(last_load_time_tmp, "%Y-%m-%d %H:%M:%S")
self.last_load_time[item] = tmp_time if tmp_time > datetime.strptime("2000-01-01 01:01:01", "%Y-%m-%d %H:%M:%S"): # 若最后装载时间异常
else: self.last_load_time[truck_id] = tmp_time
self.last_load_time[item] = datetime.now()
# redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastLoadTime"),
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
self.logger.info("lastLoadTime is Error")
else: else:
self.last_load_time[item] = datetime.now() self.last_load_time[truck_id] = datetime.now()
# redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastLoadTime"), # redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastLoadTime"),
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"") # "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
self.logger.info("lastLoadTime is None") self.logger.info("lastLoadTime is Error")
self.relative_last_load_time[item] = float( else:
(self.last_load_time[item] - self.start_time) self.last_load_time[truck_id] = datetime.now()
/ timedelta(hours=0, minutes=1, seconds=0) # redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastLoadTime"),
) # "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
# print("相对last_load_time", self.relative_last_load_time[item]) self.logger.info("lastLoadTime is None")
self.logger.info("相对last_load_time") self.relative_last_load_time[truck_id] = float(
self.logger.info(self.relative_last_load_time[item]) (self.last_load_time[truck_id] - self.start_time)
if task in [0, 1, 2]: # 矿卡空载行驶或仍未出场 / timedelta(hours=0, minutes=1, seconds=0)
if str_to_byte("lastUnloadTime") in key_value_dict.keys(): )
last_unload_time_tmp = eval(key_value_dict[str_to_byte("lastUnloadTime")]) # print("相对last_load_time", self.relative_last_load_time[item])
tmp_time = datetime.strptime(last_unload_time_tmp, "%Y-%m-%d %H:%M:%S") self.logger.info("相对last_load_time")
if tmp_time > datetime.strptime("2000-01-01 01:01:01", "%Y-%m-%d %H:%M:%S"): self.logger.info(self.relative_last_load_time[truck_id])
self.last_unload_time[item] = tmp_time if task in [0, 1, 2]: # 矿卡空载行驶或仍未出场
else: if str_to_byte("lastUnloadTime") in key_value_dict.keys():
self.last_unload_time[item] = datetime.now() last_unload_time_tmp = eval(key_value_dict[str_to_byte("lastUnloadTime")])
# redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"), tmp_time = datetime.strptime(last_unload_time_tmp, "%Y-%m-%d %H:%M:%S")
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"") if tmp_time > datetime.strptime("2000-01-01 01:01:01", "%Y-%m-%d %H:%M:%S"):
self.logger.info("lastUnloadTime is Error") self.last_unload_time[truck_id] = tmp_time
else: else:
self.last_unload_time[item] = datetime.now() self.last_unload_time[truck_id] = datetime.now()
# key_value_dict[str_to_byte("lastUnloadTime")] = datetime.now().strftime(
# "%b %d, %Y %I:%M:%S %p"
# )
# redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"), # redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"),
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"") # "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
self.logger.info("lastUnloadTime is None") self.logger.info("lastUnloadTime is Error")
self.relative_last_unload_time[item] = float( else:
(self.last_unload_time[item] - self.start_time) self.last_unload_time[truck_id] = datetime.now()
/ timedelta(hours=0, minutes=1, seconds=0) # key_value_dict[str_to_byte("lastUnloadTime")] = datetime.now().strftime(
) # "%b %d, %Y %I:%M:%S %p"
# print("相对last_unload_time", self.relative_last_unload_time[item]) # )
self.logger.info("相对last_unload_time") # redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"),
self.logger.info(self.relative_last_unload_time[item]) # "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
elif task == -2: self.logger.info("lastUnloadTime is None")
# print(datetime.now()) self.relative_last_unload_time[truck_id] = float(
self.last_unload_time[item] = datetime.now() (self.last_unload_time[truck_id] - self.start_time)
# key_value_dict["lastUnloadTime"] = datetime.now().strftime( / timedelta(hours=0, minutes=1, seconds=0)
# "%b %d, %Y %I:%M:%S %p") )
# if str_to_byte("lastUnloadTime") in key_value_dict.keys(): # print("相对last_unload_time", self.relative_last_unload_time[item])
# # redis2.hset(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"), self.logger.info("相对last_unload_time")
# # datetime.now().strftime("%b %d, %Y %I:%M:%S %p")) self.logger.info(self.relative_last_unload_time[truck_id])
# redis2.hset(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"), elif task == -2:
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"") # print(datetime.now())
# else: self.last_unload_time[truck_id] = datetime.now()
# redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"), # key_value_dict["lastUnloadTime"] = datetime.now().strftime(
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"") # "%b %d, %Y %I:%M:%S %p")
# # redis2.hsetnx(truck_uuid_to_name_dict[item], str(json.dumps(key_value_dict))) # if str_to_byte("lastUnloadTime") in key_value_dict.keys():
except Exception as es: # # redis2.hset(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"),
self.logger.error("读取矿卡可用时间异常-redis读取异常") # # datetime.now().strftime("%b %d, %Y %I:%M:%S %p"))
self.logger.error(es) # redis2.hset(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"),
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
# else:
# redis2.hsetnx(truck_uuid_to_name_dict[item], str_to_byte("lastUnloadTime"),
# "\"" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\"")
# # redis2.hsetnx(truck_uuid_to_name_dict[item], str(json.dumps(key_value_dict)))
# except Exception as es:
# self.logger.error("读取矿卡可用时间异常-redis读取异常")
# self.logger.error(es)
def update_truck_trip(self): def update_truck_trip(self):
...@@ -328,7 +318,7 @@ class TruckInfo(WalkManage): ...@@ -328,7 +318,7 @@ class TruckInfo(WalkManage):
session_mysql.commit() session_mysql.commit()
truck_id = self.truck_index_to_uuid_dict[i] truck_id = self.truck_index_to_uuid_dict[i]
task = self.truck_current_task[self.truck_index_to_uuid_dict[i]] task = self.truck_current_task[self.truck_index_to_uuid_dict[i]]
# print("truck_task:", truck_id, task) print("truck_task:", truck_id, task)
item = ( item = (
session_mysql.query(EquipmentPair) session_mysql.query(EquipmentPair)
.filter_by(truck_id=truck_id, isdeleted=0) .filter_by(truck_id=truck_id, isdeleted=0)
...@@ -523,29 +513,28 @@ class TruckInfo(WalkManage): ...@@ -523,29 +513,28 @@ class TruckInfo(WalkManage):
:return: truck_locate_dict :return: truck_locate_dict
""" """
try: # try:
truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict") truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict")
self.truck_locate_dict = {}
device_name_set = redis2.keys()
for item in device_name_set:
item = item.decode(encoding='utf-8')
key_value_dict = redis2.hgetall(item)
device_type = key_value_dict[str_to_byte('type')]
is_online = key_value_dict[str_to_byte('online')]
key_set = key_value_dict.keys()
if (device_type == str_to_byte("1")) \
and (str_to_byte('online') in key_set) \
and (bytes.decode(is_online) in ["true" or "True"]) \
and (str_to_byte('laneId') in key_set):
truck_locate = key_value_dict[str_to_byte('laneId')]
if eval(truck_locate) is not '':
self.truck_locate_dict[truck_name_to_uuid_dict[item]] = eval(truck_locate)
except Exception as es: self.truck_locate_dict = {}
logger.error("车辆所在路段读取异常") for truck_id in self.dynamic_truck_set:
logger.error(es) # truck_id = truck_id.decode(encoding='utf-8')
return {} key_value_dict = redis2.hgetall(truck_id)
device_type = key_value_dict[str_to_byte('type')]
is_online = key_value_dict[str_to_byte('online')]
key_set = key_value_dict.keys()
if (device_type == str_to_byte("1")) \
and (str_to_byte('online') in key_set) \
and (bytes.decode(is_online) in ["true" or "True"]) \
and (str_to_byte('laneId') in key_set):
truck_locate = key_value_dict[str_to_byte('laneId')]
if eval(truck_locate) is not '':
self.truck_locate_dict[truck_id] = eval(truck_locate)
# except Exception as es:
# logger.error("车辆所在路段读取异常")
# logger.error(es)
# return {}
################################################ long term update ################################################ ################################################ long term update ################################################
...@@ -612,10 +601,10 @@ class TruckInfo(WalkManage): ...@@ -612,10 +601,10 @@ class TruckInfo(WalkManage):
self.truck_dump_bind = {} self.truck_dump_bind = {}
for dump_area in session_postgre.query(DumpArea).all(): for dump_area in session_postgre.query(DumpArea).all():
if dump_area.BindList is not None: if dump_area.BindList is not None:
for truck_name in dump_area.BindList: for truck_id in dump_area.BindList:
self.truck_dump_bind[truck_name_to_uuid_dict[truck_name]] = str( # print(truck_name_to_uuid_dict)
dump_area.Id # truck_id = truck_name_to_uuid_dict[truck_name]
) self.truck_dump_bind[truck_id] = str(dump_area.Id)
except Exception as es: except Exception as es:
self.logger.error("矿卡-卸载区域绑定关系读取异常") self.logger.error("矿卡-卸载区域绑定关系读取异常")
self.logger.error(es) self.logger.error(es)
...@@ -624,22 +613,20 @@ class TruckInfo(WalkManage): ...@@ -624,22 +613,20 @@ class TruckInfo(WalkManage):
def update_truck_excavator_bind(self): def update_truck_excavator_bind(self):
truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict") truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict")
try: # try:
rule5 = session_mysql.query(DispatchRule).filter_by(id=5).first() rule5 = session_mysql.query(DispatchRule).filter_by(id=5).first()
if rule5.disabled == 0: if rule5.disabled == 0:
self.truck_excavator_bind = {} self.truck_excavator_bind = {}
for excavator_id in get_value("dynamic_excavator_set"): for excavator_id in get_value("dynamic_excavator_set"):
item = session_mysql.query(Equipment).filter_by(EQUIPMENT_ID=int(excavator_id)).first() item = session_mysql.query(Equipment).filter_by(EQUIPMENT_ID=int(excavator_id)).first()
if item.BIND_LIST is not None: if item.BIND_LIST is not None:
for truck_name in json.loads(item.BIND_LIST): for truck_id in json.loads(item.BIND_LIST):
self.truck_excavator_bind[ self.truck_excavator_bind[truck_id] = excavator_id
truck_name_to_uuid_dict[truck_name] # except Exception as es:
] = excavator_id # self.logger.error("矿卡-挖机绑定关系读取异常")
except Exception as es: # self.logger.error(es)
self.logger.error("矿卡-挖机绑定关系读取异常") # session_postgre.rollback()
self.logger.error(es) # session_mysql.rollback()
session_postgre.rollback()
session_mysql.rollback()
def update_truck_excavator_exclude(self): def update_truck_excavator_exclude(self):
...@@ -659,15 +646,11 @@ class TruckInfo(WalkManage): ...@@ -659,15 +646,11 @@ class TruckInfo(WalkManage):
session_mysql.rollback() session_mysql.rollback()
if rule5.disabled == 0: if rule5.disabled == 0:
for excavator_id in get_value("dynamic_excavator_set"): for excavator_id in get_value("dynamic_excavator_set"):
try: item = (
item = ( session_mysql.query(Equipment)
session_mysql.query(Equipment) .filter_by(EQUIPMENT_ID=int(excavator_id), ONLY_ALLOWED=1)
.filter_by(id=excavator_id, only_allowed=1) .first()
.first() )
)
except Exception as es:
session_postgre.rollback()
session_mysql.rollback()
if item is not None: if item is not None:
for truck_id in self.dynamic_truck_set: for truck_id in self.dynamic_truck_set:
if truck_uuid_to_name_dict[truck_id] not in item.bind_list: if truck_uuid_to_name_dict[truck_id] not in item.bind_list:
...@@ -764,7 +747,11 @@ class TruckInfo(WalkManage): ...@@ -764,7 +747,11 @@ class TruckInfo(WalkManage):
try: try:
empty_speed = session_mysql.query(EquipmentSpec). \ empty_speed = session_mysql.query(EquipmentSpec). \
join(Equipment, EquipmentSpec.EQUIPMENT_MODEL_ID == Equipment.EQUIPMENT_MODEL_ID). \ join(Equipment, EquipmentSpec.EQUIPMENT_MODEL_ID == Equipment.EQUIPMENT_MODEL_ID). \
filter(Equipment.EQUIPMENT_ID == truck_id).first().MAX_SPEED filter(Equipment.EQUIPMENT_ID == int(truck_id)).first().MAX_SPEED
if empty_speed is None:
self.empty_speed[truck_id] = 20
continue
if (empty_speed <= 1) or (empty_speed >= 50) or (empty_speed is None): if (empty_speed <= 1) or (empty_speed >= 50) or (empty_speed is None):
self.empty_speed[truck_id] = 20 self.empty_speed[truck_id] = 20
...@@ -773,7 +760,11 @@ class TruckInfo(WalkManage): ...@@ -773,7 +760,11 @@ class TruckInfo(WalkManage):
heavy_speed = session_mysql.query(EquipmentSpec). \ heavy_speed = session_mysql.query(EquipmentSpec). \
join(Equipment, EquipmentSpec.EQUIPMENT_MODEL_ID == Equipment.EQUIPMENT_MODEL_ID). \ join(Equipment, EquipmentSpec.EQUIPMENT_MODEL_ID == Equipment.EQUIPMENT_MODEL_ID). \
filter(Equipment.EQUIPMENT_MODID == truck_id).first().MAX_SPEED filter(Equipment.EQUIPMENT_ID == int(truck_id)).first().MAX_SPEED
if heavy_speed is None:
self.empty_speed[truck_id] = 20
continue
if (heavy_speed <= 1) or (heavy_speed >= 50) or (heavy_speed is None): if (heavy_speed <= 1) or (heavy_speed >= 50) or (heavy_speed is None):
self.heavy_speed[truck_id] = 20 self.heavy_speed[truck_id] = 20
...@@ -788,7 +779,7 @@ class TruckInfo(WalkManage): ...@@ -788,7 +779,7 @@ class TruckInfo(WalkManage):
def update_truck_disable_list(self) -> List: def update_truck_disable_list(self) -> List:
try: try:
for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=1, DISABLED=1).all(): for item in session_mysql.query(Equipment).filter_by(EQUIPMENT_TYPE_ID=1, DISABLED=1).all():
self.truck_disable_list.append(item.EQUIPMENT_ID) self.truck_disable_list.append(str(item.EQUIPMENT_ID))
except Exception as es: except Exception as es:
self.logger.error("车辆禁止列表更新异常") self.logger.error("车辆禁止列表更新异常")
self.logger.error(es) self.logger.error(es)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment