Esempio n. 1
0
    def get_context_data(self, **kwargs):
        context = super(RetailerDashboard, self).get_context_data(**kwargs)
        providers = list(
            OperatorProfile.objects.filter(
                business_type=OperatorProfile.PROVIDER))
        for provider in providers:
            set_counters(provider)
        providers_report = {
            'today': rank_watch_objects(providers, 'earnings_history'),
            'yesterday': rank_watch_objects(providers, 'earnings_history', 1),
            'last_week': rank_watch_objects(providers, 'earnings_history', 7),
            'last_28_days': rank_watch_objects(providers, 'earnings_history',
                                               28)
        }

        customers_today = slice_watch_objects(Customer)
        customers_yesterday = slice_watch_objects(Customer, 1)
        customers_last_week = slice_watch_objects(Customer, 7)
        customers_last_28_days = slice_watch_objects(Customer, 28)
        customers_report = {
            'today':
            rank_watch_objects(customers_today, 'earnings_history'),
            'yesterday':
            rank_watch_objects(customers_yesterday, 'earnings_history', 1),
            'last_week':
            rank_watch_objects(customers_last_week, 'earnings_history', 7),
            'last_28_days':
            rank_watch_objects(customers_last_28_days, 'earnings_history', 28)
        }
        context['providers_report'] = providers_report
        context['customers_report'] = customers_report
        return context
Esempio n. 2
0
 def get_context_data(self, **kwargs):
     context = super(Dashboard, self).get_context_data(**kwargs)
     service = get_service_instance()
     set_counters(service)
     customers = list(Service.objects.all())
     for customer in customers:
         set_counters(customer)
     customers_report = {
         'today': rank_watch_objects(customers, 'earnings_history'),
         'yesterday': rank_watch_objects(customers, 'earnings_history', 1),
         'last_week': rank_watch_objects(customers, 'earnings_history', 7),
         'last_28_days': rank_watch_objects(customers, 'earnings_history', 28)
     }
     apps = list(Application.objects.all())
     for app in apps:
         set_counters(app)
     apps_report = {
         'today': rank_watch_objects(apps, 'earnings_history'),
         'yesterday': rank_watch_objects(apps, 'earnings_history', 1),
         'last_week': rank_watch_objects(apps, 'earnings_history', 7),
         'last_28_days': rank_watch_objects(apps, 'earnings_history', 28)
     }
     context['customers_report'] = customers_report
     context['apps_report'] = apps_report
     return context
Esempio n. 3
0
 def get_context_data(self, **kwargs):
     context = super(Dashboard, self).get_context_data(**kwargs)
     service = self.get_service(**kwargs)
     db = service.database
     add_database(db)
     customer_list = slice_watch_objects(Customer, 28, using=db)
     customers_report = {
         'today':
         rank_watch_objects(customer_list, 'turnover_history'),
         'yesterday':
         rank_watch_objects(customer_list, 'turnover_history', 1),
         'last_week':
         rank_watch_objects(customer_list, 'turnover_history', 7),
         'last_28_days':
         rank_watch_objects(customer_list, 'turnover_history', 28)
     }
     context['customers_report'] = customers_report
     company_list = list(Service.objects.using(db).all())
     for company in company_list:
         set_counters(company)
     companies_report = {
         'today':
         rank_watch_objects(company_list, 'earnings_history'),
         'yesterday':
         rank_watch_objects(company_list, 'earnings_history', 1),
         'last_week':
         rank_watch_objects(company_list, 'earnings_history', 7),
         'last_28_days':
         rank_watch_objects(company_list, 'earnings_history', 28)
     }
     context['companies_report'] = companies_report
     return context
Esempio n. 4
0
    def test_calculate_rank_watch_objects(self):
        wo1 = WatchObject()
        wo1.val2_history = list(range(57))
        wo2 = WatchObject()
        wo2.val2_history = list(range(56, -1, -1))
        wo3 = WatchObject()
        wo3.val2_history = list(range(0, 110, 2))

        l = [wo1, wo2, wo3]
        ranked_watch_objects0 = rank_watch_objects(l, 'val2_history')
        ranked_watch_objects1 = rank_watch_objects(l, 'val2_history', 1)
        ranked_watch_objects7 = rank_watch_objects(l, 'val2_history', 7)
        ranked_watch_objects28 = rank_watch_objects(l, 'val2_history', 28)

        self.assertListEqual([wo3, wo1, wo2], ranked_watch_objects0)
        self.assertListEqual([wo3, wo1, wo2], ranked_watch_objects1)
        self.assertListEqual([wo3, wo1, wo2], ranked_watch_objects7)
        self.assertListEqual([wo3, wo1, wo2], ranked_watch_objects28)
