Пример #1
0
    def test_update_schedules_infeasible_schedule(self):
        network = ChargingNetwork()
        network.register_evse(EVSE("PS-001"), 240, 0)
        network.register_evse(EVSE("PS-004"), 240, 0)
        network.register_evse(EVSE("PS-003"), 240, 0)
        network.register_evse(EVSE("PS-002"), 240, 0)
        network.register_evse(EVSE("PS-006"), 240, 0)
        curr_dict1 = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
        current1 = Current(curr_dict1)
        curr_dict2 = {"PS-006": 0.30, "PS-004": -0.60, "PS-002": 0.50}
        current2 = Current(curr_dict2)
        network.add_constraint(current1, 50, name="first_constraint")
        network.add_constraint(current2, 10)
        start = Mock(datetime)
        scheduler = create_autospec(BaseAlgorithm)
        scheduler.max_recompute = None
        events = EventQueue(events=[Event(1), Event(2)])
        simulator = Simulator(network, scheduler, events, start)

        bad_schedule = {
            "PS-001": [200, 0, 160, 0],
            "PS-004": [0, 0, 0, 0],
            "PS-003": [0, 0, 0, 0],
            "PS-002": [0, 0, 26, 0],
            "PS-006": [0, 0, 0, 40],
        }
        with self.assertWarnsRegex(
            UserWarning,
            r"Invalid schedule provided at iteration 0. "
            r"Max violation is 2.9999\d+? A on _const_1 at time index 2.",
        ):
            simulator._update_schedules(bad_schedule)
Пример #2
0
 def _accessor_test_setup(self) -> None:
     evse1 = EVSE("PS-001")
     evse2 = EVSE("PS-002")
     evse3 = EVSE("PS-003")
     self.network.register_evse(evse1, 240, -30)
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
Пример #3
0
    def test_plugin_station_exists(self):
        evse = EVSE("PS-001")
        evse.plugin = Mock(evse.plugin)
        self.network.register_evse(evse, 240, 0)
        ev = create_autospec(EV)

        self.network.plugin(ev, "PS-001")
        evse.plugin.assert_called_once()
Пример #4
0
 def test_voltage_accessor(self):
     evse1 = EVSE('PS-001')
     evse2 = EVSE('PS-002')
     evse3 = EVSE('PS-003')
     self.network.register_evse(evse1, 240, -30)
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
     self.assertEqual(self.network.voltages,
         {'PS-001' : 240, 'PS-003' : 100, 'PS-002' : 140})
Пример #5
0
 def test_plugin_station_exists(self) -> None:
     evse = EVSE("PS-001")
     evse.plugin = Mock(evse.plugin)
     self.network.register_evse(evse, 240, 0)
     ev = create_autospec(EV)
     ev.station_id = "PS-001"
     self.network.plugin(ev)
     # noinspection PyUnresolvedReferences
     evse.plugin.assert_called_once()
Пример #6
0
    def _unplug_test_setup_helper(self, real_session_id: str) -> EVSE:
        evse = EVSE("PS-001")
        ev = create_autospec(EV)
        ev.station_id = "PS-001"
        ev.session_id = real_session_id
        evse.plugin(ev)

        self.network.register_evse(evse, 240, 0)
        return evse
Пример #7
0
 def test_phase_angles_accessor(self):
     evse1 = EVSE('PS-001')
     evse2 = EVSE('PS-002')
     evse3 = EVSE('PS-003')
     self.network.register_evse(evse1, 240, -30)
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
     self.assertEqual(self.network.phase_angles,
         {'PS-001' : -30, 'PS-003' : 150, 'PS-002' : 90})
Пример #8
0
 def test_voltage_accessor(self):
     evse1 = EVSE("PS-001")
     evse2 = EVSE("PS-002")
     evse3 = EVSE("PS-003")
     self.network.register_evse(evse1, 240, -30)
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
     self.assertEqual(
         self.network.voltages, {"PS-001": 240, "PS-003": 100, "PS-002": 140}
     )
Пример #9
0
 def test_phase_angles_accessor(self):
     evse1 = EVSE("PS-001")
     evse2 = EVSE("PS-002")
     evse3 = EVSE("PS-003")
     self.network.register_evse(evse1, 240, -30)
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
     self.assertEqual(
         self.network.phase_angles, {"PS-001": -30, "PS-003": 150, "PS-002": 90}
     )
