def standard_deviation(cls, month): stats = cls.objects.filter(month_id=month) total = stats.values_list("rating", flat=True) N = stats.count() mean = cls.mean(month) sum_diff = sum([(mean-float(each))**2 for each in total]) sd = cmath.sqrt(sum_diff / N-1) return sd.imag * 100
def mean(cls, month): stats = cls.objects.filter(month_id=month) total = sum(stats.values_list("rating", flat=True)) N = stats.count() return total / N