def iPhone11_sales():
    # 电商平台数据源概览
    total_source = []
    total_count = []
    total_good_rate = []
    for platform in ipa.Total.select():
        total_source.append(platform.source)
        total_count.append(rounding_w(platform.total))
        total_good_rate.append(float(platform.good_rate))
    # 各型号数据概览
    mc_name = []
    mc_per = []
    mc_good_rate = []
    for model in ipa.ModelCount.select():
        mc_name.append(model.color + '\n' + model.rom)
        mc_per.append(model.percentage)
        mc_good_rate.append(float(model.good_rate))
    # 机身颜色百分比
    color_count = []
    for cc in ipa.ColorCount.select():
        color_count.append({'value': float(cc.percentage), 'name': cc.color})
    # 储存容量百分比
    rom_count = []
    for roc in ipa.RomCount.select():
        rom_count.append({'value': float(roc.percentage), 'name': roc.rom})
    # 用户设备类型统计
    udc_per = []
    for udc in ipa.UserDeviceCount.select():
        udc_per.append({'value': float(udc.android_percentage), 'name': 'Android 转化用户'})
        udc_per.append({'value': float(udc.ios_percentage), 'name': 'iOS 留存用户'})
        udc_per.append({'value': float(udc.other_percentage), 'name': 'other'})

    return render_template('iPhone11_sales.html', total_source=total_source, total_count=total_count,
                           total_good_rate=total_good_rate, mc_name=mc_name, mc_per=mc_per, mc_good_rate=mc_good_rate,
                           color_count=color_count, rom_count=rom_count, udc_per=udc_per)
def wh_brand_sales_star():
    # 苹果无线耳机销量明星
    apple_model = []
    apple_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == '苹果').order_by(
            WHBrandSalesStar.total.desc()):
        apple_model.append(wh_bss.model)
        apple_mt.append(rounding_w(wh_bss.total))
    # ENKOR无线耳机销量明星
    enkor_model = []
    enkor_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == 'ENKOR').order_by(
            WHBrandSalesStar.total.desc()):
        enkor_model.append(wh_bss.model)
        enkor_mt.append(rounding_w(wh_bss.total))
    # 华为无线耳机销量明星
    hw_model = []
    hw_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == '华为').order_by(
            WHBrandSalesStar.total.desc()):
        hw_model.append(wh_bss.model)
        hw_mt.append(rounding_w(wh_bss.total))
    # 漫步者无线耳机销量明星
    edifier_model = []
    edifier_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == '漫步者').order_by(
            WHBrandSalesStar.total.desc()):
        edifier_model.append(wh_bss.model)
        edifier_mt.append(rounding_w(wh_bss.total))
    # 小米无线耳机销量明星
    mi_model = []
    mi_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == '小米').order_by(
            WHBrandSalesStar.total.desc()):
        mi_model.append(wh_bss.model)
        mi_mt.append(rounding_w(wh_bss.total))
    # 索尼无线耳机销量明星
    sony_model = []
    sony_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == '索尼').order_by(
            WHBrandSalesStar.total.desc()):
        sony_model.append(wh_bss.model)
        sony_mt.append(rounding_w(wh_bss.total))
    # Bose无线耳机销量明星
    bose_model = []
    bose_mt = []
    for wh_bss in WHBrandSalesStar.select().where(WHBrandSalesStar.brand == 'Bose').order_by(
            WHBrandSalesStar.total.desc()):
        bose_model.append(wh_bss.model)
        bose_mt.append(rounding_w(wh_bss.total))

    return render_template('wh_brand_sales_star.html', apple_model=apple_model, apple_mt=apple_mt,
                           enkor_model=enkor_model, enkor_mt=enkor_mt, hw_model=hw_model, hw_mt=hw_mt,
                           edifier_model=edifier_model, edifier_mt=edifier_mt, mi_model=mi_model, mi_mt=mi_mt,
                           sony_model=sony_model, sony_mt=sony_mt, bose_model=bose_model, bose_mt=bose_mt)
