pycityagent 1.0.0__py3-none-any.whl → 2.0.0a1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pycityagent/__init__.py +7 -3
- pycityagent/agent.py +180 -284
- pycityagent/economy/__init__.py +5 -0
- pycityagent/economy/econ_client.py +307 -0
- pycityagent/environment/__init__.py +7 -0
- pycityagent/environment/interact/interact.py +141 -0
- pycityagent/environment/sence/__init__.py +0 -0
- pycityagent/{brain → environment/sence}/static.py +1 -1
- pycityagent/environment/sidecar/__init__.py +8 -0
- pycityagent/environment/sidecar/sidecarv2.py +109 -0
- pycityagent/environment/sim/__init__.py +27 -0
- pycityagent/environment/sim/aoi_service.py +38 -0
- pycityagent/environment/sim/client.py +126 -0
- pycityagent/environment/sim/clock_service.py +43 -0
- pycityagent/environment/sim/economy_services.py +191 -0
- pycityagent/environment/sim/lane_service.py +110 -0
- pycityagent/environment/sim/light_service.py +120 -0
- pycityagent/environment/sim/person_service.py +294 -0
- pycityagent/environment/sim/road_service.py +38 -0
- pycityagent/environment/sim/social_service.py +58 -0
- pycityagent/environment/simulator.py +369 -0
- pycityagent/environment/utils/__init__.py +8 -0
- pycityagent/environment/utils/geojson.py +26 -0
- pycityagent/environment/utils/grpc.py +57 -0
- pycityagent/environment/utils/map_utils.py +157 -0
- pycityagent/environment/utils/protobuf.py +39 -0
- pycityagent/llm/__init__.py +6 -0
- pycityagent/llm/embedding.py +136 -0
- pycityagent/llm/llm.py +430 -0
- pycityagent/llm/llmconfig.py +15 -0
- pycityagent/llm/utils.py +6 -0
- pycityagent/memory/__init__.py +11 -0
- pycityagent/memory/const.py +41 -0
- pycityagent/memory/memory.py +453 -0
- pycityagent/memory/memory_base.py +168 -0
- pycityagent/memory/profile.py +165 -0
- pycityagent/memory/self_define.py +165 -0
- pycityagent/memory/state.py +173 -0
- pycityagent/memory/utils.py +27 -0
- pycityagent/message/__init__.py +0 -0
- pycityagent/simulation/__init__.py +7 -0
- pycityagent/simulation/interview.py +36 -0
- pycityagent/simulation/simulation.py +286 -0
- pycityagent/simulation/survey/__init__.py +9 -0
- pycityagent/simulation/survey/manager.py +67 -0
- pycityagent/simulation/survey/models.py +49 -0
- pycityagent/simulation/ui/__init__.py +3 -0
- pycityagent/simulation/ui/interface.py +602 -0
- pycityagent/utils/__init__.py +0 -0
- pycityagent/utils/decorators.py +89 -0
- pycityagent/utils/parsers/__init__.py +12 -0
- pycityagent/utils/parsers/code_block_parser.py +37 -0
- pycityagent/utils/parsers/json_parser.py +86 -0
- pycityagent/utils/parsers/parser_base.py +60 -0
- pycityagent/workflow/__init__.py +22 -0
- pycityagent/workflow/block.py +137 -0
- pycityagent/workflow/prompt.py +72 -0
- pycityagent/workflow/tool.py +246 -0
- pycityagent/workflow/trigger.py +66 -0
- pycityagent-2.0.0a1.dist-info/METADATA +208 -0
- pycityagent-2.0.0a1.dist-info/RECORD +65 -0
- {pycityagent-1.0.0.dist-info → pycityagent-2.0.0a1.dist-info}/WHEEL +1 -2
- pycityagent/ac/__init__.py +0 -6
- pycityagent/ac/ac.py +0 -50
- pycityagent/ac/action.py +0 -14
- pycityagent/ac/controled.py +0 -13
- pycityagent/ac/converse.py +0 -31
- pycityagent/ac/idle.py +0 -17
- pycityagent/ac/shop.py +0 -80
- pycityagent/ac/trip.py +0 -37
- pycityagent/brain/__init__.py +0 -10
- pycityagent/brain/brain.py +0 -52
- pycityagent/brain/brainfc.py +0 -10
- pycityagent/brain/memory.py +0 -541
- pycityagent/brain/persistence/social.py +0 -1
- pycityagent/brain/persistence/spatial.py +0 -14
- pycityagent/brain/reason/shop.py +0 -37
- pycityagent/brain/reason/social.py +0 -148
- pycityagent/brain/reason/trip.py +0 -67
- pycityagent/brain/reason/user.py +0 -122
- pycityagent/brain/retrive/social.py +0 -6
- pycityagent/brain/scheduler.py +0 -408
- pycityagent/brain/sence.py +0 -375
- pycityagent/cc/__init__.py +0 -5
- pycityagent/cc/cc.py +0 -102
- pycityagent/cc/conve.py +0 -6
- pycityagent/cc/idle.py +0 -20
- pycityagent/cc/shop.py +0 -6
- pycityagent/cc/trip.py +0 -13
- pycityagent/cc/user.py +0 -13
- pycityagent/hubconnector/__init__.py +0 -3
- pycityagent/hubconnector/hubconnector.py +0 -137
- pycityagent/image/__init__.py +0 -3
- pycityagent/image/image.py +0 -158
- pycityagent/simulator.py +0 -161
- pycityagent/st/__init__.py +0 -4
- pycityagent/st/st.py +0 -96
- pycityagent/urbanllm/__init__.py +0 -3
- pycityagent/urbanllm/urbanllm.py +0 -132
- pycityagent-1.0.0.dist-info/LICENSE +0 -21
- pycityagent-1.0.0.dist-info/METADATA +0 -181
- pycityagent-1.0.0.dist-info/RECORD +0 -48
- pycityagent-1.0.0.dist-info/top_level.txt +0 -1
- /pycityagent/{brain/persistence/__init__.py → config.py} +0 -0
- /pycityagent/{brain/reason → environment/interact}/__init__.py +0 -0
- /pycityagent/{brain/retrive → environment/message}/__init__.py +0 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
import warnings
|
2
|
+
import grpc
|
3
|
+
|
4
|
+
from ..sidecar import OnlyClientSidecar
|
5
|
+
from .clock_service import ClockService
|
6
|
+
from .person_service import PersonService
|
7
|
+
from .aoi_service import AoiService
|
8
|
+
from .lane_service import LaneService
|
9
|
+
from .road_service import RoadService
|
10
|
+
from .social_service import SocialService
|
11
|
+
from .economy_services import EconomyPersonService, EconomyOrgService
|
12
|
+
from .light_service import LightService
|
13
|
+
|
14
|
+
from ..utils.grpc import create_aio_channel
|
15
|
+
|
16
|
+
__all__ = ["CityClient"]
|
17
|
+
|
18
|
+
|
19
|
+
class CityClient:
|
20
|
+
"""
|
21
|
+
模拟器接口
|
22
|
+
Simulator interface
|
23
|
+
"""
|
24
|
+
|
25
|
+
NAME = "city"
|
26
|
+
|
27
|
+
def __init__(
|
28
|
+
self,
|
29
|
+
url: str,
|
30
|
+
secure: bool = False,
|
31
|
+
):
|
32
|
+
"""
|
33
|
+
Args:
|
34
|
+
- url (str): 模拟器server的地址。The address of the emulator server.
|
35
|
+
- secure (bool, optional): 是否使用安全连接. Defaults to False. Whether to use a secure connection. Defaults to False.
|
36
|
+
"""
|
37
|
+
aio_channel = create_aio_channel(url, secure)
|
38
|
+
self._clock_service = ClockService(aio_channel)
|
39
|
+
self._lane_service = LaneService(aio_channel)
|
40
|
+
self._person_service = PersonService(aio_channel)
|
41
|
+
self._aoi_service = AoiService(aio_channel)
|
42
|
+
self._road_service = RoadService(aio_channel)
|
43
|
+
self._social_service = SocialService(aio_channel)
|
44
|
+
self._economy_person_service = EconomyPersonService(aio_channel)
|
45
|
+
self._economy_org_service = EconomyOrgService(aio_channel)
|
46
|
+
self._light_service = LightService(aio_channel)
|
47
|
+
|
48
|
+
@staticmethod
|
49
|
+
def from_sidecar(sidecar: OnlyClientSidecar, name: str = NAME):
|
50
|
+
"""
|
51
|
+
从sidecar中创建CityClient
|
52
|
+
Create CityClient from sidecar
|
53
|
+
"""
|
54
|
+
return CityClient(sidecar.wait_url(name))
|
55
|
+
|
56
|
+
@property
|
57
|
+
def clock_service(self):
|
58
|
+
"""
|
59
|
+
模拟器时间服务子模块
|
60
|
+
Simulator time service submodule
|
61
|
+
"""
|
62
|
+
return self._clock_service
|
63
|
+
|
64
|
+
@property
|
65
|
+
def lane_service(self):
|
66
|
+
"""
|
67
|
+
模拟器lane服务子模块
|
68
|
+
Simulator lane service submodule
|
69
|
+
"""
|
70
|
+
return self._lane_service
|
71
|
+
|
72
|
+
@property
|
73
|
+
def person_service(self):
|
74
|
+
"""
|
75
|
+
模拟器智能体服务子模块
|
76
|
+
Simulator agent service submodule
|
77
|
+
"""
|
78
|
+
return self._person_service
|
79
|
+
|
80
|
+
@property
|
81
|
+
def aoi_service(self):
|
82
|
+
"""
|
83
|
+
模拟器AOI服务子模块
|
84
|
+
Simulator AOI service submodule
|
85
|
+
"""
|
86
|
+
return self._aoi_service
|
87
|
+
|
88
|
+
@property
|
89
|
+
def road_service(self):
|
90
|
+
"""
|
91
|
+
模拟器road服务子模块
|
92
|
+
Simulator road service submodule
|
93
|
+
"""
|
94
|
+
return self._road_service
|
95
|
+
|
96
|
+
@property
|
97
|
+
def social_service(self):
|
98
|
+
"""
|
99
|
+
模拟器social服务子模块
|
100
|
+
Simulator social service submodule
|
101
|
+
"""
|
102
|
+
return self._social_service
|
103
|
+
|
104
|
+
@property
|
105
|
+
def economy_person_service(self):
|
106
|
+
"""
|
107
|
+
模拟器经济服务(个人)子模块
|
108
|
+
Simulator economic service (personal) submodule
|
109
|
+
"""
|
110
|
+
return self._economy_person_service
|
111
|
+
|
112
|
+
@property
|
113
|
+
def economy_org_service(self):
|
114
|
+
"""
|
115
|
+
模拟器经济服务(组织)子模块
|
116
|
+
Simulator economic service (organizational) submodule
|
117
|
+
"""
|
118
|
+
return self._economy_org_service
|
119
|
+
|
120
|
+
@property
|
121
|
+
def light_service(self):
|
122
|
+
"""
|
123
|
+
模拟器红绿灯服务子模块
|
124
|
+
Simulator traffic light service submodule
|
125
|
+
"""
|
126
|
+
return self._light_service
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from typing import Any, Awaitable, Coroutine, cast, Union, Dict
|
2
|
+
|
3
|
+
import grpc
|
4
|
+
from google.protobuf.json_format import ParseDict
|
5
|
+
from pycityproto.city.clock.v1 import clock_service_pb2 as clock_service
|
6
|
+
from pycityproto.city.clock.v1 import clock_service_pb2_grpc as clock_grpc
|
7
|
+
|
8
|
+
from ..utils.protobuf import async_parse
|
9
|
+
|
10
|
+
__all__ = ["ClockService"]
|
11
|
+
|
12
|
+
|
13
|
+
class ClockService:
|
14
|
+
"""
|
15
|
+
城市模拟时间服务
|
16
|
+
City simulation clock service
|
17
|
+
"""
|
18
|
+
|
19
|
+
def __init__(self, aio_channel: grpc.aio.Channel):
|
20
|
+
self._aio_stub = clock_grpc.ClockServiceStub(aio_channel)
|
21
|
+
|
22
|
+
def Now(
|
23
|
+
self,
|
24
|
+
req: Union[clock_service.NowRequest, dict],
|
25
|
+
dict_return: bool = True,
|
26
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], clock_service.NowResponse]]:
|
27
|
+
"""
|
28
|
+
获取当前的模拟时间请求
|
29
|
+
Getting current simulation clock
|
30
|
+
|
31
|
+
Args:
|
32
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.clock.v1.NowRequest
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
- https://cityproto.sim.fiblab.net/#city.clock.v1.NowResponse
|
36
|
+
"""
|
37
|
+
if type(req) != clock_service.NowRequest:
|
38
|
+
req = ParseDict(req, clock_service.NowRequest())
|
39
|
+
res = cast(
|
40
|
+
Awaitable[clock_service.NowResponse],
|
41
|
+
self._aio_stub.Now(req),
|
42
|
+
)
|
43
|
+
return async_parse(res, dict_return)
|
@@ -0,0 +1,191 @@
|
|
1
|
+
from typing import Any, Awaitable, Coroutine, cast, Union, Dict
|
2
|
+
|
3
|
+
import grpc
|
4
|
+
from google.protobuf.json_format import ParseDict
|
5
|
+
from pycityproto.city.economy.v1 import org_service_pb2 as org_service
|
6
|
+
from pycityproto.city.economy.v1 import org_service_pb2_grpc as org_grpc
|
7
|
+
from pycityproto.city.economy.v1 import person_service_pb2 as person_service
|
8
|
+
from pycityproto.city.economy.v1 import person_service_pb2_grpc as person_grpc
|
9
|
+
|
10
|
+
from ..utils.protobuf import async_parse
|
11
|
+
|
12
|
+
__all__ = ["EconomyPersonService", "EconomyOrgService"]
|
13
|
+
|
14
|
+
|
15
|
+
class EconomyPersonService:
|
16
|
+
"""
|
17
|
+
城市模拟经济服务(个人)
|
18
|
+
City simulation economic service (personal)
|
19
|
+
"""
|
20
|
+
|
21
|
+
def __init__(self, aio_channel: grpc.aio.Channel):
|
22
|
+
self._aio_stub = person_grpc.PersonServiceStub(aio_channel)
|
23
|
+
|
24
|
+
def GetPerson(
|
25
|
+
self,
|
26
|
+
req: Union[person_service.GetPersonRequest, dict],
|
27
|
+
dict_return: bool = True,
|
28
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], person_service.GetPersonResponse]]:
|
29
|
+
"""
|
30
|
+
批量查询人的经济情况(资金、雇佣关系)
|
31
|
+
Query person’s economic situation (funds, employment relationship) in batches
|
32
|
+
|
33
|
+
Args:
|
34
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.GetPersonRequest
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.GetPersonResponse
|
38
|
+
"""
|
39
|
+
if type(req) != person_service.GetPersonRequest:
|
40
|
+
req = ParseDict(req, person_service.GetPersonRequest())
|
41
|
+
res = cast(
|
42
|
+
Awaitable[person_service.GetPersonResponse], self._aio_stub.GetPerson(req)
|
43
|
+
)
|
44
|
+
return async_parse(res, dict_return)
|
45
|
+
|
46
|
+
def UpdatePersonMoney(
|
47
|
+
self,
|
48
|
+
req: Union[person_service.UpdatePersonMoneyRequest, dict],
|
49
|
+
dict_return: bool = True,
|
50
|
+
) -> Coroutine[
|
51
|
+
Any, Any, Union[Dict[str, Any], person_service.UpdatePersonMoneyResponse]
|
52
|
+
]:
|
53
|
+
"""
|
54
|
+
批量修改人的资金
|
55
|
+
Modify person’s money in batches
|
56
|
+
|
57
|
+
Args:
|
58
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdatePersonMoneyRequest
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.UpdatePersonMoneyResponse
|
62
|
+
"""
|
63
|
+
if type(req) != person_service.UpdatePersonMoneyRequest:
|
64
|
+
req = ParseDict(req, person_service.UpdatePersonMoneyRequest())
|
65
|
+
res = cast(
|
66
|
+
Awaitable[person_service.UpdatePersonMoneyResponse],
|
67
|
+
self._aio_stub.UpdatePersonMoney(req),
|
68
|
+
)
|
69
|
+
return async_parse(res, dict_return)
|
70
|
+
|
71
|
+
|
72
|
+
class EconomyOrgService:
|
73
|
+
"""
|
74
|
+
城市模拟经济服务(组织)
|
75
|
+
City simulation economic service (organizational)
|
76
|
+
"""
|
77
|
+
|
78
|
+
def __init__(self, aio_channel: grpc.aio.Channel):
|
79
|
+
self._aio_stub = org_grpc.OrgServiceStub(aio_channel)
|
80
|
+
|
81
|
+
def GetOrg(
|
82
|
+
self, req: Union[org_service.GetOrgRequest, dict], dict_return: bool = True
|
83
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], org_service.GetOrgResponse]]:
|
84
|
+
"""
|
85
|
+
批量查询组织的经济情况(员工、岗位、资金、货物)
|
86
|
+
Query the economic status of the organization (employees, positions, funds, goods) in batches
|
87
|
+
|
88
|
+
Args:
|
89
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.GetOrgRequest
|
90
|
+
|
91
|
+
Returns:
|
92
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.GetOrgResponse
|
93
|
+
"""
|
94
|
+
if type(req) != org_service.GetOrgRequest:
|
95
|
+
req = ParseDict(req, org_service.GetOrgRequest())
|
96
|
+
res = cast(Awaitable[org_service.GetOrgResponse], self._aio_stub.GetOrg(req))
|
97
|
+
return async_parse(res, dict_return)
|
98
|
+
|
99
|
+
def UpdateOrgMoney(
|
100
|
+
self,
|
101
|
+
req: Union[org_service.UpdateOrgMoneyRequest, dict],
|
102
|
+
dict_return: bool = True,
|
103
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], org_service.UpdateOrgMoneyResponse]]:
|
104
|
+
"""
|
105
|
+
批量修改组织的资金
|
106
|
+
Modify organization’s money in batches
|
107
|
+
|
108
|
+
Args:
|
109
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgMoneyRequest
|
110
|
+
|
111
|
+
Returns:
|
112
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgMoneyResponse
|
113
|
+
"""
|
114
|
+
if type(req) != org_service.UpdateOrgMoneyRequest:
|
115
|
+
req = ParseDict(req, org_service.UpdateOrgMoneyRequest())
|
116
|
+
res = cast(
|
117
|
+
Awaitable[org_service.UpdateOrgMoneyResponse],
|
118
|
+
self._aio_stub.UpdateOrgMoney(req),
|
119
|
+
)
|
120
|
+
return async_parse(res, dict_return)
|
121
|
+
|
122
|
+
def UpdateOrgGoods(
|
123
|
+
self,
|
124
|
+
req: Union[org_service.UpdateOrgGoodsRequest, dict],
|
125
|
+
dict_return: bool = True,
|
126
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], org_service.UpdateOrgGoodsResponse]]:
|
127
|
+
"""
|
128
|
+
批量修改组织的货物
|
129
|
+
Modify organization’s goods in batches
|
130
|
+
|
131
|
+
Args:
|
132
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgGoodsRequest
|
133
|
+
|
134
|
+
Returns:
|
135
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgGoodsResponse
|
136
|
+
"""
|
137
|
+
if type(req) != org_service.UpdateOrgGoodsRequest:
|
138
|
+
req = ParseDict(req, org_service.UpdateOrgGoodsRequest())
|
139
|
+
res = cast(
|
140
|
+
Awaitable[org_service.UpdateOrgGoodsResponse],
|
141
|
+
self._aio_stub.UpdateOrgGoods(req),
|
142
|
+
)
|
143
|
+
return async_parse(res, dict_return)
|
144
|
+
|
145
|
+
def UpdateOrgEmployee(
|
146
|
+
self,
|
147
|
+
req: Union[org_service.UpdateOrgEmployeeRequest, dict],
|
148
|
+
dict_return: bool = True,
|
149
|
+
) -> Coroutine[
|
150
|
+
Any, Any, Union[Dict[str, Any], org_service.UpdateOrgEmployeeResponse]
|
151
|
+
]:
|
152
|
+
"""
|
153
|
+
批量修改组织的员工
|
154
|
+
Modify organization’s emplpyees in batches
|
155
|
+
|
156
|
+
Args:
|
157
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgEmployeeRequest
|
158
|
+
|
159
|
+
Returns:
|
160
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgEmployeeResponse
|
161
|
+
"""
|
162
|
+
if type(req) != org_service.UpdateOrgEmployeeRequest:
|
163
|
+
req = ParseDict(req, org_service.UpdateOrgEmployeeRequest())
|
164
|
+
res = cast(
|
165
|
+
Awaitable[org_service.UpdateOrgEmployeeResponse],
|
166
|
+
self._aio_stub.UpdateOrgEmployee(req),
|
167
|
+
)
|
168
|
+
return async_parse(res, dict_return)
|
169
|
+
|
170
|
+
def UpdateOrgJob(
|
171
|
+
self,
|
172
|
+
req: Union[org_service.UpdateOrgJobRequest, dict],
|
173
|
+
dict_return: bool = True,
|
174
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], org_service.UpdateOrgJobResponse]]:
|
175
|
+
"""
|
176
|
+
批量修改组织的岗位
|
177
|
+
Modify organization’s jobs in batches
|
178
|
+
|
179
|
+
Args:
|
180
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgJobRequest
|
181
|
+
|
182
|
+
Returns:
|
183
|
+
- https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgJobResponse
|
184
|
+
"""
|
185
|
+
if type(req) != org_service.UpdateOrgJobRequest:
|
186
|
+
req = ParseDict(req, org_service.UpdateOrgJobRequest())
|
187
|
+
res = cast(
|
188
|
+
Awaitable[org_service.UpdateOrgJobResponse],
|
189
|
+
self._aio_stub.UpdateOrgJob(req),
|
190
|
+
)
|
191
|
+
return async_parse(res, dict_return)
|
@@ -0,0 +1,110 @@
|
|
1
|
+
from typing import Any, Awaitable, Coroutine, cast, Union, Dict
|
2
|
+
|
3
|
+
import grpc
|
4
|
+
from google.protobuf.json_format import ParseDict
|
5
|
+
from pycityproto.city.map.v2 import lane_service_pb2 as lane_service
|
6
|
+
from pycityproto.city.map.v2 import lane_service_pb2_grpc as lane_grpc
|
7
|
+
|
8
|
+
from ..utils.protobuf import async_parse
|
9
|
+
|
10
|
+
__all__ = ["LaneService"]
|
11
|
+
|
12
|
+
|
13
|
+
class LaneService:
|
14
|
+
"""
|
15
|
+
交通模拟lane服务
|
16
|
+
Traffic simulation lane service
|
17
|
+
"""
|
18
|
+
|
19
|
+
def __init__(self, aio_channel: grpc.aio.Channel):
|
20
|
+
self._aio_stub = lane_grpc.LaneServiceStub(aio_channel)
|
21
|
+
|
22
|
+
def GetLane(
|
23
|
+
self, req: Union[lane_service.GetLaneRequest, dict], dict_return: bool = True
|
24
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], lane_service.GetLaneResponse]]:
|
25
|
+
"""
|
26
|
+
获取Lane的信息
|
27
|
+
Get Lane's information
|
28
|
+
|
29
|
+
Args:
|
30
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneRequest
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
- https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneResponse
|
34
|
+
"""
|
35
|
+
if type(req) != lane_service.GetLaneRequest:
|
36
|
+
req = ParseDict(req, lane_service.GetLaneRequest())
|
37
|
+
res = cast(Awaitable[lane_service.GetLaneResponse], self._aio_stub.GetLane(req))
|
38
|
+
return async_parse(res, dict_return)
|
39
|
+
|
40
|
+
def SetLaneMaxV(
|
41
|
+
self,
|
42
|
+
req: Union[lane_service.SetLaneMaxVRequest, dict],
|
43
|
+
dict_return: bool = True,
|
44
|
+
) -> Coroutine[Any, Any, Union[Dict[str, Any], lane_service.SetLaneMaxVResponse]]:
|
45
|
+
"""
|
46
|
+
设置Lane的最大速度(限速)
|
47
|
+
Set the maximum speed of Lane (speed limit)
|
48
|
+
|
49
|
+
Args:
|
50
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneMaxVRequest
|
51
|
+
|
52
|
+
Returns:
|
53
|
+
- https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneMaxVResponse
|
54
|
+
"""
|
55
|
+
if type(req) != lane_service.SetLaneMaxVRequest:
|
56
|
+
req = ParseDict(req, lane_service.SetLaneMaxVRequest())
|
57
|
+
res = cast(
|
58
|
+
Awaitable[lane_service.SetLaneMaxVResponse], self._aio_stub.SetLaneMaxV(req)
|
59
|
+
)
|
60
|
+
return async_parse(res, dict_return)
|
61
|
+
|
62
|
+
def SetLaneRestriction(
|
63
|
+
self,
|
64
|
+
req: Union[lane_service.SetLaneRestrictionRequest, dict],
|
65
|
+
dict_return: bool = True,
|
66
|
+
) -> Coroutine[
|
67
|
+
Any, Any, Union[Dict[str, Any], lane_service.SetLaneRestrictionResponse]
|
68
|
+
]:
|
69
|
+
"""
|
70
|
+
设置Lane的限制
|
71
|
+
Set the restriction of Lane
|
72
|
+
|
73
|
+
Args:
|
74
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneRestrictionRequest
|
75
|
+
|
76
|
+
Returns:
|
77
|
+
- https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneRestrictionResponse
|
78
|
+
"""
|
79
|
+
if type(req) != lane_service.SetLaneRestrictionRequest:
|
80
|
+
req = ParseDict(req, lane_service.SetLaneRestrictionRequest())
|
81
|
+
res = cast(
|
82
|
+
Awaitable[lane_service.SetLaneRestrictionResponse],
|
83
|
+
self._aio_stub.SetLaneRestriction(req),
|
84
|
+
)
|
85
|
+
return async_parse(res, dict_return)
|
86
|
+
|
87
|
+
def GetLaneByLongLatBBox(
|
88
|
+
self,
|
89
|
+
req: Union[lane_service.GetLaneByLongLatBBoxRequest, dict],
|
90
|
+
dict_return: bool = True,
|
91
|
+
) -> Coroutine[
|
92
|
+
Any, Any, Union[Dict[str, Any], lane_service.GetLaneByLongLatBBoxResponse]
|
93
|
+
]:
|
94
|
+
"""
|
95
|
+
获取特定区域内的Lane的信息
|
96
|
+
Get lane information in a specific region
|
97
|
+
|
98
|
+
Args:
|
99
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneByLongLatBBoxRequest
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
- https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneByLongLatBBoxResponse
|
103
|
+
"""
|
104
|
+
if type(req) != lane_service.GetLaneByLongLatBBoxRequest:
|
105
|
+
req = ParseDict(req, lane_service.GetLaneByLongLatBBoxRequest())
|
106
|
+
res = cast(
|
107
|
+
Awaitable[lane_service.GetLaneByLongLatBBoxResponse],
|
108
|
+
self._aio_stub.GetLaneByLongLatBBox(req),
|
109
|
+
)
|
110
|
+
return async_parse(res, dict_return)
|
@@ -0,0 +1,120 @@
|
|
1
|
+
from typing import Any, Awaitable, Coroutine, cast, Union, Dict
|
2
|
+
|
3
|
+
import grpc
|
4
|
+
from google.protobuf.json_format import ParseDict
|
5
|
+
from pycityproto.city.map.v2 import traffic_light_service_pb2 as light_service
|
6
|
+
from pycityproto.city.map.v2 import traffic_light_service_pb2_grpc as light_grpc
|
7
|
+
|
8
|
+
from ..utils.protobuf import async_parse
|
9
|
+
|
10
|
+
__all__ = ["LightService"]
|
11
|
+
|
12
|
+
|
13
|
+
class LightService:
|
14
|
+
"""
|
15
|
+
城市模拟信控服务
|
16
|
+
City simulation traffic light service
|
17
|
+
"""
|
18
|
+
|
19
|
+
def __init__(self, aio_channel: grpc.aio.Channel):
|
20
|
+
self._aio_stub = light_grpc.TrafficLightServiceStub(aio_channel)
|
21
|
+
|
22
|
+
def GetTrafficLight(
|
23
|
+
self,
|
24
|
+
req: Union[light_service.GetTrafficLightRequest, Dict[str, Any]],
|
25
|
+
dict_return: bool = True,
|
26
|
+
) -> Coroutine[
|
27
|
+
Any, Any, Union[Dict[str, Any], light_service.GetTrafficLightResponse]
|
28
|
+
]:
|
29
|
+
"""
|
30
|
+
获取路口的红绿灯信息
|
31
|
+
Get traffic light information
|
32
|
+
|
33
|
+
Args:
|
34
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.GetTrafficLightRequest
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
- https://cityproto.sim.fiblab.net/#city.traffic.v1.GetTrafficLightResponse
|
38
|
+
"""
|
39
|
+
if type(req) != light_service.GetTrafficLightRequest:
|
40
|
+
req = ParseDict(req, light_service.GetTrafficLightRequest())
|
41
|
+
res = cast(
|
42
|
+
Awaitable[light_service.GetTrafficLightResponse],
|
43
|
+
self._aio_stub.GetTrafficLight(req),
|
44
|
+
)
|
45
|
+
return async_parse(res, dict_return)
|
46
|
+
|
47
|
+
def SetTrafficLight(
|
48
|
+
self,
|
49
|
+
req: Union[light_service.SetTrafficLightRequest, Dict[str, Any]],
|
50
|
+
dict_return: bool = True,
|
51
|
+
) -> Coroutine[
|
52
|
+
Any, Any, Union[Dict[str, Any], light_service.SetTrafficLightResponse]
|
53
|
+
]:
|
54
|
+
"""
|
55
|
+
设置路口的红绿灯信息
|
56
|
+
Set traffic light information
|
57
|
+
|
58
|
+
Args:
|
59
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightRequest
|
60
|
+
|
61
|
+
Returns:
|
62
|
+
- https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightResponse
|
63
|
+
"""
|
64
|
+
if type(req) != light_service.SetTrafficLightRequest:
|
65
|
+
req = ParseDict(req, light_service.SetTrafficLightRequest())
|
66
|
+
res = cast(
|
67
|
+
Awaitable[light_service.SetTrafficLightResponse],
|
68
|
+
self._aio_stub.SetTrafficLight(req),
|
69
|
+
)
|
70
|
+
return async_parse(res, dict_return)
|
71
|
+
|
72
|
+
def SetTrafficLightPhase(
|
73
|
+
self,
|
74
|
+
req: Union[light_service.SetTrafficLightPhaseRequest, dict],
|
75
|
+
dict_return: bool = True,
|
76
|
+
) -> Coroutine[
|
77
|
+
Any, Any, Union[Dict[str, Any], light_service.SetTrafficLightPhaseResponse]
|
78
|
+
]:
|
79
|
+
"""
|
80
|
+
设置路口的红绿灯相位
|
81
|
+
Set traffic light phase
|
82
|
+
|
83
|
+
Args:
|
84
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightPhaseRequest
|
85
|
+
|
86
|
+
Returns:
|
87
|
+
- https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightPhaseResponse
|
88
|
+
"""
|
89
|
+
if type(req) != light_service.SetTrafficLightPhaseRequest:
|
90
|
+
req = ParseDict(req, light_service.SetTrafficLightPhaseRequest())
|
91
|
+
res = cast(
|
92
|
+
Awaitable[light_service.SetTrafficLightPhaseResponse],
|
93
|
+
self._aio_stub.SetTrafficLightPhase(req),
|
94
|
+
)
|
95
|
+
return async_parse(res, dict_return)
|
96
|
+
|
97
|
+
def SetTrafficLightStatus(
|
98
|
+
self,
|
99
|
+
req: Union[light_service.SetTrafficLightStatusRequest, dict],
|
100
|
+
dict_return: bool = True,
|
101
|
+
) -> Coroutine[
|
102
|
+
Any, Any, Union[Dict[str, Any], light_service.SetTrafficLightStatusResponse]
|
103
|
+
]:
|
104
|
+
"""
|
105
|
+
设置路口的红绿灯状态
|
106
|
+
Set traffic light status
|
107
|
+
|
108
|
+
Args:
|
109
|
+
- req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightStatusRequest
|
110
|
+
|
111
|
+
Returns:
|
112
|
+
- https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightStatusResponse
|
113
|
+
"""
|
114
|
+
if type(req) != light_service.SetTrafficLightStatusRequest:
|
115
|
+
req = ParseDict(req, light_service.SetTrafficLightStatusRequest())
|
116
|
+
res = cast(
|
117
|
+
Awaitable[light_service.SetTrafficLightStatusResponse],
|
118
|
+
self._aio_stub.SetTrafficLightStatus(req),
|
119
|
+
)
|
120
|
+
return async_parse(res, dict_return)
|