def effective_carbon_intensity(self): if self.provision_of_the_act is None: return None t = self.provision_of_the_act.determination_type.the_type if t == 'Alternative': return self.intensity if t == 'GHGenius': i = self.schedule_d_sheet_index sheets = self.schedule.compliance_report.schedule_d.sheets.all() return sheets[i].carbon_intensity if t == 'Fuel Code': if self.fuel_code is None: return None return self.fuel_code.carbon_intensity if t == 'Carbon Intensity' or t == 'Default Carbon Intensity': period = self.schedule.compliance_report.compliance_period if self.fuel_type.credit_calculation_only: obj = CreditCalculationService.get( category__name=self.fuel_type.name, effective_date=period.effective_date, model_name="PetroleumCarbonIntensity" ) return obj.density else: obj = CreditCalculationService.get( category__name=self.fuel_type.default_carbon_intensity_category.name, effective_date=period.effective_date, model_name="DefaultCarbonIntensity" ) return obj.density return None
def get_limits(self, obj): """ Gets the Carbon Intensity Limits for the compliance period """ diesel_limit = CreditCalculationService.get( compliance_period_id=obj.id, effective_date=date.today(), fuel_class__fuel_class="Diesel", model_name="CarbonIntensityLimit") gasoline_limit = CreditCalculationService.get( compliance_period_id=obj.id, effective_date=date.today(), fuel_class__fuel_class="Gasoline", model_name="CarbonIntensityLimit") return { "diesel": { "fuel": "Diesel Class", "density": diesel_limit.density, "effective_date": diesel_limit.effective_date, "expiration_date": diesel_limit.expiration_date } if diesel_limit else None, "gasoline": { "fuel": "Gasoline Class", "density": gasoline_limit.density, "effective_date": gasoline_limit.effective_date, "expiration_date": gasoline_limit.expiration_date } if gasoline_limit else None }
def get_default_carbon_intensity(self, obj): """ Gets the Default Carbon Intensity """ if obj.credit_calculation_only: row = CreditCalculationService.get( category__name=obj.name, effective_date=self.effective_date, model_name="PetroleumCarbonIntensity") else: row = CreditCalculationService.get( category_id=obj.default_carbon_intensity_category_id, effective_date=self.effective_date, model_name="DefaultCarbonIntensity") return row.density if row else None
def eer(self): period = self.schedule.compliance_report.compliance_period obj = CreditCalculationService.get( category_id=self.fuel_type.energy_effectiveness_ratio_category_id, effective_date=period.effective_date, fuel_class__fuel_class=self.fuel_class.fuel_class, model_name="EnergyEffectivenessRatio" ) return obj.ratio
def energy_density(self): period = self.schedule.compliance_report.compliance_period obj = CreditCalculationService.get( category_id=self.fuel_type.energy_density_category_id, effective_date=period.effective_date, model_name="EnergyDensity" ) return obj.density
def ci_limit(self): period = self.schedule.compliance_report.compliance_period obj = CreditCalculationService.get( compliance_period=period, effective_date=period.effective_date, fuel_class__fuel_class=self.fuel_class.fuel_class, model_name="CarbonIntensityLimit" ) return obj.density
def get_density(self, obj): """ Gets the Energy Density """ density = CreditCalculationService.get(model_name="EnergyDensity", category_id=obj.id, effective_date=date.today()) return density.density if density else None
def get_density(self, obj): """ Gets the Carbon Intensity """ row = CreditCalculationService.get(model_name="DefaultCarbonIntensity", category_id=obj.id, effective_date=date.today()) return row.density if row else None
def get_energy_density(self, obj): """ Gets the Energy Density """ row = CreditCalculationService.get( category_id=obj.energy_density_category_id, effective_date=self.effective_date, model_name="EnergyDensity") return row.density if row else None
def get_carbon_intensity_limit(self, _obj): """ Gets the Carbon Intensity Limit """ diesel_row = CreditCalculationService.get( compliance_period_id=self.compliance_period_id, effective_date=self.effective_date, fuel_class__fuel_class="Diesel", model_name="CarbonIntensityLimit") gasoline_row = CreditCalculationService.get( compliance_period_id=self.compliance_period_id, effective_date=self.effective_date, fuel_class__fuel_class="Gasoline", model_name="CarbonIntensityLimit") return { "diesel": diesel_row.density if diesel_row else None, "gasoline": gasoline_row.density if gasoline_row else None }
def get_energy_effectiveness_ratio(self, obj): """ Gets the Energy Effectiveness Ratio """ diesel_row = CreditCalculationService.get( category_id=obj.energy_effectiveness_ratio_category_id, effective_date=self.effective_date, fuel_class__fuel_class="Diesel", model_name="EnergyEffectivenessRatio") gasoline_row = CreditCalculationService.get( category_id=obj.energy_effectiveness_ratio_category_id, effective_date=self.effective_date, fuel_class__fuel_class="Gasoline", model_name="EnergyEffectivenessRatio") return { "diesel": diesel_row.ratio if diesel_row else None, "gasoline": gasoline_row.ratio if gasoline_row else None }
def get_gasoline_ratio(self, obj): """ Gets the Energy Effectiveness Ratio for Gasoline Class """ gasoline_ratio = CreditCalculationService.get( model_name="EnergyEffectivenessRatio", category_id=obj.id, effective_date=date.today(), fuel_class__fuel_class="Gasoline" ) return gasoline_ratio.ratio if gasoline_ratio else None
def get_diesel_ratio(self, obj): """ Gets the Energy Effectiveness Ratio for Diesel Class """ diesel_ratio = CreditCalculationService.get( model_name="EnergyEffectivenessRatio", category_id=obj.id, effective_date=date.today(), fuel_class__fuel_class="Diesel" ) return diesel_ratio.ratio if diesel_ratio else None
def get_ratios(self, obj): """ Gets the Energy Effectiveness Ratio for Diesel and Gasoline Class """ diesel_ratio = CreditCalculationService.get( category_id=obj.id, effective_date=date.today(), fuel_class__fuel_class="Diesel", model_name="EnergyEffectivenessRatio" ) gasoline_ratio = CreditCalculationService.get( category_id=obj.id, effective_date=date.today(), fuel_class__fuel_class="Gasoline", model_name="EnergyEffectivenessRatio" ) return { "diesel": { "fuel": "Diesel Class", "ratio": diesel_ratio.ratio if diesel_ratio else None, "effective_date": diesel_ratio.effective_date if diesel_ratio else None, "expiration_date": diesel_ratio.expiration_date if diesel_ratio else None }, "gasoline": { "fuel": "Gasoline Class", "ratio": gasoline_ratio.ratio if gasoline_ratio else None, "effective_date": gasoline_ratio.effective_date if gasoline_ratio else None, "expiration_date": gasoline_ratio.expiration_date if gasoline_ratio else None } }
def get_density(self, obj): """ Gets the Energy Density """ row = CreditCalculationService.get(model_name="EnergyDensity", category_id=obj.id, effective_date=date.today()) if not row: return None return { "density": row.density, "effective_date": row.effective_date, "expiration_date": row.expiration_date }