Beispiel #1
0
def poster_uv_everyday_distribution(day_time):
    '''
    海报使用次数、人数
    :param day_time:某一天,格式为:"2018-11-21"
    :return: posters_pv:海报使用次数, poster_uv:海报使用人数
    '''

    star_timeStamp = day2timestamp(day_time)

    posters = mdb.log_poster.find(
        {"ctime": {
            "$gte": star_timeStamp,
            "$lt": star_timeStamp + 86400
        }})
    posters_types_count = {}
    temp_count = 0
    for p in posters:
        temp_id = p["temp_id"]
        temp = mdb.temp_poster.find({"_id": temp_id})
        for t in temp:
            try:
                if t["sub_type"] not in posters_types_count.keys():
                    posters_types_count[t["sub_type"]] = 1
                else:
                    posters_types_count[t["sub_type"]] += 1
            except:
                temp_count += 1
    print(temp_count)

    return posters_types_count
Beispiel #2
0
def poster_uv_everyday(day_time):
    '''
    海报使用次数、人数
    :param day_time:某一天,格式为:"2018-11-21"
    :return: posters_pv:海报使用次数, poster_uv:海报使用人数
    '''

    star_timeStamp = day2timestamp(day_time)

    posters = mdb.log_poster.distinct(
        "uid",
        {"ctime": {
            "$gte": star_timeStamp,
            "$lt": star_timeStamp + 86400
        }})  # 使用海报的uid
    poster_uv = len(posters)  # 海报使用人数

    posters_pv = mdb.log_poster.find({
        "ctime": {
            "$gte": star_timeStamp,
            "$lt": star_timeStamp + 86400
        }
    }).count()  # 海报使用次数

    return posters_pv, poster_uv
Beispiel #3
0
def get_vip_stylist_list():
    '''
    生成使用售后卡功能的VIP发型师名单,及电话号码
    :return:
    '''
    w = xlwt.Workbook()
    sh = w.add_sheet("发型师信息")

    day_time_start = "2019-1-10"
    star_timeStamp0 = day2timestamp(day_time_start)
    print(star_timeStamp0)
    for k in range(7):
        star_timeStamp = star_timeStamp0 + k * 86400

        stylists = get_stylists(star_timeStamp)

        print("使用售后卡人数:", len(stylists))
        print(stylists)

        import datetime
        dateArray = datetime.datetime.utcfromtimestamp(star_timeStamp + 36000)
        otherStyleTime = dateArray.strftime("%Y--%m--%d")

        sh.write(0, 4 * k + 0, otherStyleTime)

        sh.write(1, 4 * k + 0, "姓名")
        sh.write(1, 4 * k + 1, "电话号码")
        sh.write(1, 4 * k + 2, "vip")

        for i, sy in enumerate(stylists):
            sy_id = int(sy)
            s_vip, s_mobile, s_name = get_stylist_phone_vip(sy_id, star_timeStamp)

            if s_vip == "vip":
                sh.write(i + 2, 4 * k + 0, s_name)
                sh.write(i + 2, 4 * k + 2, s_vip)
                sh.write(i + 2, 4 * k + 1, s_mobile)

    w.save("/Users/sunyihuan/Desktop/使用售后卡发型师.xls")
def get_wangluosheji_stylists(day_time):
    '''
    获取某段时间内,完成网络设计订单的发型师名单
    :param day_time:
    :return:
    '''
    star_timeStamp = day2timestamp(day_time)
    needs_finish = mdb.xm_hair_scheme.find({
        "is_finish": 1,
        "ctime": {
            "$gte": ts2utcdatetime(star_timeStamp),
            "$lt": ts2utcdatetime(star_timeStamp + 30 * 86400)
        }
    })
    wangluo_stylist = []
    for n_f in needs_finish:
        need_id = id2ObjectId(n_f["need_id"])
        needs_p = mdb.xm_hair_need.find({"_id": need_id})
        for n in needs_p:
            if n["source"] == 2:
                if n["myid"] not in wangluo_stylist:
                    wangluo_stylist.append(n["myid"])
    return wangluo_stylist
        },
        "sort": {
            "action_timestamp": {  # 根据action_timestamp字段升序排序
                "order": "desc"  # asc升序,desc降序
            }
        }
    }

    res = es.search(index=index, body=body)  # 获取测试端数据

    return res["aggregations"]['uv']['value']