Пример #10
0
 def setUp(self):
     self.simulator = create_autospec(Simulator)
     self.network = ChargingNetwork()
     self.simulator.network = self.network
     self.interface = Interface(self.simulator)
     evse1 = EVSE('PS-001')
     self.network.register_evse(evse1, 120, -30)
     evse2 = EVSE('PS-002')
     evse3 = EVSE('PS-003')
     self.network.register_evse(evse3, 360, 150)
     self.network.register_evse(evse2, 240, 90)
Пример #11
0
 def setUp(self):
     self.network = ChargingNetwork()
     self.network.register_evse(EVSE("PS-001"), 240, 0)
     self.network.register_evse(EVSE("PS-004"), 240, 0)
     self.network.register_evse(EVSE("PS-003"), 240, 0)
     self.network.register_evse(EVSE("PS-002"), 240, 0)
     self.network.register_evse(EVSE("PS-006"), 240, 0)
     curr_dict1 = {"PS-001": 0.25, "PS-002": 0.50, "PS-003": -0.25}
     current1 = Current(curr_dict1)
     curr_dict2 = {"PS-006": 0.30, "PS-004": -0.60, "PS-002": 0.50}
     current2 = Current(curr_dict2)
     self.network.add_constraint(current1, 50, name="first_constraint")
     self.network.add_constraint(current2, 10)
Пример #12
0
 def setUp(self):
     self.network = ChargingNetwork()
     self.network.register_evse(EVSE('PS-001'), 240, 0)
     self.network.register_evse(EVSE('PS-004'), 240, 0)
     self.network.register_evse(EVSE('PS-003'), 240, 0)
     self.network.register_evse(EVSE('PS-002'), 240, 0)
     self.network.register_evse(EVSE('PS-006'), 240, 0)
     curr_dict1 = {'PS-001' : 0.25, 'PS-002' : 0.50, 'PS-003' : -0.25}
     current1 = Current(curr_dict1)
     curr_dict2 = {'PS-006' : 0.30, 'PS-004' : -0.60, 'PS-002' : 0.50}
     current2 = Current(curr_dict2)
     self.network.add_constraint(current1, 50, name='first_constraint')
     self.network.add_constraint(current2, 10)
Пример #13
0
 def setUp(self):
     start = Mock(datetime)
     network = ChargingNetwork()
     evse1 = EVSE("PS-001", max_rate=32)
     network.register_evse(evse1, 240, 0)
     evse2 = EVSE("PS-002", max_rate=32)
     network.register_evse(evse2, 240, 0)
     evse3 = EVSE("PS-003", max_rate=32)
     network.register_evse(evse3, 240, 0)
     self.scheduler = BaseAlgorithm()
     self.scheduler.max_recompute = None
     events = EventQueue(events=[Event(1), Event(2)])
     self.simulator = Simulator(network, self.scheduler, events, start)
Пример #14
0
 def test_unplug_no_ev(self) -> None:
     evse = EVSE("PS-001")
     self.network.register_evse(evse, 240, 0)
     with patch.object(evse, "unplug") as unplug:
         with self.assertWarns(UserWarning):
             self.network.unplug("PS-001", "Session-01")
     unplug.assert_not_called()
Пример #15
0
 def test_register_evse(self):
     evse1 = EVSE('PS-001')
     self.network.register_evse(evse1, 240, -30)
     evse2 = EVSE('PS-002')
     evse3 = EVSE('PS-003')
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
     self.assertIn('PS-001', self.network._EVSEs)
     self.assertIs(self.network._EVSEs['PS-001'], evse1)
     self.assertIn('PS-002', self.network._EVSEs)
     self.assertIs(self.network._EVSEs['PS-002'], evse2)
     self.assertIn('PS-003', self.network._EVSEs)
     self.assertIs(self.network._EVSEs['PS-003'], evse3)
     self.assertEqual(self.network.station_ids, ['PS-001', 'PS-003', 'PS-002'])
     np.testing.assert_allclose(self.network._phase_angles, np.array([-30, 150, 90]))
     np.testing.assert_allclose(self.network._voltages, np.array([240, 100, 140]))