Esempio n. 5
0
 def get_context_data(self, **kwargs):
     context = super(ProviderDashboard, self).get_context_data(**kwargs)
     customers_today = slice_watch_objects(Customer)
     customers_yesterday = slice_watch_objects(Customer, 1)
     customers_last_week = slice_watch_objects(Customer, 7)
     customers_last_28_days = slice_watch_objects(Customer, 28)
     customers_report = {
         'today':
         rank_watch_objects(customers_today, 'turnover_history'),
         'yesterday':
         rank_watch_objects(customers_yesterday, 'turnover_history', 1),
         'last_week':
         rank_watch_objects(customers_last_week, 'turnover_history', 7),
         'last_28_days':
         rank_watch_objects(customers_last_28_days, 'turnover_history', 28)
     }
     context['customers_report'] = customers_report
     try:
         if getattr(settings, 'DEBUG', False):
             _umbrella_db = 'ikwen_umbrella'
         else:
             _umbrella_db = 'ikwen_umbrella_prod'  # Force the umbrella Alias to point the real umbrella DB
         add_database_to_settings(_umbrella_db)
         service = get_service_instance()
         DarajaConfig.objects.using(_umbrella_db).get(
             service=service, referrer_share_rate__gt=0)
         daras_list = slice_watch_objects(Dara,
                                          28,
                                          time_field='last_transaction_on')
         daras_report = {
             'today':
             rank_watch_objects(daras_list, 'turnover_history'),
             'yesterday':
             rank_watch_objects(daras_list, 'turnover_history', 1),
             'last_week':
             rank_watch_objects(daras_list, 'turnover_history', 7),
             'last_28_days':
             rank_watch_objects(daras_list, 'turnover_history', 28)
         }
         context['daras_report'] = daras_report
     except:
         pass
     return context
Esempio n. 6
0
    def get_context_data(self, **kwargs):
        context = super(Dashboard, self).get_context_data(**kwargs)
        service = get_service_instance()
        set_counters(service)
        earnings_today = context['earnings_report']['today']
        earnings_yesterday = context['earnings_report']['yesterday']
        earnings_last_week = context['earnings_report']['last_week']
        earnings_last_28_days = context['earnings_report']['last_28_days']

        transaction_count = calculate_watch_info(service.transaction_count_history)
        transaction_count_yesterday = calculate_watch_info(service.transaction_count_history, 1)
        transaction_count_last_week = calculate_watch_info(service.transaction_count_history, 7)
        transaction_count_last_28_days = calculate_watch_info(service.transaction_count_history, 28)

        # AEPT stands for Average Earning Per Transaction
        aept_today = earnings_today['total'] / transaction_count['total'] if transaction_count['total'] else 0
        aept_yesterday = earnings_yesterday['total'] / transaction_count_yesterday['total']\
            if transaction_count_yesterday and transaction_count_yesterday['total'] else 0
        aept_last_week = earnings_last_week['total'] / transaction_count_last_week['total']\
            if transaction_count_last_week and transaction_count_last_week['total'] else 0
        aept_last_28_days = earnings_last_28_days['total'] / transaction_count_last_28_days['total']\
            if transaction_count_last_28_days and transaction_count_last_28_days['total'] else 0

        transactions_report = {
            'today': {
                'count': transaction_count['total'] if transaction_count else 0,
                'aept': '%.2f' % aept_today,  # AEPT: Avg Earning Per Transaction
            },
            'yesterday': {
                'count': transaction_count_yesterday['total'] if transaction_count_yesterday else 0,
                'aept': '%.2f' % aept_yesterday,
            },
            'last_week': {
                'count': transaction_count_last_week['total'] if transaction_count_last_week else 0,
                'aept': '%.2f' % aept_last_week,
            },
            'last_28_days': {
                'count': transaction_count_last_28_days['total']if transaction_count_last_28_days else 0,
                'aept': '%.2f' % aept_last_28_days,
            }
        }
        customers = list(Service.objects.all())
        for customer in customers:
            set_counters(customer)
        customers_report = {
            'today': rank_watch_objects(customers, 'earnings_history'),
            'yesterday': rank_watch_objects(customers, 'earnings_history', 1),
            'last_week': rank_watch_objects(customers, 'earnings_history', 7),
            'last_28_days': rank_watch_objects(customers, 'earnings_history', 28)
        }
        apps = list(Application.objects.all())
        for app in apps:
            set_counters(app)
        apps_report = {
            'today': rank_watch_objects(apps, 'earnings_history'),
            'yesterday': rank_watch_objects(apps, 'earnings_history', 1),
            'last_week': rank_watch_objects(apps, 'earnings_history', 7),
            'last_28_days': rank_watch_objects(apps, 'earnings_history', 28)
        }

        context['transactions_report'] = transactions_report
        context['customers_report'] = customers_report
        context['apps_report'] = apps_report
        return context
