Commit 0619e46c authored by 张晓彤's avatar 张晓彤

二次调度修复及加入请求机制

parent c5099188
...@@ -51,3 +51,13 @@ Changelog for package Dispatch ...@@ -51,3 +51,13 @@ Changelog for package Dispatch
[TODO ]: [TODO ]:
[info ]: author: zxt ; time: 2022-04-07 17:33:00 ; email: ; tel: ; [info ]: author: zxt ; time: 2022-04-07 17:33:00 ; email: ; tel: ;
-------------------- --------------------
--------------------
[version]: 3.4.0
[message]: 新增拓扑路网功能,新增部分依赖库,启动方式发生改变,部署前注意查阅部署文档;
[feather]:
[fix ]:
[TODO ]:
[info ]: author: zxt ; time: 2022-09-09 14:00:00 ; email: ; tel: ;
--------------------
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#!E:\Pycharm Projects\Waytous
# -*- coding: utf-8 -*-
# @Time : 2022/8/18 13:53
# @Author : Opfer
# @Site :
# @File : ruler.py
# @Software: PyCharm
\ No newline at end of file
...@@ -8,83 +8,46 @@ ...@@ -8,83 +8,46 @@
import requests import requests
from tables import * from tables import *
import uuid with open(json_file) as f:
mysql_config = json.load(f)["mysql"]
def redispatch_request(truck_id, excavator_id, unload_area_id):
""" # def redispatch_request(truck_id, excavator_id, unload_area_id):
redispatch request. # """
:param truck_id: # redispatch request.
:param excavator_id: # :param truck_id:
:param unload_area_id: # :param excavator_id:
:return: # :param unload_area_id:
""" # :return:
# """
exactor_no = session_mysql.query(Equipment).filter_by(id=excavator_id).first().device_name #
unload_area_name = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first().Name # exactor_no = session_mysql.query(Equipment).filter_by(id=excavator_id).first().device_name
truck_name = session_mysql.query(Equipment).filter_by(id=truck_id).first().device_name # unload_area_name = session_postgre.query(DumpArea).filter_by(Id=unload_area_id).first().Name
# truck_name = session_mysql.query(Equipment).filter_by(id=truck_id).first().device_name
real_data = { #
"exactorId": excavator_id, # real_data = {
"exactorNo": exactor_no, # "exactorId": excavator_id,
"id": str(uuid.uuid4()), # "exactorNo": exactor_no,
"unloadAreaId": unload_area_id, # "id": str(uuid.uuid4()),
"unloadAreaName": unload_area_name, # "unloadAreaId": unload_area_id,
"truckId": truck_id, # "unloadAreaName": unload_area_name,
"truckNo": truck_name, # "truckId": truck_id,
"isauto": "true", # "truckNo": truck_name,
"tempChange": 1, # "isauto": "true",
"immediateEffect": 1 # "tempChange": 1,
} # "immediateEffect": 1
# }
#
# return POST(real_data)
return POST(real_data)
def POST(real_data): def POST(truck_id):
""" """
Post. Post.
:param real_data: :param real_data:
:return: :return:
""" """
url_d = "http://" + mysql_config["host"] + ":8020/ht/api/dispatch/updateTemp?truckId=" + truck_id
# real_data = { res_d = requests.get(url_d)
# "exactorId": "ddaa65cc-2658-4e35-b6ec-9deb046e0bfb", print(res_d.text)
# "exactorNo": "WJ001",
# "id": "d83f09cb-8df3-44d5-8e46-10dbaa317e19",
# "unloadAreaId": "10c75b23-4134-3ef1-9097-114bacac1982",
# "unloadAreaName": "卸载区4",
# "truckId": "de4080b3-fb89-460d-b511-c2ecd73c815c",
# "truckNo": "de4080b3-fb89-460d-b511-c2ecd73c815c",
# "isauto": "false",
# "tempChange": 1,
# "immediateEffect": 1
# }
#
# real_data = {
# 'exactorId': 'a3d09975-82d7-4a30-8c54-fe4ed8ff5a29',
# 'exactorNo': 'BI395-02',
# 'id': '76cb19a8-6541-4245-8ef6-40682aca9635',
# 'unloadAreaId': 'd4675d61-2134-8be7-fb36-fb9ef3c97f7c',
# 'unloadAreaName': '哈卸4',
# 'truckId': '7c196882-8850-4344-aff8-846a597f7792',
# 'truckNo': '7c196882-8850-4344-aff8-846a597f7792',
# 'isauto': 'true',
# 'tempChange': 1,
# 'immediateEffect': 1
# }
#
# head = {"Content-Type":"application/json; charset=UTF-8", 'Connection': 'close'}
url_d = "http://172.16.0.103:8020/ht/api/dispatch/update"
real_data = json.dumps(real_data)
print(real_data)
res_d = requests.post(url=url_d, data=real_data)
return res_d.text return res_d.text
\ No newline at end of file
#
# truck_id, excavator_id, unload_area_id = "9ce82957-b1e1-4dee-8dd1-3bbfa2a496b5", \
# "a3d09975-82d7-4a30-8c54-fe4ed8ff5a29", \
# "d4675d61-2134-8be7-fb36-fb9ef3c97f7c"
#
# res = redispatch_request(truck_id, excavator_id, unload_area_id)
#
# print(res)
\ No newline at end of file
...@@ -401,9 +401,9 @@ class DispatchInfo: ...@@ -401,9 +401,9 @@ class DispatchInfo:
cls.load_distance[item] = unload_load_distance cls.load_distance[item] = unload_load_distance
except Exception as es: except Exception as es:
logger.error(f'{item} 分组装载路网异常') logger.warning(f'{item} 分组装载路网异常')
cls.load_distance[item] = np.full((len(unload_areas), len(load_areas)), 10000) cls.load_distance[item] = np.full((len(unload_areas), len(load_areas)), 10000)
logger.error(es) logger.warning(es)
session_postgre.rollback() session_postgre.rollback()
session_mysql.rollback() session_mysql.rollback()
...@@ -418,9 +418,9 @@ class DispatchInfo: ...@@ -418,9 +418,9 @@ class DispatchInfo:
cls.unload_distance[item] = load_unload_distance cls.unload_distance[item] = load_unload_distance
except Exception as es: except Exception as es:
logger.error(f'{item} 分组卸载路网异常') logger.warning(f'{item} 分组卸载路网异常')
cls.unload_distance[item] = np.full((len(load_areas), len(unload_areas)), 10000) cls.unload_distance[item] = np.full((len(load_areas), len(unload_areas)), 10000)
logger.error(es) logger.warning(es)
session_postgre.rollback() session_postgre.rollback()
session_mysql.rollback() session_mysql.rollback()
......
...@@ -82,7 +82,7 @@ class ExcavatorInfo(WalkManage): ...@@ -82,7 +82,7 @@ class ExcavatorInfo(WalkManage):
self.logger.info(self.loading_time) self.logger.info(self.loading_time)
self.logger.info("excavator_uuid_to_index_dict") self.logger.info("excavator_uuid_to_index_dict")
self.logger.info(self.excavator_uuid_to_index_dict) self.logger.info(self.excavator_uuid_to_index_dict)
self.loading_time[self.excavator_uuid_to_index_dict[excavator_id]] = 10.00 self.loading_time[self.excavator_uuid_to_index_dict[excavator_id]] = 2.00
# 更新挖机设备出入时间 # 更新挖机设备出入时间
def update_excavator_entrance_exit_time(self): def update_excavator_entrance_exit_time(self):
......
...@@ -86,6 +86,8 @@ class TruckInfo(WalkManage): ...@@ -86,6 +86,8 @@ class TruckInfo(WalkManage):
self._excavator = excavator self._excavator = excavator
# 车辆位置信息 # 车辆位置信息
self.truck_locate_dict = {} self.truck_locate_dict = {}
# 车辆临时调度
self.truck_is_temp = {}
def get_truck_current_trip(self): def get_truck_current_trip(self):
return self.truck_current_trip return self.truck_current_trip
...@@ -137,6 +139,7 @@ class TruckInfo(WalkManage): ...@@ -137,6 +139,7 @@ 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 = {}
device_name_set = redis2.keys() 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")
...@@ -186,6 +189,43 @@ class TruckInfo(WalkManage): ...@@ -186,6 +189,43 @@ class TruckInfo(WalkManage):
# logger.info("矿卡当前任务:") # logger.info("矿卡当前任务:")
# logger.info(self.truck_current_task) # logger.info(self.truck_current_task)
def update_truck_is_temp(self):
"""
:return:
"""
self.truck_is_temp = {}
device_name_set = redis2.keys()
truck_name_to_uuid_dict = get_value("truck_name_to_uuid_dict")
for item in device_name_set:
try:
item = item.decode(encoding="utf-8")
if item not in truck_name_to_uuid_dict:
continue
key_value_dict = byte_to_str(redis5.get(truck_name_to_uuid_dict[item])) # reids str可以自动转为bytes
print(key_value_dict)
key_value_dict = json.loads(key_value_dict)
if truck_name_to_uuid_dict[item] in self.dynamic_truck_set:
try:
isTemp = key_value_dict["isTemp"]
print(isTemp)
self.truck_is_temp[truck_name_to_uuid_dict[item]] = bool(isTemp)
except Exception as es:
self.logger.error(es)
self.truck_is_temp[truck_name_to_uuid_dict[item]] = True
print(f'here3 {item} {bool(isTemp)}')
except Exception as es:
self.logger.warning("读取矿卡任务异常-reids读取异常")
self.logger.warning(es)
self.logger.info("isTemp")
self.logger.info(self.truck_is_temp)
# 更新矿卡最后装载/卸载时间 # 更新矿卡最后装载/卸载时间
def update_truck_last_leave_time(self): def update_truck_last_leave_time(self):
self.last_load_time = {} self.last_load_time = {}
...@@ -885,6 +925,8 @@ class TruckInfo(WalkManage): ...@@ -885,6 +925,8 @@ class TruckInfo(WalkManage):
# 更新卡车当前任务 # 更新卡车当前任务
self.update_truck_current_task() self.update_truck_current_task()
self.update_truck_is_temp()
# 更新卡车最后一次装载/卸载时间 # 更新卡车最后一次装载/卸载时间
self.update_truck_last_leave_time() self.update_truck_last_leave_time()
......
...@@ -326,14 +326,18 @@ class Topo(): ...@@ -326,14 +326,18 @@ class Topo():
unload_G target unload_G target
""" """
def get_unload_target_node_real(self, truck_location_lane, pre_target): def get_unload_target_node_real(self, truck_location_lane, pre_target, allow):
source_node = self.get_unload_edge_node(truck_location_lane) source_node = self.get_unload_edge_node(truck_location_lane)
target_list = [] target_list = []
for (u, wt) in self.unload_G.nodes.data('name'): for (u, wt) in self.unload_G.nodes.data('name'):
# select next reachable target # select next reachable target
if wt == 'dump' and u != pre_target: if wt == 'dump':
if allow:
target_list.append(u)
else:
if u != pre_target:
target_list.append(u) target_list.append(u)
if not len(target_list): if not len(target_list):
...@@ -420,7 +424,7 @@ class Topo(): ...@@ -420,7 +424,7 @@ class Topo():
load_G target load_G target
""" """
def get_load_target_node_real(self, truck_location_lane, pre_target): def get_load_target_node_real(self, truck_location_lane, pre_target, allow):
# source_node = self.get_load_edge_node(truck_location_lane) # source_node = self.get_load_edge_node(truck_location_lane)
source_node, end_node = self.get_load_edge_node(truck_location_lane) source_node, end_node = self.get_load_edge_node(truck_location_lane)
...@@ -432,7 +436,11 @@ class Topo(): ...@@ -432,7 +436,11 @@ class Topo():
target_list = [] target_list = []
for (node, att) in self.load_G.nodes.data('name'): for (node, att) in self.load_G.nodes.data('name'):
# select next reachable target # select next reachable target
if att == 'digging' and node != pre_destination_node: if att == 'digging':
if allow:
target_list.append(node)
else:
if node != pre_destination_node:
target_list.append(node) target_list.append(node)
if not len(target_list): if not len(target_list):
......
...@@ -9,6 +9,6 @@ ...@@ -9,6 +9,6 @@
from graph.topo_update import topo_graph_update from graph.topo_update import topo_graph_update
from graph.graph_load import graph_construct from graph.graph_load import graph_construct
# topo_graph_update() topo_graph_update()
graph_construct() # graph_construct()
\ No newline at end of file \ No newline at end of file
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