Esempio n. 1
0
def calc_counters(request):
    start_date = None if request.GET.get("do_all") else (default_tz_now_min() - timedelta(days=1)) # all or start for yesterday
    end_date = default_tz_now_max() - timedelta(days=1)

    total_orders, created = Counter.objects.get_or_create(name="total_orders")
    total_orders.value = Order.objects.filter(type=OrderType.SHARED, debug=False, status=CHARGED).count()
    total_orders.save()

    money_saved, created = Counter.objects.get_or_create(name="money_saved")

    if not start_date:
        money_saved.value = 0
        money_saved.save()
        logging.info("fresh calculation - until %s" % end_date)
    else:
        if money_saved.modify_date > end_date:
            msg = "money saved already calculated: %s < %s" % (money_saved.modify_date, end_date)
            logging.error(msg)
            return HttpResponseBadRequest(msg)

        logging.info("from %s - until %s" % (start_date, end_date))

    deferred.defer(do_calc, start_date, end_date, _queue="maintenance")

    return HttpResponse("OK")
Esempio n. 2
0
def calc_counters(request):
    start_date = None if request.GET.get("do_all") else (
        default_tz_now_min() - timedelta(days=1))  # all or start for yesterday
    end_date = default_tz_now_max() - timedelta(days=1)

    total_orders, created = Counter.objects.get_or_create(name="total_orders")
    total_orders.value = Order.objects.filter(type=OrderType.SHARED,
                                              debug=False,
                                              status=CHARGED).count()
    total_orders.save()

    money_saved, created = Counter.objects.get_or_create(name="money_saved")

    if not start_date:
        money_saved.value = 0
        money_saved.save()
        logging.info("fresh calculation - until %s" % end_date)
    else:
        if money_saved.modify_date > end_date:
            msg = "money saved already calculated: %s < %s" % (
                money_saved.modify_date, end_date)
            logging.error(msg)
            return HttpResponseBadRequest(msg)

        logging.info("from %s - until %s" % (start_date, end_date))

    deferred.defer(do_calc, start_date, end_date, _queue="maintenance")

    return HttpResponse("OK")
Esempio n. 3
0
def kpi(request):
    na = "N/A"
    init_start_date = default_tz_now_min() - timedelta(days=1)
    init_end_date = default_tz_now_max()
    channel_id = get_uuid()
    token = channel.create_channel(channel_id)

    from analytics.kpi import calc_kpi_data
    return base_datepicker_page(request, calc_kpi_data, 'kpi.html', locals(), init_start_date, init_end_date, async=True)
Esempio n. 4
0
        def get_query_date_range_by_month_offset(month_offset):
            now = default_tz_now()
            if now.month > month_offset:
                d = now.replace(month=now.month - month_offset)
            else:
                d = now.replace(month=now.month - month_offset + 12, year=now.year -1)


            start_day, end_day = calendar.monthrange(d.year, d.month)

            start_date = default_tz_now_min().replace(day=1, month=d.month, year=d.year)
            end_date = default_tz_now_max().replace(day=end_day, month=d.month, year=d.year)

            return start_date, end_date
Esempio n. 5
0
def kpi(request):
    na = "N/A"
    init_start_date = default_tz_now_min() - timedelta(days=1)
    init_end_date = default_tz_now_max()
    channel_id = get_uuid()
    token = channel.create_channel(channel_id)

    from analytics.kpi import calc_kpi_data
    return base_datepicker_page(request,
                                calc_kpi_data,
                                'kpi.html',
                                locals(),
                                init_start_date,
                                init_end_date,
                                async=True)
Esempio n. 6
0
        def get_query_date_range_by_month_offset(month_offset):
            now = default_tz_now()
            if now.month > month_offset:
                d = now.replace(month=now.month - month_offset)
            else:
                d = now.replace(month=now.month - month_offset + 12,
                                year=now.year - 1)

            start_day, end_day = calendar.monthrange(d.year, d.month)

            start_date = default_tz_now_min().replace(day=1,
                                                      month=d.month,
                                                      year=d.year)
            end_date = default_tz_now_max().replace(day=end_day,
                                                    month=d.month,
                                                    year=d.year)

            return start_date, end_date
Esempio n. 7
0
        if form.is_valid():
            start_date = datetime.datetime.combine(form.cleaned_data["start_date"], datetime.time.min)
            end_date = datetime.datetime.combine(form.cleaned_data["end_date"], datetime.time.max)
            if async:
                assert wrapper_locals.get('channel_id')
                assert wrapper_locals.get('token')
                async_computation_submitted_signal.send(sender="base_datepicker_page", channel_id=wrapper_locals.get('channel_id'))
                deferred.defer(f_data, start_date, end_date, channel_id=wrapper_locals.get('channel_id'), token=wrapper_locals.get('token'))
                return JSONResponse({'status': 'submitted', 'token': wrapper_locals.get('token')})
            else:
                return JSONResponse({'data': f_data(start_date, end_date)})
        else:
            return JSONResponse({'error': 'error'})
    else:
        form = DatePickerForm()
        init_end_date = init_end_date or default_tz_now_max()
        init_start_date = init_start_date or default_tz_now_min()
        if async:
            assert wrapper_locals.get('channel_id')
            assert wrapper_locals.get('token')
            async_computation_submitted_signal.send(sender="base_datepicker_page", channel_id=wrapper_locals.get('channel_id'))
            deferred.defer(f_data, init_start_date, init_end_date, channel_id=wrapper_locals.get('channel_id'), token=wrapper_locals.get('token'))
            data = simplejson.dumps({'status': 'submitted', 'token': wrapper_locals.get('token')})
        else:
            data = simplejson.dumps(f_data(init_start_date, init_end_date))

        start_date, end_date = to_js_date(init_start_date), to_js_date(init_end_date)

        extended_locals = wrapper_locals.copy()
        extended_locals.update(locals())
Esempio n. 8
0
             deferred.defer(f_data,
                            start_date,
                            end_date,
                            channel_id=wrapper_locals.get('channel_id'),
                            token=wrapper_locals.get('token'))
             return JSONResponse({
                 'status': 'submitted',
                 'token': wrapper_locals.get('token')
             })
         else:
             return JSONResponse({'data': f_data(start_date, end_date)})
     else:
         return JSONResponse({'error': 'error'})
 else:
     form = DatePickerForm()
     init_end_date = init_end_date or default_tz_now_max()
     init_start_date = init_start_date or default_tz_now_min()
     if async:
         assert wrapper_locals.get('channel_id')
         assert wrapper_locals.get('token')
         async_computation_submitted_signal.send(
             sender="base_datepicker_page",
             channel_id=wrapper_locals.get('channel_id'))
         deferred.defer(f_data,
                        init_start_date,
                        init_end_date,
                        channel_id=wrapper_locals.get('channel_id'),
                        token=wrapper_locals.get('token'))
         data = simplejson.dumps({
             'status': 'submitted',
             'token': wrapper_locals.get('token')