pycityagent 2.0.0a43__cp39-cp39-macosx_11_0_arm64.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.
Files changed (81) hide show
  1. pycityagent/__init__.py +23 -0
  2. pycityagent/agent.py +833 -0
  3. pycityagent/cli/wrapper.py +44 -0
  4. pycityagent/economy/__init__.py +5 -0
  5. pycityagent/economy/econ_client.py +355 -0
  6. pycityagent/environment/__init__.py +7 -0
  7. pycityagent/environment/interact/__init__.py +0 -0
  8. pycityagent/environment/interact/interact.py +198 -0
  9. pycityagent/environment/message/__init__.py +0 -0
  10. pycityagent/environment/sence/__init__.py +0 -0
  11. pycityagent/environment/sence/static.py +416 -0
  12. pycityagent/environment/sidecar/__init__.py +8 -0
  13. pycityagent/environment/sidecar/sidecarv2.py +109 -0
  14. pycityagent/environment/sim/__init__.py +29 -0
  15. pycityagent/environment/sim/aoi_service.py +39 -0
  16. pycityagent/environment/sim/client.py +126 -0
  17. pycityagent/environment/sim/clock_service.py +44 -0
  18. pycityagent/environment/sim/economy_services.py +192 -0
  19. pycityagent/environment/sim/lane_service.py +111 -0
  20. pycityagent/environment/sim/light_service.py +122 -0
  21. pycityagent/environment/sim/person_service.py +295 -0
  22. pycityagent/environment/sim/road_service.py +39 -0
  23. pycityagent/environment/sim/sim_env.py +145 -0
  24. pycityagent/environment/sim/social_service.py +59 -0
  25. pycityagent/environment/simulator.py +331 -0
  26. pycityagent/environment/utils/__init__.py +14 -0
  27. pycityagent/environment/utils/base64.py +16 -0
  28. pycityagent/environment/utils/const.py +244 -0
  29. pycityagent/environment/utils/geojson.py +24 -0
  30. pycityagent/environment/utils/grpc.py +57 -0
  31. pycityagent/environment/utils/map_utils.py +157 -0
  32. pycityagent/environment/utils/port.py +11 -0
  33. pycityagent/environment/utils/protobuf.py +41 -0
  34. pycityagent/llm/__init__.py +11 -0
  35. pycityagent/llm/embeddings.py +231 -0
  36. pycityagent/llm/llm.py +377 -0
  37. pycityagent/llm/llmconfig.py +13 -0
  38. pycityagent/llm/utils.py +6 -0
  39. pycityagent/memory/__init__.py +13 -0
  40. pycityagent/memory/const.py +43 -0
  41. pycityagent/memory/faiss_query.py +302 -0
  42. pycityagent/memory/memory.py +448 -0
  43. pycityagent/memory/memory_base.py +170 -0
  44. pycityagent/memory/profile.py +165 -0
  45. pycityagent/memory/self_define.py +165 -0
  46. pycityagent/memory/state.py +173 -0
  47. pycityagent/memory/utils.py +28 -0
  48. pycityagent/message/__init__.py +3 -0
  49. pycityagent/message/messager.py +88 -0
  50. pycityagent/metrics/__init__.py +6 -0
  51. pycityagent/metrics/mlflow_client.py +147 -0
  52. pycityagent/metrics/utils/const.py +0 -0
  53. pycityagent/pycityagent-sim +0 -0
  54. pycityagent/pycityagent-ui +0 -0
  55. pycityagent/simulation/__init__.py +8 -0
  56. pycityagent/simulation/agentgroup.py +580 -0
  57. pycityagent/simulation/simulation.py +634 -0
  58. pycityagent/simulation/storage/pg.py +184 -0
  59. pycityagent/survey/__init__.py +4 -0
  60. pycityagent/survey/manager.py +54 -0
  61. pycityagent/survey/models.py +120 -0
  62. pycityagent/utils/__init__.py +11 -0
  63. pycityagent/utils/avro_schema.py +109 -0
  64. pycityagent/utils/decorators.py +99 -0
  65. pycityagent/utils/parsers/__init__.py +13 -0
  66. pycityagent/utils/parsers/code_block_parser.py +37 -0
  67. pycityagent/utils/parsers/json_parser.py +86 -0
  68. pycityagent/utils/parsers/parser_base.py +60 -0
  69. pycityagent/utils/pg_query.py +92 -0
  70. pycityagent/utils/survey_util.py +53 -0
  71. pycityagent/workflow/__init__.py +26 -0
  72. pycityagent/workflow/block.py +211 -0
  73. pycityagent/workflow/prompt.py +79 -0
  74. pycityagent/workflow/tool.py +240 -0
  75. pycityagent/workflow/trigger.py +163 -0
  76. pycityagent-2.0.0a43.dist-info/LICENSE +21 -0
  77. pycityagent-2.0.0a43.dist-info/METADATA +235 -0
  78. pycityagent-2.0.0a43.dist-info/RECORD +81 -0
  79. pycityagent-2.0.0a43.dist-info/WHEEL +5 -0
  80. pycityagent-2.0.0a43.dist-info/entry_points.txt +3 -0
  81. pycityagent-2.0.0a43.dist-info/top_level.txt +3 -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,44 @@