def wh_sales():
    # 数据总览
    total = WHTotal.get_by_id(1)
    total_tc = rounding_w(total.total_count)
    # 自营与非自营销量比例
    wh_self_per = WHSelfPer.get_by_id(1)
    # 无线耳机销量排行
    wh_name = []
    wh_count = []
    for item in WH.select().order_by(WH.total.asc()):
        wh_name.append(item.brand + '\n' + item.model[:20])
        wh_count.append(item.total)
    # 热销型号
    hm_name = []
    hm_count = []
    for item in WH.select().order_by(WH.total.desc()):
        hm_name.append(item.brand + '\n' + item.model[:20])
        hm_count.append(rounding_w(item.total))
    hm_name = hm_name[:12]
    hm_count = hm_count[:12]

    return render_template('wh_sales.html', total=total, total_tc=total_tc, wh_self_per=wh_self_per, wh_name=wh_name,
                           wh_count=wh_count, hm_name=hm_name, hm_count=hm_count)
def phone_sales():
    # 手机销量排行
    phone_name = []
    phone_count = []
    for item in Phone.select().order_by(Phone.total.asc()):
        phone_name.append(item.brand + '\n' + item.model)
        phone_count.append(item.total)
    # 热销机型
    hm_name = []
    hm_count = []
    for item in Phone.select().order_by(Phone.total.desc()):
        hm_name.append(item.brand + '\n' + item.model)
        hm_count.append(rounding_w(item.total))
    hm_name = hm_name[:20]
    hm_count = hm_count[:20]
    # 数据总览
    total = PhoneTotal.get_by_id(1)
    total_tc = rounding_w(total.total_count)
    # 平台数据源概览
    platform_source = []
    platform_tc = []
    platform_cc = []
    platform_sp = []
    platform_nsp = []
    for platform in PhonePlatform.select():
        platform_source.append(platform.source)
        platform_tc.append(rounding_w(platform.total_count))
        platform_cc.append(platform.commodity_count)
        platform_sp.append(float(platform.self_percentage))
        platform_nsp.append(float(platform.non_self_percentage))
    # 智能手机各项尺寸参数的平均数和中位数
    phone_size = PhoneSize.get_by_id(1)

    return render_template('phone_sales.html', phone_name=phone_name, phone_count=phone_count, total=total,
                           total_tc=total_tc, platform_source=platform_source, platform_tc=platform_tc,
                           platform_cc=platform_cc, platform_sp=platform_sp, platform_nsp=platform_nsp,
                           phone_size=phone_size, hm_name=hm_name, hm_count=hm_count)
def phone_brand_sales_star():
    # 苹果手机销量明星
    apple_model = []
    apple_mt = []
    for bss in BrandSalesStar.select().where(BrandSalesStar.brand == '苹果') \
            .order_by(BrandSalesStar.total.desc()):
        apple_model.append(bss.model)
        apple_mt.append(rounding_w(bss.total))
    # 小米手机销量明星
    mi_model = []
    mi_mt = []
    for bss in BrandSalesStar.select().where(BrandSalesStar.brand == '小米') \
            .order_by(BrandSalesStar.total.desc()):
        mi_model.append(bss.model)
        mi_mt.append(rounding_w(bss.total))
    # 华为手机销量明星
    hw_model = []
    hw_mt = []
    for bss in BrandSalesStar.select().where(BrandSalesStar.brand == '华为') \
            .order_by(BrandSalesStar.total.desc()):
        hw_model.append(bss.model)
        hw_mt.append(rounding_w(bss.total))
    # 荣耀手机销量明星
    honor_model = []
    honor_mt = []
    for bss in BrandSalesStar.select().where(BrandSalesStar.brand == '荣耀') \
            .order_by(BrandSalesStar.total.desc()):
        honor_model.append(bss.model)
        honor_mt.append(rounding_w(bss.total))
    # OPPO手机销量明星
    oppo_model = []
    oppo_mt = []
    for bss in BrandSalesStar.select().where(BrandSalesStar.brand == 'OPPO') \
            .order_by(BrandSalesStar.total.desc()):
        oppo_model.append(bss.model)
        oppo_mt.append(rounding_w(bss.total))
    # vivo手机销量明星
    vivo_model = []
    vivo_mt = []
    for bss in BrandSalesStar.select().where(BrandSalesStar.brand == 'vivo') \
            .order_by(BrandSalesStar.total.desc()):
        vivo_model.append(bss.model)
        vivo_mt.append(rounding_w(bss.total))

    return render_template('phone_brand_sales_star.html', apple_model=apple_model, apple_mt=apple_mt, mi_model=mi_model,
                           mi_mt=mi_mt, hw_model=hw_model, hw_mt=hw_mt, honor_model=honor_model, honor_mt=honor_mt,
                           oppo_model=oppo_model, oppo_mt=oppo_mt, vivo_model=vivo_model, vivo_mt=vivo_mt,)
