Skip to content

Commit 81db577

Browse files
committed
chore: format
1 parent b28b385 commit 81db577

File tree

147 files changed

+11722
-11945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+11722
-11945
lines changed

src/adf_core_python/cli/cli.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,49 @@
88

99
@click.command()
1010
@click.option(
11-
"--name", prompt="Your agent team name", help="The name of your agent team"
11+
"--name", prompt="Your agent team name", help="The name of your agent team"
1212
)
1313
def cli(name: str) -> None:
14-
# load template dir and create a new agent team
15-
click.echo(f"Creating a new agent team with name: {name}")
16-
# 自身がいるディレクトリを取得
17-
template_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "template")
18-
# コマンドラインのカレントディレクトリを取得
19-
current_dir = os.getcwd()
14+
# load template dir and create a new agent team
15+
click.echo(f"Creating a new agent team with name: {name}")
16+
# 自身がいるディレクトリを取得
17+
template_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "template")
18+
# コマンドラインのカレントディレクトリを取得
19+
current_dir = os.getcwd()
2020

21-
_copy_template(
22-
template_dir,
23-
current_dir,
24-
name,
25-
)
21+
_copy_template(
22+
template_dir,
23+
current_dir,
24+
name,
25+
)
2626

2727

2828
def _copy_template(
29-
src: str,
30-
dest: str,
31-
name: str,
29+
src: str,
30+
dest: str,
31+
name: str,
3232
) -> None:
33-
dest = os.path.join(dest, name)
34-
shutil.copytree(src, dest)
35-
36-
# dest以下のファイル内のNAME_PLACEHOLDERをnameに置換
37-
for root, dirs, files in os.walk(dest):
38-
for file in files:
39-
file_path = os.path.join(root, file)
40-
with open(file_path, "r") as f:
41-
if not file_path.endswith((".py", ".yaml", ".json")):
42-
continue
43-
content = f.read()
44-
with open(file_path, "w") as f:
45-
f.write(content.replace(NAME_PLACEHOLDER, name))
46-
47-
# ディレクトリ名のNAME_PLACEHOLDERをnameに置換
48-
for root, dirs, files in os.walk(dest):
49-
for dir in dirs:
50-
dir_path = os.path.join(root, dir)
51-
new_dir_path = dir_path.replace(NAME_PLACEHOLDER, name)
52-
os.rename(dir_path, new_dir_path)
33+
dest = os.path.join(dest, name)
34+
shutil.copytree(src, dest)
35+
36+
# dest以下のファイル内のNAME_PLACEHOLDERをnameに置換
37+
for root, dirs, files in os.walk(dest):
38+
for file in files:
39+
file_path = os.path.join(root, file)
40+
with open(file_path, "r") as f:
41+
if not file_path.endswith((".py", ".yaml", ".json")):
42+
continue
43+
content = f.read()
44+
with open(file_path, "w") as f:
45+
f.write(content.replace(NAME_PLACEHOLDER, name))
46+
47+
# ディレクトリ名のNAME_PLACEHOLDERをnameに置換
48+
for root, dirs, files in os.walk(dest):
49+
for dir in dirs:
50+
dir_path = os.path.join(root, dir)
51+
new_dir_path = dir_path.replace(NAME_PLACEHOLDER, name)
52+
os.rename(dir_path, new_dir_path)
5353

5454

5555
if __name__ == "__main__":
56-
cli()
56+
cli()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from adf_core_python.launcher import Launcher
22

33
if __name__ == "__main__":
4-
launcher = Launcher("./config/launcher.yaml")
5-
launcher.launch()
4+
launcher = Launcher("./config/launcher.yaml")
5+
launcher.launch()

src/adf_core_python/cli/template/src/team_name/module/complex/sample_human_detector.py

Lines changed: 130 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -14,136 +14,135 @@
1414

1515

