Commit 62c4edc6 authored by 张晓彤's avatar 张晓彤

优化穿越装载区调度,优化二次调度触发机制

parent 97c4b861
This diff is collapsed.
...@@ -6,25 +6,26 @@ ...@@ -6,25 +6,26 @@
"dump_target_mass": 5000, "dump_target_mass": 5000,
"excavator_target_mass": 5000 "excavator_target_mass": 5000
}, },
"mysql": { "mysql": {
"host": "172.16.0.103", "host": "172.16.0.51",
"port": "3306", "port": "3306",
"user": "root", "user": "root",
"password": "Huituo@123", "password": "Huituo@123",
"database": "ht_zhunneng" "database": "ht_zhunneng"
}, },
"postgresql": { "postgresql": {
"host": "172.16.0.103", "host": "172.16.0.51",
"port": "5432", "port": "5432",
"user": "postgres", "user": "postgres",
"password": "Huituo@123", "password": "Huituo@123",
"database": "gis_zhunneng" "database": "gis_zhunneng"
}, },
"redis": { "redis": {
"host": "172.16.0.103", "host": "172.16.0.51",
"password": "Huituo@123" "password": "Huituo@123"
},
"gothrough": {
"closer_area_name": "哈1010平盘",
"further_area_name": "哈1026平盘"
} }
} }
\ No newline at end of file
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
import requests import requests
from tables import * from tables import *
with open(json_file) as f: with open(json_file, encoding='UTF-8') as f:
mysql_config = json.load(f)["mysql"] mysql_config = json.load(f)["mysql"]
...@@ -50,13 +50,19 @@ with open(json_file) as f: ...@@ -50,13 +50,19 @@ with open(json_file) as f:
def get_cross_next_lanes(truck_locate): def get_cross_next_lanes(truck_locate):
"""
获取当前车辆所在路段(交叉口),的子孙(后续两个)节点
:param truck_locate:
:return: lane_id list
"""
next_lane_list = [] next_lane_list = []
startNodeId = session_postgre.query(Lane).filter_by(Id=truck_locate).first().EndNodeId startNodeId = session_postgre.query(Lane).filter_by(Id=truck_locate).first().EndNodeId
for item in session_postgre.query(Lane).filter_by(StartNodeId=startNodeId).all(): for item in session_postgre.query(Lane).filter_by(StartNodeId=startNodeId).all():
next_lane_list.append(str(item.Id)) next_lane_list.append(str(item.Id))
next_lane_end_node = item.EndNodeId next_lane_end_node = item.EndNodeId
for next_item in session_postgre.query(Lane).filter_by(StartNodeId=next_lane_end_node).all(): if item.Length < 100:
next_lane_list.append(str(next_item.Id)) for next_item in session_postgre.query(Lane).filter_by(StartNodeId=next_lane_end_node).all():
next_lane_list.append(str(next_item.Id))
print("next_lane_list") print("next_lane_list")
print(next_lane_list) print(next_lane_list)
return next_lane_list return next_lane_list
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
from data.para_config import * from data.para_config import *
from typing import List from typing import List
from util.core_exception import CoreException
# 矿卡设备类 # 矿卡设备类
...@@ -136,6 +137,7 @@ class TruckInfo(WalkManage): ...@@ -136,6 +137,7 @@ class TruckInfo(WalkManage):
################################################ short term update ################################################ ################################################ short term update ################################################
# TODO: 应该一次读取形成一个对象,然后分配各属性
# 更新矿卡当前任务 # 更新矿卡当前任务
def update_truck_current_task(self): def update_truck_current_task(self):
self.truck_current_task = {} self.truck_current_task = {}
...@@ -145,27 +147,30 @@ class TruckInfo(WalkManage): ...@@ -145,27 +147,30 @@ class TruckInfo(WalkManage):
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 item in device_name_set:
# try: try:
item = item.decode(encoding="utf-8") item = item.decode(encoding="utf-8")
key_value_dict = redis2.hgetall(item) # reids str可以自动转为bytes key_value_dict = redis2.hgetall(item) # reids str可以自动转为bytes
if str_to_byte("type") in key_value_dict: 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: else:
continue continue
if device_type == 1: if device_type == 1:
if truck_name_to_uuid_dict[item] in self.dynamic_truck_set: if item not in truck_name_to_uuid_dict:
# currentTask = int(key_value_dict[str_to_byte("currentTask")]) raise CoreException(107, f'车辆{item}不存在于truck_name_to_uuid_dict')
currentTask = int(byte_to_str(key_value_dict[str_to_byte("currentTask")]))
self.truck_current_task[ if truck_name_to_uuid_dict[item] in self.dynamic_truck_set:
truck_name_to_uuid_dict[item] # currentTask = int(key_value_dict[str_to_byte("currentTask")])
] = currentTask currentTask = int(byte_to_str(key_value_dict[str_to_byte("currentTask")]))
currentState = int(float(byte_to_str(key_value_dict[str_to_byte("state")]))) self.truck_current_task[
self.truck_current_state[ truck_name_to_uuid_dict[item]
truck_name_to_uuid_dict[item] ] = currentTask
] = currentState currentState = int(float(byte_to_str(key_value_dict[str_to_byte("state")])))
# except Exception as es: self.truck_current_state[
# self.logger.error("读取矿卡任务异常-reids读取异常") truck_name_to_uuid_dict[item]
# self.logger.error(es) ] = currentState
except Exception as es:
self.logger.warning("读取矿卡任务异常-reids读取异常")
self.logger.warning(es)
self.logger.info("矿卡当前任务:") self.logger.info("矿卡当前任务:")
self.logger.info(self.truck_current_task) self.logger.info(self.truck_current_task)
...@@ -208,10 +213,16 @@ class TruckInfo(WalkManage): ...@@ -208,10 +213,16 @@ class TruckInfo(WalkManage):
if item not in truck_name_to_uuid_dict: if item not in truck_name_to_uuid_dict:
continue continue
key_value_dict = byte_to_str(redis5.get(truck_name_to_uuid_dict[item])) # reids str可以自动转为bytes if item not in truck_name_to_uuid_dict:
raise CoreException(107, f'车辆{item}不存在于truck_name_to_uuid_dict')
key_value_dict = redis5.get(truck_name_to_uuid_dict[item]) # reids str可以自动转为bytes
if key_value_dict is None:
raise CoreException(108, f'车辆{item}不存在于redis5')
key_value_dict = json.loads(byte_to_str(key_value_dict))
print(key_value_dict)
key_value_dict = json.loads(key_value_dict)
if truck_name_to_uuid_dict[item] in self.dynamic_truck_set: if truck_name_to_uuid_dict[item] in self.dynamic_truck_set:
try: try:
isTemp = key_value_dict["isTemp"] isTemp = key_value_dict["isTemp"]
......
...@@ -188,4 +188,4 @@ if __name__ == "__main__": ...@@ -188,4 +188,4 @@ if __name__ == "__main__":
logger.info(" ") logger.info(" ")
logger.info("调度系统启动") logger.info("调度系统启动")
main(30, dispatcher) main(20, dispatcher)
...@@ -23,16 +23,16 @@ global redispatch_active ...@@ -23,16 +23,16 @@ global redispatch_active
json_file = "config.json" json_file = "config.json"
with open(json_file) as f: with open(json_file, encoding='UTF-8') as f:
para_config = json.load(f)["para"] para_config = json.load(f)["para"]
with open(json_file) as f: with open(json_file, encoding='UTF-8') as f:
mysql_config = json.load(f)["mysql"] mysql_config = json.load(f)["mysql"]
with open(json_file) as f: with open(json_file, encoding='UTF-8') as f:
postgre_config = json.load(f)["postgresql"] postgre_config = json.load(f)["postgresql"]
with open(json_file) as f: with open(json_file, encoding='UTF-8') as f:
redis_config = json.load(f)["redis"] redis_config = json.load(f)["redis"]
# 全局参数 # 全局参数
......
...@@ -2,4 +2,5 @@ ...@@ -2,4 +2,5 @@
ps -ef|grep realtime_dispatch.py|grep -v grep |awk {'print $2'} ps -ef|grep realtime_dispatch.py|grep -v grep |awk {'print $2'}
kill -9 ps kill -9 ps
python3 topo_update_server.py python3 topo_update_server.py
nohup python3 realtime_dispatch.py --active >/dev/null 2>&1 & nohup python3 realtime_dispatch.py --active >/dev/null 2>&1 &
\ No newline at end of file nohup flask run --host=0.0.0.0 >/dev/null 2>&1 &
\ No newline at end of file
...@@ -21,8 +21,8 @@ relative_path = os.path.dirname(os.path.abspath(__file__)) # 获取当前文件 ...@@ -21,8 +21,8 @@ relative_path = os.path.dirname(os.path.abspath(__file__)) # 获取当前文件
json_file = os.path.join(relative_path, "config.json") json_file = os.path.join(relative_path, "config.json")
# json_file = "config.json" # json_file = "config.json"
with open(json_file) as f: with open(json_file, encoding='UTF-8') as f:
load_vale = json.load(f) load_vale = json.load(f, encoding='UTF-8')
postgre_config = load_vale["postgresql"] postgre_config = load_vale["postgresql"]
......
This diff is collapsed.
...@@ -13,20 +13,25 @@ code_msg = {101: "调度失败", ...@@ -13,20 +13,25 @@ code_msg = {101: "调度失败",
103: "数组越界异常", 103: "数组越界异常",
104: "数组维度不一致", 104: "数组维度不一致",
105: "数组越界", 105: "数组越界",
106: "挖机不存在或信息缺失"} 106: "挖机不存在或信息缺失",
107: "redis2设备信息与数据库不一致",
108: "redis5调度信息为空",
109: "配置信息不完整",
110: "车辆行程信息异常",
111: "挖机不存在或信息确实"}
class CoreException(Exception): class CoreException(Exception):
""" class for my exception.""" """ class for my exception."""
def __init__(self, Code: int = None, ErrorInfo: str = None): def __init__(self, Code: int = 101, ErrorInfo: str = None):
super().__init__(self, ErrorInfo) super().__init__(self, ErrorInfo)
self.__error_info = ErrorInfo self.__error_info = ErrorInfo
self.code = Code self.code = Code
self.__traceback = "" self.__traceback = ""
def __str__(self) -> str: def __str__(self) -> str:
return '{0:}-{1:} \n{2:}'.format(code_msg[self.code], self.__error_info, self.__traceback) return '{0:}-{1:} {2:}'.format(code_msg[self.code], self.__error_info, self.__traceback)
# def with_traceback(self, tb) -> BaseException: # def with_traceback(self, tb) -> BaseException:
# self.__traceback = tb # self.__traceback = tb
......
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