def five_daohang_page_uv(index, gt_time, lt_time):
    page_uv = {}
    for current_page in [
            "app-001", "jin-ri-ying-xiao", "hai-bao", "ke_hu", "wo-de"
    ]:
        page_name = "{}_uv".format(current_page)
        uv = DaoHang_uv(index, gt_time, lt_time, current_page)
        page_uv[page_name] = uv
    return page_uv


if __name__ == "__main__":
    index = 'user_behavior_log_prod_20180723'  # 线上index
    start_time = day2timestamp("2019-1-6")  # 当日的日期,转化为当日0点时间戳
    end_time = day2timestamp("2019-1-7")  # 后一天的日期,转化为后一天0点时间戳

    print(five_daohang_page_uv(index, start_time, end_time))
Beispiel #6
0
# coding:utf-8
'''
色板模块使用人数
created on 2019/1/7

@author:sunyihuan
'''
from utils import connect_mongodb_sheji, connect_es, id2ObjectId, day2timestamp, ts2utcdatetime, list_change_type

mdb = connect_mongodb_sheji()
stylists_color_disk = mdb.xm_good_colour_disk.distinct("myid", {"status": 101})
print("完成色板设置总人数:", len(stylists_color_disk))

star_timeStamp = day2timestamp("2019-1-7")
vip_st = mdb.wxuser.distinct("_id", {"expireat": {
    "$gt": star_timeStamp
}})  # vip列表
stylists_color_disk_vip = set(stylists_color_disk) & set(vip_st)
print("完成色板设置VIP总人数:", len(stylists_color_disk_vip))

# "brand_id"=100001 伊诺雅;"brand_id"=100002欧莱雅;"brand_id"=100005施华蔻;
# "brand_id"=100004 威娜;"brand_id"=100005 资生堂

stylists_color_yny = mdb.xm_good_colour_disk.distinct("myid", {
    "status": 101,
    "brand_id": 100001
})
print("选择伊诺雅设置总人数:", len(stylists_color_yny))
stylists_color_oly = mdb.xm_good_colour_disk.distinct("myid", {
    "status": 101,
    "brand_id": 100002
Beispiel #7
0
                if u["inline"] == 1:
                    amounts -= o["price"]
            typ = o["type"]
            if typ not in type.keys():
                type[typ] = 1
        except:
            print(o)
        else:
            type[typ] = type[typ] + 1
    return amounts, type


if __name__ == "__main__":
    start_time = "2019-5-1"
    end_time = "2019-6-1"
    start_time = day2timestamp(start_time)
    print(start_time)
    end_time = day2timestamp(end_time)
    print(end_time)
    #
    # mobile_nums, buy_vip_nums, vip_nums, one_month_expire = basic_data(start_time, end_time)
    # print("已存入手机号码人数: ", mobile_nums)
    # print("购买过VIP人数: ", buy_vip_nums)
    # print("当前VIP人数: ", vip_nums)
    # print("一个月内到期的人数: ", one_month_expire)
    #
    #
    # t_count, t_uid = twice_buy_vip()
    # print("二次购买人数: ", t_count)
    # print(t_uid)
Beispiel #8
0
    three_days_using_uv = set(stylist_one) & set(stylist_two) & set(
        stylist_three)
    two_stylist = (set(stylist_one) & set(stylist_two)) | (
        set(stylist_two) & set(stylist_three))
    return stylist_one, stylist_two, stylist_three, three_days_using_uv, two_stylist


if __name__ == "__main__":
    # stylists = seven_day_stylist()
    # card_nums = mdb.customer_card_after.find(
    #     {"status": 101, "ctime": {"$gt": ts2utcdatetime(1545062400), "$lt": ts2utcdatetime(1545148800)}}).count()
    # card_get_nums = mdb.customer_card_after.find({"status": 101, "is_get": 1,
    #                                               "ctime": {"$gt": ts2utcdatetime(1545062400),
    #                                                         "$lt": ts2utcdatetime(1545148800)}}).count()
    # print("使用售后服务卡功能人数:", len(stylists))
    # print("生成售后服务卡总数:", card_nums)
    # print("售后服务卡被领取总数:", card_get_nums)
    day_time_start = "2019-1-28"

    star_timeStamp = day2timestamp(day_time_start)

    # stylist_one, stylist_two, stylist_three, three_days_using_uv, two_stylist = three_days_using_card(star_timeStamp)
    # print("第一天使用人数", len(stylist_one))
    # print("第二天使用人数", len(stylist_two))
    # print("第三天使用人数", len(stylist_three))
    # print("连续两天都使用的人数", len(two_stylist))
    # print("三天都使用的人数", len(three_days_using_uv))
    # print(two_stylist)
    two_stylist = two_days_using_card_stylists(star_timeStamp)
    stylists_2_excel(two_stylist, star_timeStamp)
Beispiel #9
0

def average_uv(index, endtime, n):
    '''
    vip近n天的平均日活、VIP购买量
    :param endtime: 当前时间
    :param n: 天数
    :return:
    '''
    av_vip_uv = 0
    bus_av = 0
    for i in range(30):
        end_time = endtime - i * 86400
        start_time = end_time - 86400

        vip_uv = days_vip_uv(index, start_time, end_time)
        buy_vip_nums = days_buy_nums(start_time, end_time)

        av_vip_uv += len(vip_uv)
        bus_av += buy_vip_nums

    return int(av_vip_uv / n), int(bus_av / n)


if __name__ == "__main__":
    index = 'user_behavior_log_prod_20180723'  # 线上index
    # start_time = day2timestamp("2019-2-10")  # 当日的日期,转化为当日0点时间戳
    end_time0 = day2timestamp("2019-3-11")  # 后一天的日期,转化为后一天0点时间戳
    av_vip_uv, bus_av = average_uv(index, end_time0, 30)
    print(av_vip_uv, bus_av)
Beispiel #10
0
                    #     }
                    # }
                ],
                "should": []
            }
        },
        "sort": {
            "action_timestamp": {  # 根据action_timestamp字段升序排序
                "order": "desc"  # asc升序,desc降序
            }
        }
    }

    res = es.search(index=index, body=body)  # 获取测试端数据

    return res["aggregations"]['uv']['value']