Esempio n. 7
0
    def get_context_data(self, **kwargs):
        context = super(Dashboard, self).get_context_data(**kwargs)
        earnings_today = context['earnings_report']['today']
        earnings_yesterday = context['earnings_report']['yesterday']
        earnings_last_week = context['earnings_report']['last_week']
        earnings_last_28_days = context['earnings_report']['last_28_days']

        service = get_service_instance()
        set_counters(service)
        orders_count_today = calculate_watch_info(
            service.transaction_count_history)
        orders_count_yesterday = calculate_watch_info(
            service.transaction_count_history, 1)
        orders_count_last_week = calculate_watch_info(
            service.transaction_count_history, 7)
        orders_count_last_28_days = calculate_watch_info(
            service.transaction_count_history, 28)

        # AEPO stands for Average Earning Per Order
        aepo_today = earnings_today['total'] / orders_count_today[
            'total'] if orders_count_today['total'] else 0
        aepo_yesterday = earnings_yesterday['total'] / orders_count_yesterday['total']\
            if orders_count_yesterday and orders_count_yesterday['total'] else 0
        aepo_last_week = earnings_last_week['total'] / orders_count_last_week['total']\
            if orders_count_last_week and orders_count_last_week['total'] else 0
        aepo_last_28_days = earnings_last_28_days['total'] / orders_count_last_28_days['total']\
            if orders_count_last_28_days and orders_count_last_28_days['total'] else 0

        orders_report = {
            'today': {
                'count':
                orders_count_today['total'] if orders_count_today else 0,
                'aepo': '%.2f' % aepo_today,  # AEPO: Avg Earning Per Order
            },
            'yesterday': {
                'count':
                orders_count_yesterday['total']
                if orders_count_yesterday else 0,
                'aepo':
                '%.2f' % aepo_yesterday,  # AEPO: Avg Earning Per Order
            },
            'last_week': {
                'count':
                orders_count_last_week['total']
                if orders_count_last_week else 0,
                'aepo':
                '%.2f' % aepo_last_week,  # AEPO: Avg Earning Per Order
            },
            'last_28_days': {
                'count':
                orders_count_last_28_days['total']
                if orders_count_last_28_days else 0,
                'aepo':
                '%.2f' % aepo_last_28_days,  # AEPO: Avg Earning Per Order
            }
        }
        customers_today = slice_watch_objects(Customer)
        customers_yesterday = slice_watch_objects(Customer, 1)
        customers_last_week = slice_watch_objects(Customer, 7)
        customers_last_28_days = slice_watch_objects(Customer, 28)
        customers_report = {
            'today':
            rank_watch_objects(customers_today, 'turnover_history'),
            'yesterday':
            rank_watch_objects(customers_yesterday, 'turnover_history', 1),
            'last_week':
            rank_watch_objects(customers_last_week, 'turnover_history', 7),
            'last_28_days':
            rank_watch_objects(customers_last_28_days, 'turnover_history', 28)
        }
        context['orders_report'] = orders_report
        context['customers_report'] = customers_report
        return context
