def calculate_points_group(self, result): """ Function used to recalculate group points """ if result.number.distance_id == self.BERNU_DISTANCE_ID: return result.points_group # For children lets return the same number. if result.status: return 0 try: top_result = Result.objects.filter(competition=result.competition, number__distance=result.number.distance, participant__group=result.participant.group).order_by('time')[0] except IndexError: return 1000 return math.trunc((float(math.trunc(time_to_seconds(top_result.time))) / float(math.trunc(time_to_seconds(result.time)))) * 1000)
def calculate_points_distance(self, result): """ Function used to calculate distance points """ if result.number.distance_id == self.BERNU_DISTANCE_ID: return result.points_distance # For children lets return the same number. if result.status: # If result has the status then that means that result is 0 return 0 try: top_result = Result.objects.filter(competition=result.competition, number__distance=result.number.distance).order_by('time')[0] except IndexError: return 1000 return math.trunc((float(math.trunc(time_to_seconds(top_result.time))) / float(math.trunc(time_to_seconds(result.time)))) * 1000)
def get_total_seconds(self): return sum((time_to_seconds(obj.time) for obj in self.results))
def set_distance_total_seconds(self): self.distance_total_seconds = sum((time_to_seconds(obj.time) for obj in self.results))