Пример #16
0
 def test_register_evse(self):
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 240, -30)
     evse2 = EVSE("PS-002")
     evse3 = EVSE("PS-003")
     self.network.register_evse(evse3, 100, 150)
     self.network.register_evse(evse2, 140, 90)
     self.assertIn("PS-001", self.network._EVSEs)
     self.assertIs(self.network._EVSEs["PS-001"], evse1)
     self.assertIn("PS-002", self.network._EVSEs)
     self.assertIs(self.network._EVSEs["PS-002"], evse2)
     self.assertIn("PS-003", self.network._EVSEs)
     self.assertIs(self.network._EVSEs["PS-003"], evse3)
     self.assertEqual(self.network.station_ids, ["PS-001", "PS-003", "PS-002"])
     np.testing.assert_allclose(self.network._phase_angles, np.array([-30, 150, 90]))
     np.testing.assert_allclose(self.network._voltages, np.array([240, 100, 140]))
Пример #17
0
 def test_update_pilots_valid_pilots(self):
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 240, 0)
     evse2 = EVSE("PS-002")
     self.network.register_evse(evse2, 240, 0)
     evse3 = EVSE("PS-003")
     self.network.register_evse(evse3, 240, 0)
     evse1.set_pilot = create_autospec(evse1.set_pilot)
     evse2.set_pilot = create_autospec(evse2.set_pilot)
     evse3.set_pilot = create_autospec(evse3.set_pilot)
     self.network.update_pilots(np.array([[24, 16], [16, 24], [0, 0]]), 0, 5)
     evse1.set_pilot.assert_any_call(24, 240, 5)
     evse2.set_pilot.assert_any_call(16, 240, 5)
     evse3.set_pilot.assert_any_call(0, 240, 5)
Пример #18
0
 def setUp(self) -> None:
     """ Run this setup function once before each test. """
     self.simulator = create_autospec(Simulator)
     self.network = ChargingNetwork()
     self.simulator.network = self.network
     self.interface = Interface(self.simulator)
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 120, -30)
     evse2 = EVSE("PS-002")
     evse3 = DeadbandEVSE("PS-003")
     self.network.register_evse(evse3, 360, 150)
     self.network.register_evse(evse2, 240, 90)
     # Include a FiniteRatesEVSE for more thorough testing.
     self.allowable_rates: List[int] = [0, 8, 16, 24, 32]
     evse4: FiniteRatesEVSE = FiniteRatesEVSE("PS-004",
                                              self.allowable_rates)
     self.network.register_evse(evse4, 120, -30)
     for i, station_id in enumerate(self.network.station_ids):
         self.network.add_constraint(Current(station_id), 1, f"C{i+1}")
Пример #19
0
 def setUp(self) -> None:
     """ Run this setup function once before each test. """
     self.simulator = create_autospec(Simulator)
     self.network = ChargingNetwork()
     self.simulator.network = self.network
     self.interface = Interface(self.simulator)
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 120, -30)
     evse2 = EVSE("PS-002")
     evse3 = DeadbandEVSE("PS-003")
     self.network.register_evse(evse3, 360, 150)
     self.network.register_evse(evse2, 240, 90)
     # Include a FiniteRatesEVSE for more thorough testing.
     self.allowable_rates: List[int] = [0, 8, 16, 24, 32]
     evse4: FiniteRatesEVSE = FiniteRatesEVSE("PS-004",
                                              self.allowable_rates)
     self.network.register_evse(evse4, 120, -30)
     self.network.constraint_matrix = np.eye(4)
     self.network.magnitudes = np.ones((4, 1))
     self.network.constraint_index = ["C1", "C2", "C3", "C4"]
Пример #20
0
 def setUp(self):
     self.max_rate = 32
     self.mid_rate = 16
     self.atol = 1e-3
     self.evse = EVSE("0001", max_rate=self.max_rate)