Esempio n. 8
0
    def get_context_data(self, **kwargs):
        context = super(LogicomDashboard, self).get_context_data(**kwargs)
        operator_profile = get_service_instance().config
        set_counters(operator_profile)
        earnings_today = context['earnings_report']['today']
        earnings_yesterday = context['earnings_report']['yesterday']
        earnings_last_week = context['earnings_report']['last_week']
        earnings_last_28_days = context['earnings_report']['last_28_days']

        orders_count_today = calculate_watch_info(
            operator_profile.orders_count_history)
        orders_count_yesterday = calculate_watch_info(
            operator_profile.orders_count_history, 1)
        orders_count_last_week = calculate_watch_info(
            operator_profile.orders_count_history, 7)
        orders_count_last_28_days = calculate_watch_info(
            operator_profile.orders_count_history, 28)

        # AEPO stands for Average Earning Per Order
        aepo_today = earnings_today['total'] / orders_count_today[
            'total'] if orders_count_today['total'] else 0
        aepo_yesterday = earnings_yesterday['total'] / orders_count_yesterday['total']\
            if orders_count_yesterday and orders_count_yesterday['total'] else 0
        aepo_last_week = earnings_last_week['total'] / orders_count_last_week['total']\
            if orders_count_last_week and orders_count_last_week['total'] else 0
        aepo_last_28_days = earnings_last_28_days['total'] / orders_count_last_28_days['total']\
            if orders_count_last_28_days and orders_count_last_28_days['total'] else 0

        orders_report = {
            'today': {
                'count':
                orders_count_today['total'] if orders_count_today else 0,
                'aepo': '%.2f' % aepo_today,  # AEPO: Avg Earning Per Order
            },
            'yesterday': {
                'count':
                orders_count_yesterday['total']
                if orders_count_yesterday else 0,
                'aepo':
                '%.2f' % aepo_yesterday,  # AEPO: Avg Earning Per Order
            },
            'last_week': {
                'count':
                orders_count_last_week['total']
                if orders_count_last_week else 0,
                'aepo':
                '%.2f' % aepo_last_week,  # AEPO: Avg Earning Per Order
            },
            'last_28_days': {
                'count':
                orders_count_last_28_days['total']
                if orders_count_last_28_days else 0,
                'aepo':
                '%.2f' % aepo_last_28_days,  # AEPO: Avg Earning Per Order
            }
        }
        providers = list(
            OperatorProfile.objects.filter(
                business_type=OperatorProfile.PROVIDER))
        for provider in providers:
            set_counters(provider)
        providers_report = {
            'today': rank_watch_objects(providers, 'earnings_history'),
            'yesterday': rank_watch_objects(providers, 'earnings_history', 1),
            'last_week': rank_watch_objects(providers, 'earnings_history', 7),
            'last_28_days': rank_watch_objects(providers, 'earnings_history',
                                               28)
        }

        context['orders_report'] = orders_report
        context['providers_report'] = providers_report
        return context
