Ejemplo n.º 1
0
 def wait_for_simulator_request(
         self, sid: SimulationID,
         vid: VehicleID) -> SimStateResponse.SimState:
     """
     Waits for the simulation with ID sid to request the car with ID vid. This call blocks until the simulation
     requests the appropriate car in the given simulation.
     :param sid: The ID of the simulation the vehicle is included in.
     :param vid: The ID of the vehicle in the simulation to wait for.
     :return: The current state of the simulation at the point when the call to this function returns. The return
     value should be used to check whether the simulation is still running. Another vehicle or the even user may have
     stopped the simulation.
     """
     from drivebuildclient.httpUtil import do_get_request
     response = do_get_request(self.host, self.port,
                               "/ai/waitForSimulatorRequest", {
                                   "sid": sid.SerializeToString(),
                                   "vid": vid.SerializeToString()
                               })
     if response.status == 200:
         result = b"".join(response.readlines())
         sim_state = SimStateResponse()
         sim_state.ParseFromString(result)
         return sim_state.state
     else:
         AIExchangeService._print_error(response)
Ejemplo n.º 2
0
 def request_data(self, sid: SimulationID, vid: VehicleID,
                  request: DataRequest) -> DataResponse:
     """
     Request data of a certain vehicle contained by a certain simulation.
     :param sid: The ID of the simulation the vehicle to request data about is part of.
     :param vid: The ID of the vehicle to get collected data from.
     :param request: The types of data to be requested about the given vehicle. A DataRequest object is build like
     the following:
     request = DataRequest()
     request.request_ids.extend(["id_1", "id_2",..., "id_n"])
     NOTE: You have to use extend(...)! An assignment like request.request_ids = [...] will not work due to the
     implementation of Googles protobuffer.
     :return: The data the simulation collected about the given vehicle. The way of accessing the data is dependant
     on the type of data you requested. To find out how to access the data properly you should set a break point and
     checkout the content of the returned value using a debugger.
     """
     from drivebuildclient.httpUtil import do_get_request
     response = do_get_request(
         self.host, self.port, "/ai/requestData", {
             "request": request.SerializeToString(),
             "sid": sid.SerializeToString(),
             "vid": vid.SerializeToString()
         })
     if response.status == 200:
         result = b"".join(response.readlines())
         data_response = DataResponse()
         data_response.ParseFromString(result)
         return data_response
     else:
         AIExchangeService._print_error(response)
Ejemplo n.º 3
0
 def get_trace(
     self,
     sid: SimulationID,
     vid: Optional[VehicleID] = None
 ) -> List[Tuple[str, str, int, DataResponse]]:
     """
     Return all the collected data of a single or all participants in a simulation.
     :param sid: The simulation to request all the collected data from.
     :param vid: The vehicle whose collected data has to be returned. If None this method returns all the collected
     data.
     :return: The JSON serialized object representing all the collected data of a simulation or a participant in a
     simulation.
     """
     from drivebuildclient.httpUtil import do_get_request
     import dill as pickle
     args = {"sid": sid.SerializeToString()}
     if vid:
         args["vid"] = vid.SerializeToString()
     response = do_get_request(self.host, self.port, "/stats/trace", args)
     if response.status == 200:
         response_content = b"".join(response.readlines())
         trace_data = pickle.loads(response_content)
         trace = []
         for entry in trace_data:
             sid = SimulationID()
             sid.sid = str(entry[0])
             vid = VehicleID()
             vid.vid = entry[1]
             data = DataResponse()
             data.ParseFromString(entry[3])
             trace.append((sid, vid, entry[2], data))
         return trace
     else:
         AIExchangeService._print_error(response)
         return "The trace could not be retrieved."
Ejemplo n.º 4
0
 def get_status(self, sid: SimulationID) -> str:
     """
     Check the status of the given simulation.
     :param sid: The simulation to get the status of.
     :return: A string representing the status of the simulation like RUNNING, FINISHED or ERRORED.
     """
     from drivebuildclient.httpUtil import do_get_request
     import dill as pickle
     response = do_get_request(self.host, self.port, "/stats/status",
                               {"sid": sid.SerializeToString()})
     if response.status == 200:
         return pickle.loads(b"".join(response.readlines()))
     else:
         AIExchangeService._print_error(response)
         return "Status could not be determined."
Ejemplo n.º 5
0
 def get_running_tests(self, user: User) -> SubmissionResult.Submissions:
     """
     Return the currently running tests of the given user.
     :param user: The user to get a list of running simulation for.
     :return: The list of running simulations initiated by the given user.
     """
     from drivebuildclient.httpUtil import do_get_request
     response = do_get_request(self.host, self.port,
                               "/stats/getRunningSids",
                               {"user": user.SerializeToString()})
     if response.status == 200:
         submission_result = SubmissionResult()
         submission_result.ParseFromString(b"".join(response.readlines()))
         return submission_result.result
     else:
         AIExchangeService._print_error(response)
Ejemplo n.º 6
0
 def control_sim(self, sid: SimulationID,
                 result: TestResult) -> Optional[Void]:
     """
     Force a simulation to end having the given result.
     :param sid: The simulation to control.
     :param result: The test result to be set to the simulation.
     :return: A Void object possibly containing a info message.
     """
     from drivebuildclient.httpUtil import do_get_request
     response = do_get_request(self.host, self.port, "/sim/stop", {
         "sid": sid.SerializeToString(),
         "result": result.SerializeToString()
     })
     if response.status == 200:
         void = Void()
         void.ParseFromString(b"".join(response.readlines()))
         return void
     else:
         AIExchangeService._print_error(response)
Ejemplo n.º 7
0
 def get_result(self, sid: SimulationID) -> str:
     """
     Get the test result of the given simulation. This call blocks until the test result of the simulation is known.
     :param sid: The simulation to get the test result of.
     :return: The current test result of the given simulation like SUCCEEDED, FAILED or CANCELLED.
     """
     from drivebuildclient.httpUtil import do_get_request
     import dill as pickle
     from time import sleep
     while True:  # Pseudo do-while-loop
         response = do_get_request(self.host, self.port, "/stats/result",
                                   {"sid": sid.SerializeToString()})
         if response.status == 200:
             result = pickle.loads(b"".join(response.readlines()))
             if result == "UNKNOWN":
                 sleep(1)
             else:
                 return result
         else:
             AIExchangeService._print_error(response)
             return "Result could not be determined."