Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Based on doing a code review and talking to Jordi I think we need to make the following changes to the code to make market based work as intended
- In assessments/models.py
- def market_based(self):
- return self.question.market_based and self.uses_mbi
- to
- def market_based(self):
- return self.question.market_based
- We have seperate method called uses_mbi and its what it should be used for market_based is based solely on wether the parent question is market based
- The market based Logic is completely wrong it should be
- @memoize_property
- def calculate_market_based_emissions(self):
- """
- Calculate the specific market based emissions for this answer.
- Uses the regular emissions and supplants in the custom factors
- entered for the answer.
- """
- if not self.market_based:
- return []
- gwp_group_id = getattr(self, 'gwp_group', None)
- if gwp_group_id is None:
- gwp_group_id = self.company_unit.company.gwp_group_id
- if self.market_based_instrument:
- # Use the mbi's factors
- custom_factors = self.market_based_instrument.get_factors()
- else:
- # Use the activitie's residual factors
- custom_factors = get_potentials(
- self.activity.residual_factors.all()
- .select_related('gas', 'unit'),
- location_hierarchy=self.location.get_location_hierarchy(),
- daterange=self.duration
- )
- if not custom_factors:
- # Cannot find residual factors matching the answer, so return
- # a copy of location based emissions, so we can set the
- # is_market_based flag on
- emissions = [
- Emission(
- e.gas, e.amount, gwp=e.gwp, path=e.path, answer=self,
- aggregate=e.aggregate, multiple_paths=e.multiple_paths
- ) for e in self.emissions
- ]
- else:
- emissions = emissions_from_graph_with_override_factors(
- activity=self.activity,
- location=self.location,
- daterange=self.duration,
- value=self.value,
- unit=self.unit,
- gwp_group=gwp_group_id,
- factors=custom_factors,
- answer=self
- )
- for em in emissions:
- em.is_market_based = True
- return emissions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement