def test_energy_origin(storage_strategy_test15, market_test15): storage_strategy_test15.event_activate() assert len(storage_strategy_test15.state.get_used_storage_share) == 1 assert storage_strategy_test15.state.get_used_storage_share[0] == EnergyOrigin( ESSEnergyOrigin.EXTERNAL, 15) storage_strategy_test15.area.current_market.trade = \ Trade('id', 'time', Offer('id', 20, 1.0, 'ChildArea'), 'ChildArea', 'FakeArea') storage_strategy_test15.event_trade(market_id=market_test15.id, trade=storage_strategy_test15.area.current_market.trade) assert len(storage_strategy_test15.state.get_used_storage_share) == 2 assert storage_strategy_test15.state.get_used_storage_share == [EnergyOrigin( ESSEnergyOrigin.EXTERNAL, 15), EnergyOrigin(ESSEnergyOrigin.LOCAL, 1)] storage_strategy_test15.area.current_market.trade = \ Trade('id', 'time', Offer('id', 20, 2.0, 'FakeArea'), 'FakeArea', 'A') storage_strategy_test15.event_trade(market_id=market_test15.id, trade=storage_strategy_test15.area.current_market.trade) assert len(storage_strategy_test15.state.get_used_storage_share) == 2 assert storage_strategy_test15.state.get_used_storage_share == [EnergyOrigin( ESSEnergyOrigin.EXTERNAL, 13), EnergyOrigin(ESSEnergyOrigin.LOCAL, 1)] storage_strategy_test15.area.current_market.trade = \ Trade('id', 'time', Offer('id', 20, 1.0, 'ParentArea'), 'FakeArea', 'FakeArea') storage_strategy_test15.event_trade(market_id=market_test15.id, trade=storage_strategy_test15.area.current_market.trade) assert len(storage_strategy_test15.state.get_used_storage_share) == 3 assert storage_strategy_test15.state.get_used_storage_share == [EnergyOrigin( ESSEnergyOrigin.EXTERNAL, 13), EnergyOrigin(ESSEnergyOrigin.LOCAL, 1), EnergyOrigin(ESSEnergyOrigin.EXTERNAL, 1)]
def _track_energy_sell_type(self, trade): energy = trade.offer.energy while limit_float_precision(energy) > 0: first_in_energy_with_origin = self.state.get_used_storage_share[0] if energy >= first_in_energy_with_origin.value: energy -= first_in_energy_with_origin.value self.state.get_used_storage_share.pop(0) elif energy < first_in_energy_with_origin.value: residual = first_in_energy_with_origin.value - energy self.state._used_storage_share[0] = \ EnergyOrigin(first_in_energy_with_origin.origin, residual) energy = 0