if __name__ == "__main__":
    index = 'user_behavior_log_prod_20180723'  # 线上index
    start_time0 = day2timestamp("2019-2-13")  # 当日的日期,转化为当日0点时间戳
    for i in range(7):
        start_time = start_time0 + 86400 * i
        end_time = start_time + 86400
        haibao_uv = DaoHang_uv(index, start_time, end_time, "hai-bao")
        chaoliu_uv = DaoHang_uv(index, start_time, end_time,
                                "fa-xing-chao-liu")
        print("日期:", str(timeStamp2day(start_time + 34000)).split(" ")[0])
        print("海报访问人数:", haibao_uv)
        print("发型潮流访问人数:", chaoliu_uv)
Beispiel #11
0
                buy_time = timeStamp2date(buy_time)
            except:
                continue
            if int(tell) > 0:
                sh.write(i + 1, 0, i + 1)
                sh.write(i + 1, 1, name)  # 写入名字
                sh.write(i + 1, 2, tell)  # 写入手机号码
                sh.write(i + 1, 3, buy_time)  # 写入购买时间
                sh.write(i + 1, 4, price)  # 写入购买金额
                sh.write(i + 1, 5, ex_time)  # 写入到期时间
        except:
            print(i, myid)
            c += 1
            print(c)

    w.save("/Users/sunyihuan/Desktop/近30天未使用app名单.xls")


if __name__ == "__main__":
    end_time = "2019-1-14"
    end_time = day2timestamp(end_time)
    # no_using_list_7 = day_nums_no_using(7)
    # no_using_list_15 = day_nums_no_using(15)
    no_using_list_30 = day_nums_no_using(end_time, 30)
    no_using = Correcting_user(no_using_list_30, end_time, 30)
    print(len(no_using))
    # print("7日未登陆app人数:", len(no_using_list_7))
    # print("15日未登陆app人数:", len(no_using_list_15))
    print("30日未登陆app人数:", len(no_using_list_30))
    write2excel(no_using)
Beispiel #12
0

def write2excel(name):
    import xlwt
    w = xlwt.Workbook()
    sh = w.add_sheet("name")
    sh.write(0, 0, "name")
    sh.write(0, 1, "count")
    for i in range(len(name)):
        sh.write(i + 1, 0, name[i][0])
        sh.write(i + 1, 1, name[i][1])
    w.save("/Users/sunyihuan/Desktop/scheme_name.xls")


