Skip to content

Commit

Permalink
fix: Load EER ratio even when end use is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaselhan committed Dec 11, 2024
1 parent 38279d5 commit a8c272f
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions backend/lcfs/web/api/fuel_code/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,18 +776,35 @@ async def get_provision_of_the_act_by_name(

@repo_handler
async def get_energy_effectiveness_ratio(
self, fuel_type_id: int, fuel_category_id: int, end_use_type_id: int
self, fuel_type_id: int, fuel_category_id: int, end_use_type_id: Optional[int]
) -> EnergyEffectivenessRatio:
"""
Retrieves the Energy Effectiveness Ratio based on fuel type, fuel category,
and optionally the end use type.
Args:
fuel_type_id (int): The ID of the fuel type.
fuel_category_id (int): The ID of the fuel category.
end_use_type_id (Optional[int]): The ID of the end use type (optional).
stmt = select(EnergyEffectivenessRatio).where(
Returns:
Optional[EnergyEffectivenessRatio]: The matching EnergyEffectivenessRatio record or None.
"""
conditions = [
EnergyEffectivenessRatio.fuel_type_id == fuel_type_id,
EnergyEffectivenessRatio.fuel_category_id == fuel_category_id,
EnergyEffectivenessRatio.end_use_type_id == end_use_type_id,
)
]

if end_use_type_id is not None:
conditions.append(
EnergyEffectivenessRatio.end_use_type_id == end_use_type_id
)

stmt = select(EnergyEffectivenessRatio).where(*conditions)
result = await self.db.execute(stmt)
energy_density = result.scalars().first()
energy_effectiveness_ratio = result.scalars().first()

return energy_density
return energy_effectiveness_ratio

@repo_handler
async def get_target_carbon_intensities(
Expand Down Expand Up @@ -848,12 +865,10 @@ async def get_standardized_fuel_data(
effective_carbon_intensity = fuel_type.default_carbon_intensity

# Get energy effectiveness ratio (EER)
eer = None
if fuel_type_id and fuel_category_id and end_use_id:
energy_effectiveness = await self.get_energy_effectiveness_ratio(
fuel_type_id, fuel_category_id, end_use_id
)
eer = energy_effectiveness.ratio if energy_effectiveness else 1.0
energy_effectiveness = await self.get_energy_effectiveness_ratio(
fuel_type_id, fuel_category_id, end_use_id
)
eer = energy_effectiveness.ratio if energy_effectiveness else 1.0

# Fetch target carbon intensity (TCI)
target_ci = None
Expand Down

0 comments on commit a8c272f

Please sign in to comment.