Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. def get_score(self, period):
  2.         ''' Get the score for this goal '''
  3.  
  4.         # Agregar filtro para este goal
  5.         executions = Execution.objects.filter(period=period)
  6.         value = 0
  7.  
  8.         # Simple values
  9.         value += executions.filter(
  10.             indicator__in=self.indicator_set.filter(accumulated_value=False)
  11.         ).aggregate(total=Coalesce(Sum('result'), 0))['total']
  12.  
  13.         # Accumulated values
  14.         value += executions.filter(
  15.             indicator__in=self.indicator_set.filter(
  16.                 accumulated_value=True,
  17.                 accumulated_graphic=True
  18.             )
  19.         ).aggregate(total=Coalesce(Sum('result_accumulated'), 0))['total']
  20.  
  21.         # Idicators that have been set as accumulated, but we need
  22.         # retrieve the simple value.
  23.         value += executions.filter(
  24.             indicator__in=self.indicator_set.filter(
  25.                 accumulated_value=True,
  26.                 accumulated_graphic=False
  27.             )
  28.         ).aggregate(total=Coalesce(Sum('result'), 0))['total']
  29.         return value
  30.  
  31. def get_weight_value(self, goal, accumulated=False):
  32.         ''' Get weight value, to be used in goals '''
  33.         try:
  34.             weight = GoalIndicator.objects.get(goal=goal, indicator=self.indicator)
  35.         except:
  36.             pass
  37.  
  38.         value = self.result_accumulated if accumulated else self.result
  39.         return (value / weight) * 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement