Beispiel #1
0
def calc_purchase_rate(target_date=None):
    # 首先获得本周新加入的用户
    user_collect = db['User']
    if target_date is None:
        start_date = local2utc(get_first_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
    else:
        start_date = local2utc(get_first_datetime_in_week(target_date - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(target_date - datetime.timedelta(days=7)))
    users = user_collect.find({'created_at': {'$gte': start_date}})
    user_count = 0
    once = 0  # 用户的一次购买人数
    twice = 0  # 用户的二次购买人数
    user_pay_collect = db['UserPay']
    for user in users:
        user_count += 1
        user_id = user.get('_id')
        user_pay_count = user_pay_collect.find({'user._id': user_id, 'status': 'PAY_SUCCESS', 'created_at': {'$gte': start_date, '$lt': end_date}}).count()
        if user_pay_count >= 1:
            once += 1
        elif user_pay_count > 1:
            twice += 1
    if user_count <= 0 or once <=0 :
        return 0, 0, once, twice, user_count
    return once / (user_count * 1.0), twice / (once * 1.0), once, twice, user_count
Beispiel #2
0
def paid_purchases(target_date=None):
    user_pay = db['UserPay']
    if target_date is None:
        start_date = local2utc(get_first_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
    else:
        start_date = local2utc(get_first_datetime_in_week(target_date - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(target_date - datetime.timedelta(days=7)))
    return user_pay.find({'status': 'PAY_SUCCESS', 'updated_at': {'$gte': start_date, '$lt': end_date}}).count()
Beispiel #3
0
def end_clazz_count(target_date=None):
    clazz_collect = db['Clazz']
    if target_date is None:
        start_date = local2utc(get_first_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
    else:
        start_date = local2utc(get_first_datetime_in_week(target_date - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(target_date - datetime.timedelta(days=7)))
    end_count = clazz_collect.find({'clazzType': {'$ne': 'LTS'}, 'endDate': {'$gte': start_date, '$lt': end_date}}).count()
    return end_count
Beispiel #4
0
def subscriptions(target_date=None):
    clazz_account = db['ClazzAccount']
    if target_date is None:
        start_date = local2utc(get_first_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(get_today_date() - datetime.timedelta(days=7)))
    else:
        start_date = local2utc(get_first_datetime_in_week(target_date - datetime.timedelta(days=7)))
        end_date = local2utc(get_last_datetime_in_week(target_date - datetime.timedelta(days=7)))
    return clazz_account.find({'status': 'PROCESSING', 'clazz.created_at': {'$gte': start_date, '$lt': end_date},
                               'clazz.clazzType': 'SEMESTER' }).count()