Esempio n. 9
0
    def get_context_data(self, **kwargs):
        context = super(KakocaseDashboardBase, self).get_context_data(**kwargs)
        operator_profile = get_service_instance().config
        set_counters(operator_profile)
        earnings_today = calculate_watch_info(
            operator_profile.earnings_history)
        earnings_yesterday = calculate_watch_info(
            operator_profile.earnings_history, 1)
        earnings_last_week = calculate_watch_info(
            operator_profile.earnings_history, 7)
        earnings_last_28_days = calculate_watch_info(
            operator_profile.earnings_history, 28)

        orders_count_today = calculate_watch_info(
            operator_profile.orders_count_history)
        orders_count_yesterday = calculate_watch_info(
            operator_profile.orders_count_history, 1)
        orders_count_last_week = calculate_watch_info(
            operator_profile.orders_count_history, 7)
        orders_count_last_28_days = calculate_watch_info(
            operator_profile.orders_count_history, 28)

        # AEPO stands for Average Earning Per Order
        aepo_today = earnings_today['total'] / orders_count_today[
            'total'] if orders_count_today['total'] else 0
        aepo_yesterday = earnings_yesterday['total'] / orders_count_yesterday['total']\
            if orders_count_yesterday and orders_count_yesterday['total'] else 0
        aepo_last_week = earnings_last_week['total'] / orders_count_last_week['total']\
            if orders_count_last_week and orders_count_last_week['total'] else 0
        aepo_last_28_days = earnings_last_28_days['total'] / orders_count_last_28_days['total']\
            if orders_count_last_28_days and orders_count_last_28_days['total'] else 0

        earnings_report = {
            'today': earnings_today,
            'yesterday': earnings_yesterday,
            'last_week': earnings_last_week,
            'last_28_days': earnings_last_28_days
        }
        orders_report = {
            'today': {
                'count':
                orders_count_today['total'] if orders_count_today else 0,
                'aepo': '%.2f' % aepo_today,  # AEPO: Avg Earning Per Order
            },
            'yesterday': {
                'count':
                orders_count_yesterday['total']
                if orders_count_yesterday else 0,
                'aepo':
                '%.2f' % aepo_yesterday,  # AEPO: Avg Earning Per Order
            },
            'last_week': {
                'count':
                orders_count_last_week['total']
                if orders_count_last_week else 0,
                'aepo':
                '%.2f' % aepo_last_week,  # AEPO: Avg Earning Per Order
            },
            'last_28_days': {
                'count':
                orders_count_last_28_days['total']
                if orders_count_last_28_days else 0,
                'aepo':
                '%.2f' % aepo_last_28_days,  # AEPO: Avg Earning Per Order
            }
        }
        categories = list(ProductCategory.objects.all())
        for category in categories:
            set_counters(category)
        categories_report = {
            'today': rank_watch_objects(categories, 'earnings_history'),
            'yesterday': rank_watch_objects(categories, 'earnings_history', 1),
            'last_week': rank_watch_objects(categories, 'earnings_history', 7),
            'last_28_days': rank_watch_objects(categories, 'earnings_history',
                                               28)
        }
        products = list(Product.objects.filter(visible=True, in_trash=False))
        for product in products:
            set_counters(product)
        products_report = {
            'today': rank_watch_objects(products, 'units_sold_history'),
            'yesterday': rank_watch_objects(products, 'units_sold_history', 1),
            'last_week': rank_watch_objects(products, 'units_sold_history', 7),
            'last_28_days': rank_watch_objects(products, 'units_sold_history',
                                               28)
        }

        context['earnings_report'] = earnings_report
        context['orders_report'] = orders_report
        context['categories_report'] = categories_report
        context['products_report'] = products_report
        context['earnings_history'] = operator_profile.earnings_history[-30:]
        context[
            'earnings_history_previous_month'] = operator_profile.earnings_history[
                -60:-30]
        context[
            'transaction_count_history'] = operator_profile.orders_count_history[
                -30:]
        return context