def phone_soc_sales():
    # SoC销量排行
    soc_name = []
    soc_count = []
    for soc in SoC.select().order_by(SoC.total.asc()):
        if soc.soc_model == '未知':
            continue
        soc_name.append(soc.soc_mfrs + '\n' + soc.soc_model)
        soc_count.append(soc.total)
    # 热销型号
    hm_name = []
    hm_count = []
    for item in SoC.select().order_by(SoC.total.desc()):
        if item.soc_model == '未知':
            continue
        hm_name.append(item.soc_mfrs + '\n' + item.soc_model)
        hm_count.append(rounding_w(item.total))
    hm_name = hm_name[:20]
    hm_count = hm_count[:20]

    return render_template('phone_soc_sales.html', soc_name=soc_name, soc_count=soc_count, hm_name=hm_name,
                           hm_count=hm_count)
def phone_soc_mfrs_sales_star():
    # 苹果A系列SoC销量明星
    as_model = []
    as_mt = []
    for soc in SoCStar.select().where(SoCStar.soc_mfrs == '苹果(A系列)').order_by(SoCStar.total.desc()):
        as_model.append(soc.soc_model)
        as_mt.append(rounding_w(soc.total))
    # 紫光展锐SoC销量明星
    unisoc_model = []
    unisoc_mt = []
    for soc in SoCStar.select().where(SoCStar.soc_mfrs == '紫光展锐').order_by(SoCStar.total.desc()):
        unisoc_model.append(soc.soc_model)
        unisoc_mt.append(rounding_w(soc.total))
    # 三星猎户座SoC销量明星
    exynos_model = []
    exynos_mt = []
    for soc in SoCStar.select().where(SoCStar.soc_mfrs == '三星猎户座').order_by(SoCStar.total.desc()):
        exynos_model.append(soc.soc_model)
        exynos_mt.append(rounding_w(soc.total))
    # 高通骁龙SoC销量明星
    snapdragon_model = []
    snapdragon_mt = []
    for soc in SoCStar.select().where(SoCStar.soc_mfrs == '高通骁龙').order_by(SoCStar.total.desc()):
        snapdragon_model.append(soc.soc_model)
        snapdragon_mt.append(rounding_w(soc.total))
    # 海思麒麟SoC销量明星
    kirin_model = []
    kirin_mt = []
    for soc in SoCStar.select().where(SoCStar.soc_mfrs == '海思麒麟').order_by(SoCStar.total.desc()):
        kirin_model.append(soc.soc_model)
        kirin_mt.append(rounding_w(soc.total))
    # 联发科SoC销量明星
    mtk_model = []
    mtk_mt = []
    for soc in SoCStar.select().where(SoCStar.soc_mfrs == '联发科').order_by(SoCStar.total.desc()):
        mtk_model.append(soc.soc_model)
        mtk_mt.append(rounding_w(soc.total))

    return render_template('phone_soc_mfrs_sales_star.html', as_model=as_model, as_mt=as_mt,
                           unisoc_model=unisoc_model, unisoc_mt=unisoc_mt, exynos_model=exynos_model,
                           exynos_mt=exynos_mt, snapdragon_model=snapdragon_model, snapdragon_mt=snapdragon_mt,
                           kirin_model=kirin_model, kirin_mt=kirin_mt, mtk_model=mtk_model, mtk_mt=mtk_mt)