def monthly(self, filters=None, group=None, start_date='all', end_date=None): dt_filtered_cube = self.filter_cube(filters) dt_filtered_cube = self.filter_by_dates(start_date, end_date, dt_filtered_cube) res = OrderedDict() i = 0 start_dt = dt_filtered_cube.aggregate(Min('date'))['date__min'] end_dt = dt_filtered_cube.exclude(date__gt=end_date).aggregate( Max('date'))['date__max'] end_increment = month_end(start_dt) while end_increment <= end_dt: resd = dict() structure = self.total(filters, group, start_dt.strftime(self.DTFORMAT), end_increment.strftime(self.DTFORMAT)) # trace.info('---MONTHLY TOTAL: {}\n\n'.format(structure)) if structure: if 'churn' in structure: resd['churn'] = structure['churn'] if 'churn_pct' in structure: resd['churn_pct'] = structure['churn_pct'] if 'average' in structure: resd['average'] = structure['average'] if 'new' in structure: resd['new'] = structure['new'] if 'total' in structure: resd['total'] = structure['total'] if len(resd) == 0: resd = structure resd['name'] = start_dt.strftime("%b") resd['start'] = str(start_dt) resd['end'] = str(end_increment) res[i] = resd i += 1 start_dt = end_increment + datetime.timedelta(days=1) end_increment = month_end(start_dt) trace.info('\n----MONTHLY SUMMARY: \n{}\n'.format(res)) return res
def monthly(self, filters=None, group=None, start_date='all', end_date=None): dt_filtered_cube = self.filter_cube(filters) dt_filtered_cube = self.filter_by_dates(start_date, end_date, dt_filtered_cube) res = OrderedDict() i = 0 start_dt = dt_filtered_cube.aggregate(Min('date'))['date__min'] end_dt = dt_filtered_cube.exclude(date__gt=end_date).aggregate(Max('date'))['date__max'] end_increment = month_end(start_dt) while end_increment <= end_dt: structure = self.total( filters, group, start_dt.strftime(self.DTFORMAT), end_increment.strftime(self.DTFORMAT)) if structure: structure['name'] = start_dt.strftime("%b") structure['start'] = str(start_dt) structure['end'] = str(end_increment) res[i] = structure i += 1 start_dt = end_increment+datetime.timedelta(days=1) end_increment = month_end(start_dt) return res
def monthly(self, filters=None, group=None, start_date='all', end_date=None): dt_filtered_cube = self.filter_cube(filters) dt_filtered_cube = self.filter_by_dates(start_date, end_date, dt_filtered_cube) res = OrderedDict() i = 0 start_dt = dt_filtered_cube.aggregate(Min('date'))['date__min'] end_dt = dt_filtered_cube.exclude(date__gt=end_date).aggregate(Max('date'))['date__max'] end_increment = month_end(start_dt) while end_increment <= end_dt: resd = dict() structure = self.total( filters, group, start_dt.strftime(self.DTFORMAT), end_increment.strftime(self.DTFORMAT)) # trace.info('---MONTHLY TOTAL: {}\n\n'.format(structure)) if structure: if 'churn' in structure: resd['churn'] = structure['churn'] if 'churn_pct' in structure: resd['churn_pct'] = structure['churn_pct'] if 'average' in structure: resd['average'] = structure['average'] if 'new' in structure: resd['new'] = structure['new'] if 'total' in structure: resd['total'] = structure['total'] if len(resd) == 0: resd = structure resd['name'] = start_dt.strftime("%b") resd['start'] = str(start_dt) resd['end'] = str(end_increment) res[i] = resd i += 1 start_dt = end_increment+datetime.timedelta(days=1) end_increment = month_end(start_dt) trace.info('\n----MONTHLY SUMMARY: \n{}\n'.format(res)) return res