Exemple #1
0
    def get_breakdown(self, days=14):
        now = datetime.now(tz=self.user.settings.time_zone).date()
        subset = self.by_date(now - timedelta(days=days), now)

        total = subset.count()
        lowest = subset.aggregate(Min('value'))['value__min']
        highest = subset.aggregate(Max('value'))['value__max']
        average = core_utils.round_value(
            subset.aggregate(Avg('value'))['value__avg'])
        
        highs = subset.filter(value__gt=self.user_settings['high']).count()
        lows = subset.filter(value__lt=self.user_settings['low']).count()
        within_target = subset.filter(
            value__gte=self.user_settings['target_min'],
            value__lte=self.user_settings['target_max']
        ).count()
        other = total - (highs + lows + within_target)

        return {
            'total': total,
            'lowest': {
                'value': '%s %s' % (self.glucose_by_unit_setting(lowest),
                                    self.glucose_unit_name) \
                    if lowest else 'None',
                'css_class': self.get_css_class(lowest),
            },
            'highest': {
                'value': '%s %s' % (self.glucose_by_unit_setting(highest),
                                    self.glucose_unit_name) \
                    if highest else 'None',
                'css_class': self.get_css_class(highest),
            },  
            'average': {
                'value': '%s %s' % (self.glucose_by_unit_setting(average),
                                    self.glucose_unit_name) \
                    if average else 'None',
                'css_class': self.get_css_class(average)
            },
            'highs': '%s (%s%%)' % (highs, core_utils.percent(highs, total)),
            'lows': '%s (%s%%)' % (lows, core_utils.percent(lows, total)),
            'within_target': '%s (%s%%)' % (
                within_target, core_utils.percent(within_target, total)),
            'other': '%s (%s%%)' % (other, core_utils.percent(other, total)),

        }
Exemple #2
0
    def get_breakdown(self, days=14):
        now = datetime.now(tz=self.user.settings.time_zone).date()
        subset = self.by_date(now - timedelta(days=days), now)

        total = subset.count()
        lowest = subset.aggregate(Min('value'))['value__min']
        highest = subset.aggregate(Max('value'))['value__max']
        average = core_utils.round_value(
            subset.aggregate(Avg('value'))['value__avg'])
        
        highs = subset.filter(value__gt=self.user_settings['high']).count()
        lows = subset.filter(value__lt=self.user_settings['low']).count()
        within_target = subset.filter(
            value__gte=self.user_settings['target_min'],
            value__lte=self.user_settings['target_max']
        ).count()
        other = total - (highs + lows + within_target)

        return {
            'total': total,
            'lowest': {
                'value': '%s %s' % (self.glucose_by_unit_setting(lowest),
                                    self.glucose_unit_name) \
                    if lowest else 'None',
                'css_class': self.get_css_class(lowest),
            },
            'highest': {
                'value': '%s %s' % (self.glucose_by_unit_setting(highest),
                                    self.glucose_unit_name) \
                    if highest else 'None',
                'css_class': self.get_css_class(highest),
            },  
            'average': {
                'value': '%s %s' % (self.glucose_by_unit_setting(average),
                                    self.glucose_unit_name) \
                    if average else 'None',
                'css_class': self.get_css_class(average)
            },
            'highs': '%s (%s%%)' % (highs, core_utils.percent(highs, total)),
            'lows': '%s (%s%%)' % (lows, core_utils.percent(lows, total)),
            'within_target': '%s (%s%%)' % (
                within_target, core_utils.percent(within_target, total)),
            'other': '%s (%s%%)' % (other, core_utils.percent(other, total)),

        }