Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.47 KB | None | 0 0
  1. 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
  2.  
  3. In assessments/models.py
  4.  
  5. def market_based(self):
  6.         return self.question.market_based and self.uses_mbi
  7.  
  8. to
  9.  
  10. def market_based(self):
  11.         return self.question.market_based
  12.  
  13. 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
  14.  
  15. The market based Logic is completely wrong it should be
  16.  
  17. @memoize_property
  18.     def calculate_market_based_emissions(self):
  19.         """
  20.        Calculate the specific market based emissions for this answer.
  21.  
  22.        Uses the regular emissions and supplants in the custom factors
  23.        entered for the answer.
  24.        """
  25.         if not self.market_based:
  26.             return []
  27.    
  28.         gwp_group_id = getattr(self, 'gwp_group', None)
  29.         if gwp_group_id is None:
  30.             gwp_group_id = self.company_unit.company.gwp_group_id
  31.  
  32.         if self.market_based_instrument:
  33.             # Use the mbi's factors
  34.             custom_factors = self.market_based_instrument.get_factors()
  35.         else:
  36.             # Use the activitie's residual factors
  37.             custom_factors = get_potentials(
  38.                 self.activity.residual_factors.all()
  39.                     .select_related('gas', 'unit'),
  40.                 location_hierarchy=self.location.get_location_hierarchy(),
  41.                 daterange=self.duration
  42.             )
  43.  
  44.         if not custom_factors:
  45.             # Cannot find residual factors matching the answer, so return
  46.             # a copy of location based emissions, so we can set the
  47.             # is_market_based flag on
  48.             emissions = [
  49.                 Emission(
  50.                     e.gas, e.amount, gwp=e.gwp, path=e.path, answer=self,
  51.                     aggregate=e.aggregate, multiple_paths=e.multiple_paths
  52.                 ) for e in self.emissions
  53.             ]
  54.         else:
  55.             emissions = emissions_from_graph_with_override_factors(
  56.                 activity=self.activity,
  57.                 location=self.location,
  58.                 daterange=self.duration,
  59.                 value=self.value,
  60.                 unit=self.unit,
  61.                 gwp_group=gwp_group_id,
  62.                 factors=custom_factors,
  63.                 answer=self
  64.             )
  65.  
  66.         for em in emissions:
  67.             em.is_market_based = True
  68.  
  69.         return emissions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement