mirror of
				https://github.com/Akkudoktor-EOS/EOS.git
				synced 2025-10-31 06:46:20 +00:00 
			
		
		
		
	Optimization of the Inverter class to speed up scr calculation (#607)
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				docker-build / platform-excludes (push) Has been cancelled
				
			
		
			
				
	
				pre-commit / pre-commit (push) Has been cancelled
				
			
		
			
				
	
				Run Pytest on Pull Request / test (push) Has been cancelled
				
			
		
			
				
	
				docker-build / build (push) Has been cancelled
				
			
		
			
				
	
				docker-build / merge (push) Has been cancelled
				
			
		
			
				
	
				Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	docker-build / platform-excludes (push) Has been cancelled
				
			pre-commit / pre-commit (push) Has been cancelled
				
			Run Pytest on Pull Request / test (push) Has been cancelled
				
			docker-build / build (push) Has been cancelled
				
			docker-build / merge (push) Has been cancelled
				
			Close stale pull requests/issues / Find Stale issues and PRs (push) Has been cancelled
				
			* fix(ElecPriceEnergyCharts): get history series, update docs Signed-off-by: redmoon2711 <redmoon2711@gmx.de> * feat(inverter): using lookup table for calculate scr Signed-off-by: redmoon2711 <redmoon2711@gmx.de> --------- Signed-off-by: redmoon2711 <redmoon2711@gmx.de>
This commit is contained in:
		| @@ -25,6 +25,22 @@ class Inverter(DeviceBase): | ||||
|         self.parameters: Optional[InverterParameters] = None | ||||
|         super().__init__(parameters) | ||||
|  | ||||
|         self.scr_lookup: dict = {} | ||||
|  | ||||
|     def _calculate_scr(self, consumption: float, generation: float) -> float: | ||||
|         """Check if the consumption and production is in the lookup table. If not, calculate and store the value.""" | ||||
|         if consumption not in self.scr_lookup: | ||||
|             self.scr_lookup[consumption] = {} | ||||
|  | ||||
|         if generation not in self.scr_lookup[consumption]: | ||||
|             scr = self.self_consumption_predictor.calculate_self_consumption( | ||||
|                 consumption, generation | ||||
|             ) | ||||
|             self.scr_lookup[consumption][generation] = scr | ||||
|             return scr | ||||
|  | ||||
|         return self.scr_lookup[consumption][generation] | ||||
|  | ||||
|     def _setup(self) -> None: | ||||
|         if self.parameters is None: | ||||
|             raise ValueError(f"Parameters not set: {self.parameters}") | ||||
| @@ -60,9 +76,8 @@ class Inverter(DeviceBase): | ||||
|                 grid_import = -remaining_power  # Negative indicates feeding into the grid | ||||
|                 self_consumption = self.max_power_wh | ||||
|             else: | ||||
|                 scr = self.self_consumption_predictor.calculate_self_consumption( | ||||
|                     consumption, generation | ||||
|                 ) | ||||
|                 # Calculate scr with lookup table | ||||
|                 scr = self._calculate_scr(consumption, generation) | ||||
|  | ||||
|                 # Remaining power after consumption | ||||
|                 remaining_power = (generation - consumption) * scr  # EVQ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user