1
+ from collections.abc import Awaitable, Coroutine
2
+ from typing import Any, Dict, Union, cast
3
+
4
+ import grpc
5
+ from google.protobuf.json_format import ParseDict
6
+ from pycityproto.city.clock.v1 import clock_service_pb2 as clock_service
7
+ from pycityproto.city.clock.v1 import clock_service_pb2_grpc as clock_grpc
8
+
9
+ from ..utils.protobuf import async_parse
10
+
11
+ __all__ = ["ClockService"]
12
+
13
+
14
+ class ClockService:
15
+ """
16
+ 城市模拟时间服务
17
+ City simulation clock service
18
+ """
19
+
20
+ def __init__(self, aio_channel: grpc.aio.Channel):
21
+ self._aio_stub = clock_grpc.ClockServiceStub(aio_channel)
22
+
23
+ def Now(
24
+ self,
25
+ req: Union[clock_service.NowRequest, dict],
26
+ dict_return: bool = True,
27
+ ) -> Coroutine[Any, Any, Union[Dict[str, Any], clock_service.NowResponse]]:
28
+ """
29
+ 获取当前的模拟时间请求
30
+ Getting current simulation clock
31
+
32
+ Args:
33
+ - req (dict): https://cityproto.sim.fiblab.net/#city.clock.v1.NowRequest
34
+
35
+ Returns:
36
+ - https://cityproto.sim.fiblab.net/#city.clock.v1.NowResponse
37
+ """
38
+ if type(req) != clock_service.NowRequest:
39
+ req = ParseDict(req, clock_service.NowRequest())
40
+ res = cast(
41
+ Awaitable[clock_service.NowResponse],
42
+ self._aio_stub.Now(req),
43
+ )
44
+ return async_parse(res, dict_return)
@@ -0,0 +1,192 @@
1
+ from typing import Any, cast, Union
2
+ from collections.abc import Awaitable, Coroutine
3
+
4
+ import grpc
5
+ from google.protobuf.json_format import ParseDict
6
+ from pycityproto.city.economy.v1 import org_service_pb2 as org_service
7
+ from pycityproto.city.economy.v1 import org_service_pb2_grpc as org_grpc
8
+ from pycityproto.city.economy.v1 import person_service_pb2 as person_service
9
+ from pycityproto.city.economy.v1 import person_service_pb2_grpc as person_grpc
10
+
11
+ from ..utils.protobuf import async_parse
12
+
13
+ __all__ = ["EconomyPersonService", "EconomyOrgService"]
14
+
15
+
16
+ class EconomyPersonService:
17
+ """
18
+ 城市模拟经济服务(个人)
19
+ City simulation economic service (personal)
20
+ """
21
+
22
+ def __init__(self, aio_channel: grpc.aio.Channel):
23
+ self._aio_stub = person_grpc.PersonServiceStub(aio_channel)
24
+
25
+ def GetPerson(
26
+ self,
27
+ req: Union[person_service.GetPersonRequest, dict],
28
+ dict_return: bool = True,
29
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], person_service.GetPersonResponse]]:
30
+ """
31
+ 批量查询人的经济情况(资金、雇佣关系)
32
+ Query person’s economic situation (funds, employment relationship) in batches
33
+
34
+ Args:
35
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.GetPersonRequest
36
+
37
+ Returns:
38
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.GetPersonResponse
39
+ """
40
+ if type(req) != person_service.GetPersonRequest:
41
+ req = ParseDict(req, person_service.GetPersonRequest())
42
+ res = cast(
43
+ Awaitable[person_service.GetPersonResponse], self._aio_stub.GetPerson(req)
44
+ )
45
+ return async_parse(res, dict_return)
46
+
47
+ def UpdatePersonMoney(
48
+ self,
49
+ req: Union[person_service.UpdatePersonMoneyRequest, dict],
50
+ dict_return: bool = True,
51
+ ) -> Coroutine[
52
+ Any, Any, Union[dict[str, Any], person_service.UpdatePersonMoneyResponse]
53
+ ]:
54
+ """
55
+ 批量修改人的资金
56
+ Modify person’s money in batches
57
+
58
+ Args:
59
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdatePersonMoneyRequest
60
+
61
+ Returns:
62
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.UpdatePersonMoneyResponse
63
+ """
64
+ if type(req) != person_service.UpdatePersonMoneyRequest:
65
+ req = ParseDict(req, person_service.UpdatePersonMoneyRequest())
66
+ res = cast(
67
+ Awaitable[person_service.UpdatePersonMoneyResponse],
68
+ self._aio_stub.UpdatePersonMoney(req),
69
+ )
70
+ return async_parse(res, dict_return)
71
+
72
+
73
+ class EconomyOrgService:
74
+ """
75
+ 城市模拟经济服务(组织)
76
+ City simulation economic service (organizational)
77
+ """
78
+
79
+ def __init__(self, aio_channel: grpc.aio.Channel):
80
+ self._aio_stub = org_grpc.OrgServiceStub(aio_channel)
81
+
82
+ def GetOrg(
83
+ self, req: Union[org_service.GetOrgRequest, dict], dict_return: bool = True
84
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.GetOrgResponse]]:
85
+ """
86
+ 批量查询组织的经济情况(员工、岗位、资金、货物)
87
+ Query the economic status of the organization (employees, positions, funds, goods) in batches
88
+
89
+ Args:
90
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.GetOrgRequest
91
+
92
+ Returns:
93
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.GetOrgResponse
94
+ """
95
+ if type(req) != org_service.GetOrgRequest:
96
+ req = ParseDict(req, org_service.GetOrgRequest())
97
+ res = cast(Awaitable[org_service.GetOrgResponse], self._aio_stub.GetOrg(req))
98
+ return async_parse(res, dict_return)
99
+
100
+ def UpdateOrgMoney(
101
+ self,
102
+ req: Union[org_service.UpdateOrgMoneyRequest, dict],
103
+ dict_return: bool = True,
104
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.UpdateOrgMoneyResponse]]:
105
+ """
106
+ 批量修改组织的资金
107
+ Modify organization’s money in batches
108
+
109
+ Args:
110
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgMoneyRequest
111
+
112
+ Returns:
113
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgMoneyResponse
114
+ """
115
+ if type(req) != org_service.UpdateOrgMoneyRequest:
116
+ req = ParseDict(req, org_service.UpdateOrgMoneyRequest())
117
+ res = cast(
118
+ Awaitable[org_service.UpdateOrgMoneyResponse],
119
+ self._aio_stub.UpdateOrgMoney(req),
120
+ )
121
+ return async_parse(res, dict_return)
122
+
123
+ def UpdateOrgGoods(
124
+ self,
125
+ req: Union[org_service.UpdateOrgGoodsRequest, dict],
126
+ dict_return: bool = True,
127
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.UpdateOrgGoodsResponse]]:
128
+ """
129
+ 批量修改组织的货物
130
+ Modify organization’s goods in batches
131
+
132
+ Args:
133
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgGoodsRequest
134
+
135
+ Returns:
136
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgGoodsResponse
137
+ """
138
+ if type(req) != org_service.UpdateOrgGoodsRequest:
139
+ req = ParseDict(req, org_service.UpdateOrgGoodsRequest())
140
+ res = cast(
141
+ Awaitable[org_service.UpdateOrgGoodsResponse],
142
+ self._aio_stub.UpdateOrgGoods(req),
143
+ )
144
+ return async_parse(res, dict_return)
145
+
146
+ def UpdateOrgEmployee(
147
+ self,
148
+ req: Union[org_service.UpdateOrgEmployeeRequest, dict],
149
+ dict_return: bool = True,
150
+ ) -> Coroutine[
151
+ Any, Any, Union[dict[str, Any], org_service.UpdateOrgEmployeeResponse]
152
+ ]:
153
+ """
154
+ 批量修改组织的员工
155
+ Modify organization’s emplpyees in batches
156
+
157
+ Args:
158
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgEmployeeRequest
159
+
160
+ Returns:
161
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgEmployeeResponse
162
+ """
163
+ if type(req) != org_service.UpdateOrgEmployeeRequest:
164
+ req = ParseDict(req, org_service.UpdateOrgEmployeeRequest())
165
+ res = cast(
166
+ Awaitable[org_service.UpdateOrgEmployeeResponse],
167
+ self._aio_stub.UpdateOrgEmployee(req),
168
+ )
169
+ return async_parse(res, dict_return)
170
+
171
+ def UpdateOrgJob(
172
+ self,
173
+ req: Union[org_service.UpdateOrgJobRequest, dict],
174
+ dict_return: bool = True,
175
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], org_service.UpdateOrgJobResponse]]:
176
+ """
177
+ 批量修改组织的岗位
178
+ Modify organization’s jobs in batches
179
+
180
+ Args:
181
+ - req (dict): https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgJobRequest
182
+
183
+ Returns:
184
+ - https://cityproto.sim.fiblab.net/#city.economy.v1.UpdateOrgJobResponse
185
+ """
186
+ if type(req) != org_service.UpdateOrgJobRequest:
187
+ req = ParseDict(req, org_service.UpdateOrgJobRequest())
188
+ res = cast(
189
+ Awaitable[org_service.UpdateOrgJobResponse],
190
+ self._aio_stub.UpdateOrgJob(req),
191
+ )
192
+ return async_parse(res, dict_return)
@@ -0,0 +1,111 @@
1
+ from typing import Any,cast, Union
2
+ from collections.abc import Awaitable, Coroutine
3
+
4
+ import grpc
5
+ from google.protobuf.json_format import ParseDict
6
+ from pycityproto.city.map.v2 import lane_service_pb2 as lane_service
7
+ from pycityproto.city.map.v2 import lane_service_pb2_grpc as lane_grpc
8
+
9
+ from ..utils.protobuf import async_parse
10
+
11
+ __all__ = ["LaneService"]
12
+
13
+
14
+ class LaneService:
15
+ """
16
+ 交通模拟lane服务
17
+ Traffic simulation lane service
18
+ """
19
+
20
+ def __init__(self, aio_channel: grpc.aio.Channel):
21
+ self._aio_stub = lane_grpc.LaneServiceStub(aio_channel)
22
+
23
+ def GetLane(
24
+ self, req: Union[lane_service.GetLaneRequest, dict], dict_return: bool = True
25
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], lane_service.GetLaneResponse]]:
26
+ """
27
+ 获取Lane的信息
28
+ Get Lane's information
29
+
30
+ Args:
31
+ - req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneRequest
32
+
33
+ Returns:
34
+ - https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneResponse
35
+ """
36
+ if type(req) != lane_service.GetLaneRequest:
37
+ req = ParseDict(req, lane_service.GetLaneRequest())
38
+ res = cast(Awaitable[lane_service.GetLaneResponse], self._aio_stub.GetLane(req))
39
+ return async_parse(res, dict_return)
40
+
41
+ def SetLaneMaxV(
42
+ self,
43
+ req: Union[lane_service.SetLaneMaxVRequest, dict],
44
+ dict_return: bool = True,
45
+ ) -> Coroutine[Any, Any, Union[dict[str, Any], lane_service.SetLaneMaxVResponse]]:
46
+ """
47
+ 设置Lane的最大速度(限速)
48
+ Set the maximum speed of Lane (speed limit)
49
+
50
+ Args:
51
+ - req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneMaxVRequest
52
+
53
+ Returns:
54
+ - https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneMaxVResponse
55
+ """
56
+ if type(req) != lane_service.SetLaneMaxVRequest:
57
+ req = ParseDict(req, lane_service.SetLaneMaxVRequest())
58
+ res = cast(
59
+ Awaitable[lane_service.SetLaneMaxVResponse], self._aio_stub.SetLaneMaxV(req)
60
+ )
61
+ return async_parse(res, dict_return)
62
+
63
+ def SetLaneRestriction(
64
+ self,
65
+ req: Union[lane_service.SetLaneRestrictionRequest, dict],
66
+ dict_return: bool = True,
67
+ ) -> Coroutine[
68
+ Any, Any, Union[dict[str, Any], lane_service.SetLaneRestrictionResponse]
69
+ ]:
70
+ """
71
+ 设置Lane的限制
72
+ Set the restriction of Lane
73
+
74
+ Args:
75
+ - req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneRestrictionRequest
76
+
77
+ Returns:
78
+ - https://cityproto.sim.fiblab.net/#city.map.v2.SetLaneRestrictionResponse
79
+ """
80
+ if type(req) != lane_service.SetLaneRestrictionRequest:
81
+ req = ParseDict(req, lane_service.SetLaneRestrictionRequest())
82
+ res = cast(
83
+ Awaitable[lane_service.SetLaneRestrictionResponse],
84
+ self._aio_stub.SetLaneRestriction(req),
85
+ )
86
+ return async_parse(res, dict_return)
87
+
88
+ def GetLaneByLongLatBBox(
89
+ self,
90
+ req: Union[lane_service.GetLaneByLongLatBBoxRequest, dict],
91
+ dict_return: bool = True,
92
+ ) -> Coroutine[
93
+ Any, Any, Union[dict[str, Any], lane_service.GetLaneByLongLatBBoxResponse]
94
+ ]:
95
+ """
96
+ 获取特定区域内的Lane的信息
97
+ Get lane information in a specific region
98
+
99
+ Args:
100
+ - req (dict): https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneByLongLatBBoxRequest
101
+
102
+ Returns:
103
+ - https://cityproto.sim.fiblab.net/#city.map.v2.GetLaneByLongLatBBoxResponse
104
+ """
105
+ if type(req) != lane_service.GetLaneByLongLatBBoxRequest:
106
+ req = ParseDict(req, lane_service.GetLaneByLongLatBBoxRequest())
107
+ res = cast(
108
+ Awaitable[lane_service.GetLaneByLongLatBBoxResponse],
109
+ self._aio_stub.GetLaneByLongLatBBox(req),
110
+ )
111
+ return async_parse(res, dict_return)
@@ -0,0 +1,122 @@
1
+ from collections.abc import Awaitable, Coroutine
2
+ from typing import Any, Union, cast
3
+
4
+ import grpc
5
+ from google.protobuf.json_format import ParseDict
6
+ from pycityproto.city.map.v2 import traffic_light_service_pb2 as light_service
7
+ from pycityproto.city.map.v2 import \
8
+ traffic_light_service_pb2_grpc as light_grpc
9
+
10
+ from ..utils.protobuf import async_parse
11
+
12
+ __all__ = ["LightService"]
13
+
14
+
15
+ class LightService:
16
+ """
17
+ 城市模拟信控服务
18
+ City simulation traffic light service
19
+ """
20
+
21
+ def __init__(self, aio_channel: grpc.aio.Channel):
22
+ self._aio_stub = light_grpc.TrafficLightServiceStub(aio_channel)
23
+
24
+ def GetTrafficLight(
25
+ self,
26
+ req: Union[light_service.GetTrafficLightRequest, dict[str, Any]],
27
+ dict_return: bool = True,
28
+ ) -> Coroutine[
29
+ Any, Any, Union[dict[str, Any], light_service.GetTrafficLightResponse]
30
+ ]:
31
+ """
32
+ 获取路口的红绿灯信息
33
+ Get traffic light information
34
+
35
+ Args:
36
+ - req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.GetTrafficLightRequest
37
+
38
+ Returns:
39
+ - https://cityproto.sim.fiblab.net/#city.traffic.v1.GetTrafficLightResponse
40
+ """
41
+ if type(req) != light_service.GetTrafficLightRequest:
42
+ req = ParseDict(req, light_service.GetTrafficLightRequest())
43
+ res = cast(
44
+ Awaitable[light_service.GetTrafficLightResponse],
45
+ self._aio_stub.GetTrafficLight(req),
46
+ )
47
+ return async_parse(res, dict_return)
48
+
49
+ def SetTrafficLight(
50
+ self,
51
+ req: Union[light_service.SetTrafficLightRequest, dict[str, Any]],
52
+ dict_return: bool = True,
53
+ ) -> Coroutine[
54
+ Any, Any, Union[dict[str, Any], light_service.SetTrafficLightResponse]
55
+ ]:
56
+ """
57
+ 设置路口的红绿灯信息
58
+ Set traffic light information
59
+
60
+ Args:
61
+ - req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightRequest
62
+
63
+ Returns:
64
+ - https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightResponse
65
+ """
66
+ if type(req) != light_service.SetTrafficLightRequest:
67
+ req = ParseDict(req, light_service.SetTrafficLightRequest())
68
+ res = cast(
69
+ Awaitable[light_service.SetTrafficLightResponse],
70
+ self._aio_stub.SetTrafficLight(req),
71
+ )
72
+ return async_parse(res, dict_return)
73
+
74
+ def SetTrafficLightPhase(
75
+ self,
76
+ req: Union[light_service.SetTrafficLightPhaseRequest, dict],
77
+ dict_return: bool = True,
78
+ ) -> Coroutine[
79
+ Any, Any, Union[dict[str, Any], light_service.SetTrafficLightPhaseResponse]
80
+ ]:
81
+ """
82
+ 设置路口的红绿灯相位
83
+ Set traffic light phase
84
+
85
+ Args:
86
+ - req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightPhaseRequest
87
+
88
+ Returns:
89
+ - https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightPhaseResponse
90
+ """
91
+ if type(req) != light_service.SetTrafficLightPhaseRequest:
92
+ req = ParseDict(req, light_service.SetTrafficLightPhaseRequest())
93
+ res = cast(
94
+ Awaitable[light_service.SetTrafficLightPhaseResponse],
95
+ self._aio_stub.SetTrafficLightPhase(req),
96
+ )
97
+ return async_parse(res, dict_return)
98
+
99
+ def SetTrafficLightStatus(
100
+ self,
101
+ req: Union[light_service.SetTrafficLightStatusRequest, dict],
102
+ dict_return: bool = True,
103
+ ) -> Coroutine[
104
+ Any, Any, Union[dict[str, Any], light_service.SetTrafficLightStatusResponse]
105
+ ]:
106
+ """
107
+ 设置路口的红绿灯状态
108
+ Set traffic light status
109
+
110
+ Args:
111
+ - req (dict): https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightStatusRequest
112
+
113
+ Returns:
114
+ - https://cityproto.sim.fiblab.net/#city.traffic.v1.SetTrafficLightStatusResponse
115
+ """
116
+ if type(req) != light_service.SetTrafficLightStatusRequest:
117
+ req = ParseDict(req, light_service.SetTrafficLightStatusRequest())
118
+ res = cast(
119
+ Awaitable[light_service.SetTrafficLightStatusResponse],
120
+ self._aio_stub.SetTrafficLightStatus(req),
121
+ )
122
+ return async_parse(res, dict_return)