1616
class SampleHumanDetector(HumanDetector):
17-
def __init__(
18-
self,
19-
agent_info: AgentInfo,
20-
world_info: WorldInfo,
21-
scenario_info: ScenarioInfo,
22-
module_manager: ModuleManager,
23-
develop_data: DevelopData,
24-
) -> None:
25-
super().__init__(
26-
agent_info, world_info, scenario_info, module_manager, develop_data
17+
def __init__(
18+
self,
19+
agent_info: AgentInfo,
20+
world_info: WorldInfo,
21+
scenario_info: ScenarioInfo,
22+
module_manager: ModuleManager,
23+
develop_data: DevelopData,
24+
) -> None:
25+
super().__init__(
26+
agent_info, world_info, scenario_info, module_manager, develop_data
27+
)
28+
self._clustering: Clustering = cast(
29+
Clustering,
30+
module_manager.get_module(
31+
"SampleHumanDetector.Clustering",
32+
"adf_core_python.implement.module.algorithm.k_means_clustering.KMeansClustering",
33+
),
34+
)
35+
self.register_sub_module(self._clustering)
36+
37+
self._result: Optional[EntityID] = None
38+
self._logger = get_agent_logger(
39+
f"{self.__class__.__module__}.{self.__class__.__qualname__}",
40+
self._agent_info,
41+
)
42+
43+
def calculate(self) -> HumanDetector:
44+
transport_human: Optional[Human] = self._agent_info.some_one_on_board()
45+
if transport_human is not None:
46+
self._result = transport_human.get_entity_id()
47+
return self
48+
49+
if self._result is not None:
50+
if not self._is_valid_human(self._result):
51+
self._result = None
52+
53+
if self._result is None:
54+
self._result = self._select_target()
55+
56+
return self
57+
58+
def _select_target(self) -> Optional[EntityID]:
59+
if self._result is not None and self._is_valid_human(self._result):
60+
return self._result
61+
62+
cluster_index: int = self._clustering.get_cluster_index(
63+
self._agent_info.get_entity_id()
64+
)
65+
cluster_entities: list[Entity] = self._clustering.get_cluster_entities(
66+
cluster_index
67+
)
68+
69+
cluster_valid_human_entities: list[Entity] = [
70+
entity
71+
for entity in cluster_entities
72+
if self._is_valid_human(entity.get_entity_id()) and isinstance(entity, Civilian)
73+
]
74+
if len(cluster_valid_human_entities) != 0:
75+
nearest_human_entity = cluster_valid_human_entities[0]
76+
nearest_distance = self._world_info.get_distance(
77+
self._agent_info.get_entity_id(),
78+
nearest_human_entity.get_entity_id(),
79+
)
80+
for entity in cluster_valid_human_entities:
81+
distance = self._world_info.get_distance(
82+
self._agent_info.get_entity_id(),
83+
entity.get_entity_id(),
2784
)
28-
self._clustering: Clustering = cast(
29-
Clustering,
30-
module_manager.get_module(
31-
"SampleHumanDetector.Clustering",
32-
"adf_core_python.implement.module.algorithm.k_means_clustering.KMeansClustering",
33-
),
85+
if distance < nearest_distance:
86+
nearest_distance = distance
87+
nearest_human_entity = entity
88+
return nearest_human_entity.get_entity_id()
89+
90+
world_valid_human_entities: list[Entity] = [
91+
entity
92+
for entity in self._world_info.get_entities_of_types([Civilian])
93+
if self._is_valid_human(entity.get_entity_id())
94+
]
95+
if len(world_valid_human_entities) != 0:
96+
nearest_human_entity = world_valid_human_entities[0]
97+
nearest_distance = self._world_info.get_distance(
98+
self._agent_info.get_entity_id(),
99+
nearest_human_entity.get_entity_id(),
100+
)
101+
for entity in world_valid_human_entities:
102+
distance = self._world_info.get_distance(
103+
self._agent_info.get_entity_id(),
104+
entity.get_entity_id(),
34105
)
35-
self.register_sub_module(self._clustering)
36-
37-
self._result: Optional[EntityID] = None
38-
self._logger = get_agent_logger(
39-
f"{self.__class__.__module__}.{self.__class__.__qualname__}",
40-
self._agent_info,
41-
)
42-
43-
def calculate(self) -> HumanDetector:
44-
transport_human: Optional[Human] = self._agent_info.some_one_on_board()
45-
if transport_human is not None:
46-
self._result = transport_human.get_entity_id()
47-
return self
48-
49-
if self._result is not None:
50-
if not self._is_valid_human(self._result):
51-
self._result = None
52-
53-
if self._result is None:
54-
self._result = self._select_target()
55-
56-
return self
57-
58-
def _select_target(self) -> Optional[EntityID]:
59-
if self._result is not None and self._is_valid_human(self._result):
60-
return self._result
61-
62-
cluster_index: int = self._clustering.get_cluster_index(
63-
self._agent_info.get_entity_id()
64-
)
65-
cluster_entities: list[Entity] = self._clustering.get_cluster_entities(
66-
cluster_index
67-
)
68-
69-
cluster_valid_human_entities: list[Entity] = [
70-
entity
71-
for entity in cluster_entities
72-
if self._is_valid_human(entity.get_entity_id())
73-
and isinstance(entity, Civilian)
74-
]
75-
if len(cluster_valid_human_entities) != 0:
76-
nearest_human_entity = cluster_valid_human_entities[0]
77-
nearest_distance = self._world_info.get_distance(
78-
self._agent_info.get_entity_id(),
79-
nearest_human_entity.get_entity_id(),
80-
)
81-
for entity in cluster_valid_human_entities:
82-
distance = self._world_info.get_distance(
83-
self._agent_info.get_entity_id(),
84-
entity.get_entity_id(),
85-
)
86-
if distance < nearest_distance:
87-
nearest_distance = distance
88-
nearest_human_entity = entity
89-
return nearest_human_entity.get_entity_id()
90-
91-
world_valid_human_entities: list[Entity] = [
92-
entity
93-
for entity in self._world_info.get_entities_of_types([Civilian])
94-
if self._is_valid_human(entity.get_entity_id())
95-
]
96-
if len(world_valid_human_entities) != 0:
97-
nearest_human_entity = world_valid_human_entities[0]
98-
nearest_distance = self._world_info.get_distance(
99-
self._agent_info.get_entity_id(),
100-
nearest_human_entity.get_entity_id(),
101-
)
102-
for entity in world_valid_human_entities:
103-
distance = self._world_info.get_distance(
104-
self._agent_info.get_entity_id(),
105-
entity.get_entity_id(),
106-
)
107-
if distance < nearest_distance:
108-
nearest_distance = distance
109-
nearest_human_entity = entity
110-
return nearest_human_entity.get_entity_id()
111-
112-
return None
113-
114-
def _is_valid_human(self, target_entity_id: EntityID) -> bool:
115-
target: Optional[Entity] = self._world_info.get_entity(target_entity_id)
116-
if target is None:
117-
return False
118-
if not isinstance(target, Human):
119-
return False
120-
hp: Optional[int] = target.get_hp()
121-
if hp is None or hp <= 0:
122-
return False
123-
buriedness: Optional[int] = target.get_buriedness()
124-
if buriedness is None:
125-
return False
126-
myself = self._agent_info.get_myself()
127-
if myself is None:
128-
return False
129-
if myself.get_urn() == EntityURN.FIRE_BRIGADE and buriedness == 0:
130-
return False
131-
if myself.get_urn() == EntityURN.AMBULANCE_TEAM and buriedness > 0:
132-
return False
133-
damage: Optional[int] = target.get_damage()
134-
if damage is None or damage == 0:
135-
return False
136-
position_entity_id: Optional[EntityID] = target.get_position()
137-
if position_entity_id is None:
138-
return False
139-
position: Optional[Entity] = self._world_info.get_entity(position_entity_id)
140-
if position is None:
141-
return False
142-
urn: EntityURN = position.get_urn()
143-
if urn == EntityURN.REFUGE or urn == EntityURN.AMBULANCE_TEAM:
144-
return False
145-
146-
return True
147-
148-
def get_target_entity_id(self) -> Optional[EntityID]:
149-
return self._result
106+
if distance < nearest_distance:
107+
nearest_distance = distance
108+
nearest_human_entity = entity
109+
return nearest_human_entity.get_entity_id()
110+
111+
return None
112+
113+
def _is_valid_human(self, target_entity_id: EntityID) -> bool:
114+
target: Optional[Entity] = self._world_info.get_entity(target_entity_id)
115+
if target is None:
116+
return False
117+
if not isinstance(target, Human):
118+
return False
119+
hp: Optional[int] = target.get_hp()
120+
if hp is None or hp <= 0:
121+
return False
122+
buriedness: Optional[int] = target.get_buriedness()
123+
if buriedness is None:
124+
return False
125+
myself = self._agent_info.get_myself()
126+
if myself is None:
127+
return False
128+
if myself.get_urn() == EntityURN.FIRE_BRIGADE and buriedness == 0:
129+
return False
130+
if myself.get_urn() == EntityURN.AMBULANCE_TEAM and buriedness > 0:
131+
return False
132+
damage: Optional[int] = target.get_damage()
133+
if damage is None or damage == 0:
134+
return False
135+
position_entity_id: Optional[EntityID] = target.get_position()
136+
if position_entity_id is None:
137+
return False
138+
position: Optional[Entity] = self._world_info.get_entity(position_entity_id)
139+
if position is None:
140+
return False
141+
urn: EntityURN = position.get_urn()
142+
if urn == EntityURN.REFUGE or urn == EntityURN.AMBULANCE_TEAM:
143+
return False
144+
145+
return True
146+
147+
def get_target_entity_id(self) -> Optional[EntityID]:
148+
return self._result

0 commit comments

Comments
 (0)