if __name__ == "__main__":
    start_time = day2timestamp("2018-10-01")
    sc_f, sc_name = scheme_static(ts2utcdatetime(start_time))
    sc = sorted(sc_f.items(), key=lambda x: x[1], reverse=True)
    name = sorted(sc_name.items(), key=lambda x: x[1], reverse=True)
    print(sc)
    print(name)
    # for sn in sc_name.keys():
    #     print(sn.split("心")[1])
    fa_count = {}
    for ss in sc_name.keys():
        fachang = ss.split("心")[1]
        if fachang not in fa_count.keys():
            fa_count[fachang] = sc_name[ss]
        else:
            fa_count[fachang] += sc_name[ss]
    fa_count = sorted(fa_count.items(), key=lambda x: x[1], reverse=True)
Beispiel #13
0
def changJing_data(day_time_start):
    '''
    返回某一日数据看板中的数据
    :param day_time_start: 日期,格式为:"2018-12-21"
    :return:
    sheji_st:设计沟通场景日活,
    sheji_st_vip:设计沟通场景VIP日活,
    poster_st:营销拓客场景日活,
    poster_st_vip:营销拓客场景VIP日活,
    stylists:美助app日活,
    stylists_yes:美助app昨日留存, 
    stylists_vip:美助app中VIP日活
    '''
    mdb = connect_mongodb_sheji()  # 链接sheji
    star_timeStamp = day2timestamp(day_time_start)

    vip_st = mdb.wxuser.distinct("_id", {"expireat": {
        "$gt": star_timeStamp
    }})  # vip列表
    vip_st = list_change_type(int, vip_st)

    poster_st = mdb.log_poster.distinct(
        "uid",
        {"ctime": {
            "$gt": star_timeStamp,
            "$lt": star_timeStamp + 86400
        }})  # 使用海报发型师uv

    fxcl_st = mdb.log_material.distinct(
        "uid",
        {"ctime": {
            "$gt": star_timeStamp,
            "$lt": star_timeStamp + 86400
        }})  # 使用海报发型师uv

    poster_st = set(poster_st) | set(fxcl_st)
    poster_st = list_change_type(int, poster_st)

    stylist_one = mdb.xm_hair_scheme.distinct(
        "myid", {
            "utime": {
                "$gte": ts2utcdatetime(star_timeStamp + 0 * 86400),
                "$lt": ts2utcdatetime(star_timeStamp + 86400)
            },
            "is_finish": 1
        })  # 完成订单发型师
    stylist_one = list_change_type(int, stylist_one)
    stylist_t = mdb.xm_good_hair.distinct(
        "myid", {
            "utime": {
                "$gte": ts2utcdatetime(star_timeStamp + 0 * 86400),
                "$lt": ts2utcdatetime(star_timeStamp + 86400)
            },
            "status": 1
        })  # 收藏发型的发型师
    stylist_t = list_change_type(int, stylist_t)

    sheji_st = set(stylist_one) | set(stylist_t)  # 设计沟通场景发型师日活
    sheji_st = list_change_type(int, sheji_st)

    sheji_st_vip = (set(stylist_one) | set(stylist_t)) & set(
        vip_st)  # 设计沟通场景发型师VIP日活

    poster_st_vip = set(vip_st) & set(poster_st)  # 使用海报发型师中VIP的人数

    stylists = seven_day_stylist(star_timeStamp,
                                 star_timeStamp + 86400)  # 美业助手app当日uv

    stylists_yestday = seven_day_stylist(star_timeStamp - 86400,
                                         star_timeStamp)  # 美业助手app昨日uv
    vip_st = list_change_type(str, vip_st)

    stylists_yes = set(stylists) & set(stylists_yestday)  # 次日留存人数

    stylists_vip = set(stylists) & set(vip_st)  # 美业助手app当日VIP日活

    return sheji_st, sheji_st_vip, poster_st, poster_st_vip, stylists, stylists_yes, stylists_vip
