新增接口用法

Signed-off-by: yinzijian <yinzijian@haomozhixing.onaliyun.com>
This commit is contained in:
yinzijian 2025-10-30 10:00:19 +08:00
parent d75da2f090
commit e07de15d39
1 changed files with 36 additions and 3 deletions

View File

@ -6,7 +6,7 @@ from typing import List
import grpc
from app.global_source import g_config
from google.protobuf.json_format import MessageToDict
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../proto')))
from proto import phase_server_pb2_grpc, phase_server_pb2
@ -101,6 +101,7 @@ def GetQueryCrossPhaseRelativeOffset(citycode: int = 0, crossids: List[str] = []
finally:
channel.close()
#更新单绿波配时方案时段与路口配时方案时段对比异常状态
def QueryGreenWaveCrossPhaseTpCheck(waveid: str, citycode: int):
stub, channel = channel_stub()
@ -114,11 +115,43 @@ def QueryGreenWaveCrossPhaseTpCheck(waveid: str, citycode: int):
def QueryCrossRunningPhase(citycode: int, crossids: [], date_list: [], tp=''):
"""
路口运行中配时方案
"""
stub, channel = channel_stub()
try:
request_params = phase_server_pb2.CrossRunningPhaseRequest(citycode=citycode, crossids=crossids, date_list=date_list, tp=tp)
request_params = phase_server_pb2.CrossRunningPhaseRequest(citycode=citycode, crossids=crossids,
date_list=date_list, tp=tp)
return stub.CrossRunningPhase(request_params, timeout=30), None
except Exception as e:
return None, e
finally:
channel.close()
def QueryCrossPhaseDiagnosis(citycode: int, crossid: str, date_list: List, tp: str, area_id: int):
"""
路口配时方案诊断
返回dict: {},None
如果报错返回: None, error
example:
response , error = QueryCrossPhaseDiagnosis(citycode,crossid,[20251010], "07:00-07:20", 350101)
if error:
print(error)
return f"{error}"
if len(response) > 0:
print(response)
"""
stub, channel = channel_stub()
try:
request_params = phase_server_pb2.CrossPhaseDiagnosisRequest(citycode=citycode, crossid=crossid,
date_list=date_list, tp=tp, area_id=area_id)
response = stub.CrossPhaseDiagnosis(request_params, timeout=30)
if response.code != 0:
raise Exception(response.msg)
return MessageToDict(response.data), None
except Exception as e:
return None, e
finally:
channel.close()