Пример #21
0
class TestEVSE(TestCase):
    def setUp(self):
        self.max_rate = 32
        self.mid_rate = 16
        self.atol = 1e-3
        self.evse = EVSE("0001", max_rate=self.max_rate)

    def test_allowable_pilot_signals_default(self):
        inf_evse = EVSE("0001")
        self.assertEqual(inf_evse.allowable_pilot_signals, [0, float("inf")])

    def test_allowable_pilot_signals(self):
        self.assertEqual(self.evse.allowable_pilot_signals, [0, self.max_rate])

    def test_plugin_unoccupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)

    def test_plugin_occupied(self):
        ev = create_autospec(EV)
        ev2 = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)
        with self.assertRaises(StationOccupiedError):
            self.evse.plugin(ev2)

    def test_unplug_occupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def test_unplug_unoccupied(self):
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def _set_pilot_has_ev_valid_rate_helper(self, pilot):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.set_pilot(pilot, 240, 5)
        self.assertEqual(self.evse.current_pilot, pilot)
        self.evse.ev.charge.assert_called_once()

    def test_set_pilot_has_ev_valid_rate(self):
        self._set_pilot_has_ev_valid_rate_helper(self.mid_rate)

    def test_set_pilot_has_ev_almost_large_rate(self):
        self._set_pilot_has_ev_valid_rate_helper(
            self.max_rate + self.atol - self.atol / 1e2
        )

    def test_set_pilot_has_ev_almost_small_rate(self):
        self._set_pilot_has_ev_valid_rate_helper(-self.atol + self.atol / 1e2)

    def test_set_pilot_has_ev_negative_rate(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(-1, 240, 5)

    def _set_pilot_no_ev_invalid_rate_helper(self, pilot):
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(pilot, 240, 5)

    def test_set_pilot_no_ev_negative_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(-1)

    def test_set_pilot_no_ev_large_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(self.max_rate + 1)

    def test_set_pilot_no_ev_barely_large_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(
            self.max_rate + self.atol + self.atol / 1e2
        )

    def test_set_pilot_no_ev_barely_small_rate(self):
        self._set_pilot_no_ev_invalid_rate_helper(-self.atol - self.atol / 1e2)
Пример #22
0
 def test_allowable_pilot_signals_default(self):
     inf_evse = EVSE("0001")
     self.assertEqual(inf_evse.allowable_pilot_signals, [0, float("inf")])
Пример #23
0
 def test_register_evse_constraints_added_error(self) -> None:
     evse1 = EVSE("PS-001")
     self.network.register_evse(evse1, 240, -30)
     self.network.add_constraint(Current(["PS-001"]), 10)
     with self.assertRaises(EVSERegistrationError):
         self.network.register_evse(EVSE("PS-002"), 100, 150)
Пример #24
0
class TestEVSE(TestCase):
    def setUp(self):
        self.evse = EVSE('0001')

    def test_allowable_pilot_signals(self):
        self.assertEqual(self.evse.allowable_pilot_signals, [0, float('inf')])

    def test_plugin_unoccupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)

    def test_plugin_occupied(self):
        ev = create_autospec(EV)
        ev2 = create_autospec(EV)
        self.evse.plugin(ev)
        self.assertEqual(self.evse.ev, ev)
        with self.assertRaises(StationOccupiedError):
            self.evse.plugin(ev2)

    def test_unplug_occupied(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def test_unplug_unoccupied(self):
        self.evse.unplug()
        self.assertIsNone(self.evse.ev)

    def test_set_pilot_has_ev_valid_rate(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        self.evse.set_pilot(16, 240, 5)
        self.assertEqual(self.evse.current_pilot, 16)
        self.evse.ev.charge.assert_called_once()

    def test_set_pilot_has_ev_negative_rate(self):
        ev = create_autospec(EV)
        self.evse.plugin(ev)
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(-1, 240, 5)

    def test_set_pilot_no_ev_negative_rate(self):
        with self.assertRaises(InvalidRateError):
            self.evse.set_pilot(-1, 240, 5)
Пример #25
0
 def test_get_ev_station_exists(self):
     evse = EVSE("PS-001")
     ev = Mock(EV)
     evse.plugin(ev)
     self.network.register_evse(evse, 240, 0)
     self.assertIs(self.network.get_ev("PS-001"), ev)
Пример #26
0
 def test_unplug_station_exists(self):
     evse = EVSE("PS-001")
     evse.unplug = Mock(evse.unplug)
     self.network.register_evse(evse, 240, 0)
     self.network.unplug("PS-001")
     evse.unplug.assert_called_once()
Пример #27
0
 def test_allowable_pilot_signals_default(self):
     inf_evse = EVSE('0001')
     self.assertEqual(inf_evse.allowable_pilot_signals, [0, float('inf')])
Пример #28
0
 def setUp(self):
     self.evse = EVSE('0001')
Пример #29
0
 def setUp(self) -> None:
     """ Set up tests for ChargingNetwork. """
     self.network = StochasticNetwork()
     self.evse_ids = ["PS-001", "PS-002", "PS-003"]
     for evse_id in self.evse_ids:
         self.network.register_evse(EVSE(evse_id), 240, 0)