def test_observe_multiple_step_same_observation(self):
     observer = measurement_metrics.MeasurementObserver()
     observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP)
     observer.observe(env=_FAKE_ENV,
                      timestep=_TIMESTEP,
                      action=np.array([1]))
     observer.observe(env=_FAKE_ENV,
                      timestep=_TIMESTEP,
                      action=np.array([4]))
     observer.observe(env=_FAKE_ENV,
                      timestep=_TIMESTEP,
                      action=np.array([5]))
     self.assertEqual(
         {
             'measurement[0]_max': 1.0,
             'measurement[0]_mean': 1.0,
             'measurement[0]_p25': 1.0,
             'measurement[0]_p50': 1.0,
             'measurement[0]_p75': 1.0,
             'measurement[1]_max': -2.0,
             'measurement[1]_mean': -2.0,
             'measurement[1]_p25': -2.0,
             'measurement[1]_p50': -2.0,
             'measurement[1]_p75': -2.0,
             'measurement[0]_min': 1.0,
             'measurement[1]_min': -2.0,
         },
         observer.get_metrics(),
     )
    def test_observe_single_dimensions(self):
        observer = measurement_metrics.MeasurementObserver()
        observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP)
        single_obs_timestep = copy.deepcopy(_TIMESTEP)
        single_obs_timestep.observation = [1000.0, -50.0]

        observer.observe(env=_FAKE_ENV,
                         timestep=single_obs_timestep,
                         action=np.array([[1, 2], [3, 4]]))

        np.testing.assert_equal(
            {
                'measurement[0]_max': 1000.0,
                'measurement[0]_min': 1000.0,
                'measurement[0]_mean': 1000.0,
                'measurement[0]_p25': 1000.0,
                'measurement[0]_p50': 1000.0,
                'measurement[0]_p75': 1000.0,
                'measurement[1]_max': -50.0,
                'measurement[1]_mean': -50.0,
                'measurement[1]_p25': -50.0,
                'measurement[1]_p50': -50.0,
                'measurement[1]_p75': -50.0,
                'measurement[1]_min': -50.0,
            },
            observer.get_metrics(),
        )
 def test_observe_multiple_step(self):
     observer = measurement_metrics.MeasurementObserver()
     observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP)
     observer.observe(env=_FAKE_ENV,
                      timestep=_TIMESTEP,
                      action=np.array([1]))
     first_obs_timestep = copy.deepcopy(_TIMESTEP)
     first_obs_timestep.observation = [1000.0, -50.0]
     observer.observe(env=_FAKE_ENV,
                      timestep=first_obs_timestep,
                      action=np.array([4]))
     second_obs_timestep = copy.deepcopy(_TIMESTEP)
     second_obs_timestep.observation = [-1000.0, 500.0]
     observer.observe(env=_FAKE_ENV,
                      timestep=second_obs_timestep,
                      action=np.array([4]))
     self.assertEqual(
         {
             'measurement[0]_max': 1000.0,
             'measurement[0]_mean': 1.0 / 3,
             'measurement[0]_p25': -499.5,
             'measurement[0]_p50': 1.0,
             'measurement[0]_p75': 500.5,
             'measurement[1]_max': 500.0,
             'measurement[1]_mean': 448.0 / 3.0,
             'measurement[1]_p25': -26.0,
             'measurement[1]_p50': -2.0,
             'measurement[1]_p75': 249.0,
             'measurement[0]_min': -1000.0,
             'measurement[1]_min': -50.0,
         },
         observer.get_metrics(),
     )
 def test_observe_first(self):
     observer = measurement_metrics.MeasurementObserver()
     observer.observe_first(env=_FAKE_ENV, timestep=_TIMESTEP)
     self.assertEqual({}, observer.get_metrics())
 def test_observe_nothing(self):
     observer = measurement_metrics.MeasurementObserver()
     self.assertEqual({}, observer.get_metrics())
 def test_observe_empty_observation(self):
     observer = measurement_metrics.MeasurementObserver()
     empty_timestep = copy.deepcopy(_TIMESTEP)
     empty_timestep.observation = {}
     observer.observe_first(env=_FAKE_ENV, timestep=empty_timestep)
     self.assertEqual({}, observer.get_metrics())