def get_finished_stylist_list(day_time):
    '''
    自2018-11-11开始
    近30天完成订单用户中,完成订单次数前100排名(名字/电话/剪发价位/地址)
    近30天完成订单用户中,完成订单次数前100排名(名字/电话/剪发价位/地址)
    :return:day_time:开始日期,格式 "2018-11-11"
    '''
    w = xlwt.Workbook()
    sh_wangluo = w.add_sheet("网络设计")
    sh_xianchang = w.add_sheet("现场设计")

    star_timeStamp = day2timestamp(day_time)
    needs_finish = mdb.xm_hair_scheme.find({"is_finish": 1, "ctime": {"$gte": ts2utcdatetime(star_timeStamp),
                                                                      "$lt": ts2utcdatetime(
                                                                          star_timeStamp + 30 * 86400)}})

    wangluo_stylist = {}
    xianchang_stylist = {}
    for n_f in needs_finish:
        need_id = id2ObjectId(n_f["need_id"])
        needs_p = mdb.xm_hair_need.find({"_id": need_id})
        for n in needs_p:
            my_id = n["myid"]
            if n["source"] == 2:
                if my_id not in wangluo_stylist.keys():
                    wangluo_stylist[my_id] = 1
                else:
                    wangluo_stylist[my_id] += 1

            elif n["source"] == 1:
                if my_id not in xianchang_stylist.keys():
                    xianchang_stylist[my_id] = 1
                else:
                    xianchang_stylist[my_id] += 1

    wangluo_stylist = dict_sorted(wangluo_stylist)
    xianchang_stylist = dict_sorted(xianchang_stylist)

    wangluo_n = get_n_range(wangluo_stylist)
    xianchang_n = get_n_range(xianchang_stylist)

    sh_wangluo.write(0, 0, "姓名")
    sh_wangluo.write(0, 1, "手机号码")
    sh_wangluo.write(0, 2, "剪发价格")
    sh_wangluo.write(0, 3, "发廊地址")
    sh_wangluo.write(0, 4, "单数")
    for i in range(wangluo_n):
        my_id = wangluo_stylist[i][0]
        my_nums = wangluo_stylist[i][1]
        sh_wangluo.write(i + 1, 4, my_nums)
        try:
            s_p = mdb.person.find({"uid": my_id})
            for s__ in s_p:
                if s__["user_name"] != "":
                    sh_wangluo.write(i + 1, 1, s__["mobile"])
                    sh_wangluo.write(i + 1, 0, s__["user_name"])
                    sh_wangluo.write(i + 1, 2, s__["cut_price"])
                    sh_wangluo.write(i + 1, 3, s__["salon_position"])
        except:
            print(my_id)

    sh_xianchang.write(0, 0, "姓名")
    sh_xianchang.write(0, 1, "手机号码")
    sh_xianchang.write(0, 2, "剪发价格")
    sh_xianchang.write(0, 3, "发廊地址")
    sh_xianchang.write(0, 4, "单数")
    for i_ in range(xianchang_n):
        my_id__ = xianchang_stylist[i_][0]
        my_nums_ = xianchang_stylist[i_][1]
        sh_xianchang.write(i_ + 1, 4, my_nums_)
        try:
            s_p = mdb.person.find({"uid": my_id__})
            for s__ in s_p:
                if s__["user_name"] != "":
                    sh_xianchang.write(i_ + 1, 0, s__["user_name"])
                    sh_xianchang.write(i_ + 1, 1, s__["mobile"])
                    sh_xianchang.write(i_ + 1, 2, s__["cut_price"])
                    sh_xianchang.write(i_ + 1, 3, s__["salon_position"])
        except:
            print(my_id__)
    w.save("/Users/sunyihuan/Desktop/{}近30天完成订单发型师名单(前100).xls".format(day_time))
Beispiel #15
0
                        }
                    }
                ],
                "should": []
            }
        },
        "sort": {
            "action_timestamp": {  # 根据action_timestamp字段升序排序
                "order": "desc"  # asc升序,desc降序
            }
        }
    }

    res = es.search(index=index, body=body)  # 获取测试端数据

    return res["aggregations"]['uv']['value']


if __name__ == "__main__":
    index = 'user_behavior_log_prod_20180723'  # 线上index
    start_time = day2timestamp("2019-3-1")  # 当日的日期,转化为当日0点时间戳
    end_time = day2timestamp("2019-3-2")  # 后一天的日期,转化为后一天0点时间戳

    huanyihuan_uv = shidai_page_uv(index, start_time, end_time, "huan_yi_huan")

    fenxiang_uv = shidai_page_uv(index, start_time, end_time,
                                 "fen_xiang_gui_mi")

    print(huanyihuan_uv)
    print(fenxiang_uv)