Skip to content

Commit 219d768

Browse files
committed
clean code
1 parent 49a97af commit 219d768

File tree

1 file changed

+3
-19
lines changed

1 file changed

+3
-19
lines changed

server.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,7 @@
99
import argparse
1010

1111

12-
logging.basicConfig(level=logging.INFO)
13-
#put log into file as well as console
14-
# Create a custom logger
15-
logger = logging.getLogger('my_logger')
16-
logger.setLevel(logging.DEBUG) # Set the minimum logging level
17-
18-
# Create handlers: one for console, one for file
19-
console_handler = logging.StreamHandler()
20-
file_handler = logging.FileHandler('logfile.log')
21-
22-
# Set logging level for each handler
23-
console_handler.setLevel(logging.ERROR)
24-
file_handler.setLevel(logging.INFO)
25-
26-
# Add the handlers to the logger
27-
logger.addHandler(console_handler)
28-
logger.addHandler(file_handler)
12+
logging.basicConfig(level=logging.DEBUG)
2913

3014
class GrpcAgent:
3115
def __init__(self, agent_type, uniform_number) -> None:
@@ -162,11 +146,11 @@ def SendByeCommand(self, register_response: pb2.RegisterResponse, context):
162146
return res
163147

164148
def GetBestPlannerAction(self, pairs: pb2.BestPlannerActionRequest, context):
165-
logger.debug(f"GetBestPlannerAction cycle:{pairs.state.world_model.cycle} pairs:{len(pairs.pairs)} unum:{pairs.state.register_response.uniform_number}")
149+
logging.debug(f"GetBestPlannerAction cycle:{pairs.state.world_model.cycle} pairs:{len(pairs.pairs)} unum:{pairs.state.register_response.uniform_number}")
166150
pairs_list: list[int, pb2.RpcActionState] = [(k, v) for k, v in pairs.pairs.items()]
167151
pairs_list.sort(key=lambda x: x[0])
168152
best_action = max(pairs_list, key=lambda x: -1000 if x[1].action.parent_index != -1 else x[1].predict_state.ball_position.x)
169-
logger.debug(f"Best action: {best_action[0]} {best_action[1].action.description} to {best_action[1].action.target_unum} in ({round(best_action[1].action.target_point.x, 2)},{round(best_action[1].action.target_point.y, 2)}) e:{round(best_action[1].evaluation,2)}")
153+
logging.debug(f"Best action: {best_action[0]} {best_action[1].action.description} to {best_action[1].action.target_unum} in ({round(best_action[1].action.target_point.x, 2)},{round(best_action[1].action.target_point.y, 2)}) e:{round(best_action[1].evaluation,2)}")
170154
res = pb2.BestPlannerActionResponse(index=best_action[0])
171155
return res
172156

0 commit comments

Comments
 (0)