Esempio n. 1
0
    def get_week_report(self):

        report_data = []
        week_list = []
        for i in xrange(WEEK_START_NO, 54):
            x = get_week_days(YEAR_START_NO, i)
            if date.today() > x[0]:
                week_list.append(x)

        for week in week_list:
            index = week_list.index(week)
            if index > 0:
                current_week_first = week[0]
                current_week_last = week[1]
                previous_week_first = week_list[index - 1][0]
                previous_week_last = week_list[index - 1][1]

                current_ret = self.report_table_obj.objects.filter(
                    report_date__gte=current_week_first,
                    report_date__lte=current_week_last)

                previous_ret = self.report_table_obj.objects.filter(
                    report_date__gte=previous_week_first,
                    report_date__lte=previous_week_last)
                fields = self.get_report_settings()['schema'].keys()
                if self.report_name == 'user_daily_report':
                    fields.append('new_member_count')

                current_data, previous_data = get_final_data(
                    current_ret, previous_ret, fields, self.report_name)

                result_doc = {}
                for key, data in current_data.items():

                    result_doc[key] = data
                    result_doc['%s_contrast' % (key)] = get_contrast(
                        data, previous_data[key])

                result_doc['report_date'] = '{0}-{1}'.format(
                    current_week_first.strftime('%Y年-%m月-%d日'),
                    current_week_last.strftime('%Y年-%m月-%d日'))
                report_data.append(result_doc)

        return report_data[::-1]
Esempio n. 2
0
    def get_week_report(self):

        report_data = []
        week_list = []
        for i in xrange(WEEK_START_NO, 54):
            x = get_week_days(YEAR_START_NO, i)
            if date.today() > x[0]:
                week_list.append(x)

        for week in week_list:
            index = week_list.index(week)
            if  index > 0:
                current_week_first = week[0]
                current_week_last = week[1]
                previous_week_first = week_list[index-1][0]
                previous_week_last = week_list[index-1][1]

                current_ret = self.report_table_obj.objects.filter(
                    report_date__gte=current_week_first,
                    report_date__lte=current_week_last
                )

                previous_ret = self.report_table_obj.objects.filter(
                    report_date__gte=previous_week_first,
                    report_date__lte=previous_week_last
                )
                fields = self.get_report_settings()['schema'].keys()
                if self.report_name == 'user_daily_report':
                    fields.append('new_member_count')

                current_data, previous_data = get_final_data(current_ret, previous_ret, fields, self.report_name)

                result_doc = {}
                for key, data in current_data.items():

                    result_doc[key] = data
                    result_doc['%s_contrast' % (key)] = get_contrast(data, previous_data[key])

                result_doc['report_date'] = '{0}-{1}'.format(current_week_first.strftime('%Y年-%m月-%d日'),
                                                             current_week_last.strftime('%Y年-%m月-%d日')
                                                             )
                report_data.append(result_doc)

        return report_data[::-1]
Esempio n. 3
0
    def get_month_report(self):

        report_data = []
        month_list = get_month_day_range(YEAR_START_NO, MONTH_START_NO)
        for month in month_list:
            index = month_list.index(month)
            if index > 0:
                current_month_first = month[0]
                current_month_last = month[1]
                previous_month_first = month_list[index - 1][0]
                previous_month_last = month_list[index - 1][1]

                current_ret = self.report_table_obj.objects.filter(
                    report_date__gte=current_month_first,
                    report_date__lte=current_month_last)

                previous_ret = self.report_table_obj.objects.filter(
                    report_date__gte=previous_month_first,
                    report_date__lte=previous_month_last)

                fields = self.get_report_settings()['schema'].keys()
                if self.report_name == 'user_daily_report':
                    fields.append('new_member_count')
                current_data, previous_data = get_final_data(
                    current_ret, previous_ret, fields, self.report_name)

                result_doc = {}

                for key, data in current_data.items():
                    if data is None:
                        data = 1

                    result_doc[key] = data
                    result_doc['%s_contrast' % (key)] = get_contrast(
                        data, previous_data[key])

                result_doc['report_date'] = '{0}-{1}'.format(
                    current_month_first.strftime('%Y年-%m月-%d日'),
                    current_month_last.strftime('%Y年-%m月-%d日'))
                report_data.append(result_doc)
        return report_data[::-1]
Esempio n. 4
0
    def get_month_report(self):

        report_data = []
        month_list = get_month_day_range(YEAR_START_NO, MONTH_START_NO)
        for month in month_list:
            index = month_list.index(month)
            if  index > 0:
                current_month_first = month[0]
                current_month_last = month[1]
                previous_month_first = month_list[index-1][0]
                previous_month_last = month_list[index-1][1]

                current_ret = self.report_table_obj.objects.filter(
                    report_date__gte=current_month_first,
                    report_date__lte=current_month_last
                )

                previous_ret = self.report_table_obj.objects.filter(
                    report_date__gte=previous_month_first,
                    report_date__lte=previous_month_last
                )

                fields = self.get_report_settings()['schema'].keys()
                if self.report_name == 'user_daily_report':
                    fields.append('new_member_count')
                current_data, previous_data = get_final_data(current_ret, previous_ret, fields, self.report_name)

                result_doc = {}

                for key, data in current_data.items():
                    if data is None:
                        data = 1

                    result_doc[key] = data
                    result_doc['%s_contrast' % (key)] = get_contrast(data, previous_data[key])

                result_doc['report_date'] = '{0}-{1}'.format(current_month_first.strftime('%Y年-%m月-%d日'),
                                                             current_month_last.strftime('%Y年-%m月-%d日')
                                                             )
                report_data.append(result_doc)
        return report_data[::-1]