Esempio n. 10
0
    def get_context_data(self, **kwargs):
        context = super(Dashboard, self).get_context_data(**kwargs)
        discipline_report = []
        school_year = get_school_year(self.request)
        for item in DisciplineItem.objects.filter(is_active=True):
            discipline_report_obj, update = DisciplineReport.objects\
                .get_or_create(discipline_item=item, level=None, classroom=None, school_year=school_year)
            set_counters(discipline_report_obj)
            students_yesterday = slice_watch_objects(StudentDisciplineReport, 1, 'last_add_on')
            students_last_week = slice_watch_objects(StudentDisciplineReport, 7, 'last_add_on')
            students_last_28_days = slice_watch_objects(StudentDisciplineReport, 28, 'last_add_on')
            item_report_obj = {
                'item': _(item.name),
                'report': {
                    'yesterday': {
                        'summary': calculate_watch_info(discipline_report_obj.total_history, 1),
                        'student_list': rank_watch_objects(students_yesterday, 'count_history')
                    },
                    'last_week': {
                        'summary': calculate_watch_info(discipline_report_obj.total_history, 7),
                        'student_list': rank_watch_objects(students_last_week, 'count_history')
                    },
                    'last_28_days': {
                        'summary': calculate_watch_info(discipline_report_obj.total_history, 28),
                        'student_list': rank_watch_objects(students_last_28_days, 'count_history')
                    }
                }
            }
            discipline_report.append(item_report_obj)

        # Classes report
        classes_report = {
            'today': {'count': 0, 'hours': 0},
            'yesterday': {'count': 0, 'hours': 0},
            'last_week': {'count': 0, 'hours': 0},
            'last_28_days': {'count': 0, 'hours': 0}
        }
        for report in LessonReport.objects.filter(school_year=school_year):
            set_counters(report)
            classes_report['today']['count'] += calculate_watch_info(report.count_history)['total']
            classes_report['today']['hours'] += calculate_watch_info(report.hours_count_history)['total']

        for report in LessonReport.objects.filter(school_year=school_year):
            set_counters(report)
            classes_report['yesterday']['count'] += calculate_watch_info(report.count_history, 1)['total']
            classes_report['yesterday']['hours'] += calculate_watch_info(report.hours_count_history, 1)['total']

        for report in LessonReport.objects.filter(school_year=school_year):
            set_counters(report)
            classes_report['last_week']['count'] += calculate_watch_info(report.count_history, 7)['total']
            classes_report['last_week']['hours'] += calculate_watch_info(report.hours_count_history, 7)['total']

        for report in LessonReport.objects.filter(school_year=school_year):
            set_counters(report)
            classes_report['last_28_days']['count'] += calculate_watch_info(report.count_history, 28)['total']
            classes_report['last_28_days']['hours'] += calculate_watch_info(report.hours_count_history, 28)['total']

        classroom_count = Classroom.objects.filter(school_year=school_year).count()
        for val in classes_report.values():
            val['count'] = round(float(val['count'])/classroom_count, 2) if classroom_count else 0
            val['hours'] = round(float(val['hours'])/classroom_count, 2) if classroom_count else 0

        # Session scores report
        session_queryset = Session.objects.filter(Q(is_active=False) | Q(is_current=True), school_year=school_year)
        all_session_list = []
        for session in session_queryset:
            if Score.objects.filter(session=session).count() > 0:
                all_session_list.append(session)
        session_group_list = list(SessionGroup.objects.filter(school_year=school_year))
        session_group_count = 0
        if len(all_session_list) >= 2:
            if len(session_group_list) >= 1:
                all_session_list.insert(2, session_group_list[0])
                session_group_count += 1
        if len(all_session_list) >= 5:
            if len(session_group_list) >= 2:
                all_session_list.insert(5, session_group_list[1])
                session_group_count += 1
        if len(all_session_list) >= 8:
            if len(session_group_list) >= 3:
                all_session_list.append(session_group_list[2])
                session_group_count += 1

        session_report, update = SessionReport.objects\
            .get_or_create(level=None, classroom=None, subject=None, school_year=school_year)
        session_group_report, update = SessionGroupReport.objects\
            .get_or_create(level=None, classroom=None, subject=None, school_year=school_year)

        # Billing report
        pending_invoice_count = Invoice.objects.filter(status=Invoice.PENDING, school_year=school_year).count()
        try:
            aggr = Invoice.objects.filter(status=Invoice.PENDING, school_year=school_year).aggregate(Sum('amount'))
            pending_invoice_amount = aggr['amount__sum']
        except IndexError:
            pending_invoice_amount = 0
        pending_invoice_data_list = []
        for classroom in Classroom.objects.filter(school_year=school_year):
            student_list = list(classroom.student_set.filter(is_excluded=False))
            count = Invoice.objects.filter(student__in=student_list, status=Invoice.PENDING).count()
            if count > 0:
                obj = {
                    'classroom': classroom,
                    'count': Invoice.objects.filter(student__in=student_list, status=Invoice.PENDING).count()
                }
                pending_invoice_data_list.append(obj)
        pending_invoice_data_list.sort(cmp=lambda x, y: 1 if x['count'] < y['count'] else -1)
        pending_invoice_data = {
            'count': pending_invoice_count,
            'amount': pending_invoice_amount,
            'list': pending_invoice_data_list
        }
        context['discipline_report'] = discipline_report
        context['all_session_list'] = all_session_list
        try:
            context['selected_session'] = all_session_list[-1]
            context['selected_session_order_number'] = all_session_list[-1].order_number
        except:
            pass
        context['session_report'] = session_report
        context['session_group_report'] = session_group_report
        context['classes_report'] = classes_report
        context['range_session_group'] = range(session_group_count)
        context['range_session'] = range(session_queryset.count())
        context['pending_invoice_data'] = pending_invoice_data
        return context