Beispiel #1
0
def test_grid_line_pie():
    line = Line("折线图示例", width=1200)
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
        legend_pos="20%",
    )
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例", title_pos="55%")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[45, 65],
        center=[65, 50],
        legend_pos="80%",
        legend_orient="vertical",
    )

    grid = Grid()
    grid.add(line, grid_right="55%")
    grid.add(pie, grid_left="60%")
    grid.render()
Beispiel #2
0
def get_pie(item_name,item_name_list,item_num_list):
    totle = item_num_list[0]+item_num_list[1]+item_num_list[2]
    subtitle = "共有:%d个好友"%totle

    pie = Pie(item_name,page_title = item_name,title_text_size=30,title_pos='center',\
        subtitle = subtitle,subtitle_text_size = 25,width=800,height= 800)
    
    pie.add("", item_name_list, item_num_list,is_label_show=True,center=[50, 45],radius=[0,50],\
        legend_pos ='left',legend_orient='vertical',label_text_size=20)

    out_file_name = './analyse/'+item_name+'.html'
    #print(out_file_name)
    pie.render(out_file_name)
Beispiel #3
0
def test_pie_legend():
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )
    pie.render()
Beispiel #4
0
def test_page():
    page = Page()
    line = Line("折线图示例")
    line.chart_id = "id_my_cell_line"
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
    )

    # pie
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center", width="600px")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    page.add([line, pie, create_a_bar(TITLE)])
    # Start render and test
    html = page._repr_html_()
    # Test base html structure
    assert html.count("<script>") == html.count("</script>") == 2
    assert html.count("<div") == html.count("</div>") == 3
    assert html.count("require.config") == html.count("function(echarts)") == 1
    # Test some chart attributes
    json_encoded_title = json.dumps(TITLE)
    assert json_encoded_title in html
    assert "nbextensions/echarts" in html  # default jshost
    assert html.count("height:400px") == 3
    assert html.count("width:600px") == 1
    assert html.count("width:800px") == 2
    assert html.count("id_my_cell_line") == 6
def draw_citys_pic(csv_file):
    page = Page(csv_file+":评论城市分析")
    info = count_city(csv_file)
    geo = Geo("","Ctipsy原创",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff")
    while True:   # 二次筛选,和pyecharts支持的城市库进行匹配,如果报错则删除该城市对应的统计
        try:
            attr, val = geo.cast(info)
            geo.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False,
                    is_piecewise=True, visual_split_number=6, symbol_size=15, is_visualmap=True)
        except ValueError as e:
            e = str(e)
            e = e.split("No coordinate is specified for ")[1]  # 获取不支持的城市名称
            info.pop(e)
        else:
            break
    info = sorted(info.items(), key=lambda x: x[1], reverse=False)  # list排序
    # print(info)
    info = dict(info)   #list转dict
    # print(info)
    attr, val = [], []
    for key in info:
        attr.append(key)
        val.append(info[key])


    geo1 = Geo("", "评论城市分布", title_pos="center", width=1200, height=600,
              background_color='#404a59', title_color="#fff")
    geo1.add("", attr, val, visual_range=[0, 300], visual_text_color="#fff", is_geo_effect_show=False,
            is_piecewise=True, visual_split_number=10, symbol_size=15, is_visualmap=True, is_more_utils=True)
    #geo1.render(csv_file + "_城市dotmap.html")
    page.add_chart(geo1)
    geo2 = Geo("", "评论来源热力图",title_pos="center", width=1200,height=600, background_color='#404a59', title_color="#fff",)
    geo2.add("", attr, val, type="heatmap", is_visualmap=True, visual_range=[0, 50],visual_text_color='#fff', is_more_utils=True)
    #geo2.render(csv_file+"_城市heatmap.html")  # 取CSV文件名的前8位数
    page.add_chart(geo2)
    bar = Bar("", "评论来源排行", title_pos="center", width=1200, height=600 )
    bar.add("", attr, val, is_visualmap=True, visual_range=[0, 100], visual_text_color='#fff',mark_point=["average"],mark_line=["average"],
            is_more_utils=True, is_label_show=True, is_datazoom_show=True, xaxis_rotate=45)
    #bar.render(csv_file+"_城市评论bar.html")  # 取CSV文件名的前8位数
    page.add_chart(bar)
    pie = Pie("", "评论来源饼图", title_pos="right", width=1200, height=600)
    pie.add("", attr, val, radius=[20, 50], label_text_color=None, is_label_show=True, legend_orient='vertical', is_more_utils=True, legend_pos='left')
    #pie.render(csv_file + "_城市评论Pie.html")  # 取CSV文件名的前8位数
    page.add_chart(pie)
    page.render(csv_file + "_城市评论分析汇总.html")
Beispiel #6
0
def test_pie_type_radius():
    pie = Pie("饼图示例", title_pos='center', width=1000, height=600)
    pie.add("", ['A', 'B', 'C', 'D', 'E', 'F'], [335, 321, 234, 135, 251, 148],
            radius=[40, 55], is_label_show=True)
    pie.add("", ['H', 'I', 'J'], [335, 679, 204], radius=[0, 30],
            legend_orient='vertical', legend_pos='left')
    pie.render()
Beispiel #7
0
def test_pie_type_rose():
    v1 = [11, 12, 13, 10, 10, 10]
    v2 = [19, 21, 32, 20, 20, 33]
    pie = Pie("饼图-玫瑰图示例", title_pos="center", width=900)
    pie.add(
        "商品A",
        CLOTHES,
        v1,
        center=[25, 50],
        is_random=True,
        radius=[30, 75],
        rosetype="radius",
    )
    pie.add(
        "商品B",
        CLOTHES,
        v2,
        center=[75, 50],
        is_random=True,
        radius=[30, 75],
        rosetype="area",
        is_legend_show=False,
        is_label_show=True,
    )
    pie.render()
Beispiel #8
0
def test_pie_type_radius():
    pie = Pie("饼图示例", title_pos="center", width=1000, height=600)
    pie.add(
        "",
        ["A", "B", "C", "D", "E", "F"],
        [335, 321, 234, 135, 251, 148],
        radius=[40, 55],
        is_label_show=True,
    )
    pie.add(
        "",
        ["H", "I", "J"],
        [335, 679, 204],
        radius=[0, 30],
        legend_orient="vertical",
        legend_pos="left",
    )
    pie.render()
Beispiel #9
0
def test_pie_multiple_movie():
    pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos="center")
    style = Style()
    pie_style = style.add(
        label_pos="center", is_label_show=True, label_text_color=None
    )

    pie.add(
        "", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24], **pie_style
    )
    pie.add(
        "", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24], **pie_style
    )
    pie.add(
        "",
        ["犯罪", ""],
        [28, 72],
        center=[90, 70],
        radius=[18, 24],
        legend_top="center",
        **pie_style
    )
    pie.render()
Beispiel #10
0
def create_charts():
    page = Page()

    style = Style(width=WIDTH, height=HEIGHT)

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    chart = Pie("饼图示例", **style.init_style)
    chart.add("", attr, v1, is_label_show=True)
    page.add(chart)

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    chart = Pie("饼图-圆环图示例", title_pos='center', **style.init_style)
    chart.add("",
              attr,
              v1,
              radius=[40, 75],
              label_text_color=None,
              is_label_show=True,
              legend_orient='vertical',
              legend_pos='left')
    page.add(chart)

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    v2 = [19, 21, 32, 20, 20, 33]
    chart = Pie("饼图-玫瑰图示例", title_pos='center', **style.init_style)
    chart.add("商品A",
              attr,
              v1,
              center=[25, 50],
              is_random=True,
              radius=[30, 75],
              rosetype='radius')
    chart.add("商品B",
              attr,
              v2,
              center=[75, 50],
              is_random=True,
              radius=[30, 75],
              rosetype='area',
              is_legend_show=False,
              is_label_show=True)
    page.add(chart)

    chart = Pie("饼图示例", title_pos='center', **style.init_style)
    chart.add("", ['A', 'B', 'C', 'D', 'E', 'F'],
              [335, 321, 234, 135, 251, 148],
              radius=[40, 55],
              is_label_show=True)
    chart.add("", ['H', 'I', 'J'], [335, 679, 204],
              radius=[0, 30],
              legend_orient='vertical',
              legend_pos='left')
    page.add(chart)

    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    chart = Pie("饼图示例", **style.init_style)
    chart.add("",
              attr, [random.randint(0, 100) for _ in range(6)],
              radius=[50, 55],
              center=[25, 50],
              is_random=True)
    chart.add("",
              attr, [random.randint(20, 100) for _ in range(6)],
              radius=[0, 45],
              center=[25, 50],
              rosetype='area')
    chart.add("",
              attr, [random.randint(0, 100) for _ in range(6)],
              radius=[50, 55],
              center=[65, 50],
              is_random=True)
    chart.add("",
              attr, [random.randint(20, 100) for _ in range(6)],
              radius=[0, 45],
              center=[65, 50],
              rosetype='radius')
    page.add(chart)

    chart = Pie('各类电影中"好片"所占的比例',
                "数据来着豆瓣",
                title_pos='center',
                **style.init_style)
    chart.add(
        "",
        ["剧情", ""],
        [25, 75],
        center=[10, 30],
        radius=[18, 24],
        label_pos='center',
        is_label_show=True,
        label_text_color=None,
    )
    chart.add("", ["奇幻", ""], [24, 76],
              center=[30, 30],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None,
              legend_pos='left')
    chart.add("", ["爱情", ""], [14, 86],
              center=[50, 30],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["惊悚", ""], [11, 89],
              center=[70, 30],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["冒险", ""], [27, 73],
              center=[90, 30],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["动作", ""], [15, 85],
              center=[10, 70],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["喜剧", ""], [54, 46],
              center=[30, 70],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["科幻", ""], [26, 74],
              center=[50, 70],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["悬疑", ""], [25, 75],
              center=[70, 70],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None)
    chart.add("", ["犯罪", ""], [28, 72],
              center=[90, 70],
              radius=[18, 24],
              label_pos='center',
              is_label_show=True,
              label_text_color=None,
              is_legend_show=True,
              legend_top="center")
    page.add(chart)

    return page
Beispiel #11
0
def fabu_type_mon(conn, width, height, zs_mj, mon):
    sql_fabu_type = "select type,count,mj from kanban_fabu_type where year(date_sub(create_date,interval 1 month))='%s'" \
                    "and month(date_sub(create_date,interval 1 month))='%s'"%(str(mon)[:4],str(mon)[-2:])
    data_fabu_type = pd.read_sql(sql_fabu_type, conn)

    date_fabu_type_count = data_fabu_type.sort_values('count', ascending=False)
    date_fabu_type_mj = data_fabu_type.sort_values('mj', ascending=False)

    fabu_type_name1 = list(date_fabu_type_count.iloc[:, 0])
    fabu_type_count1 = list(date_fabu_type_count.iloc[:, 1])
    fabu_type_name2 = list(date_fabu_type_mj.iloc[:, 0])
    fabu_type_mj2 = list(date_fabu_type_mj.iloc[:, 2])

    if zs_mj == 'zs':
        fabu_type_title1 = str(mon)[:4] + '年' + str(
            mon)[-2:] + '月土流网发布土地类型宗数占比'
        fabu_type_pie1 = Pie(fabu_type_title1,
                             title_pos='center',
                             width=width,
                             height=height)
        fabu_type_pie1.add("",
                           fabu_type_name1,
                           fabu_type_count1,
                           rosetype='radius',
                           radius=[25, 50],
                           label_text_color=None,
                           is_label_show=True,
                           is_legend_show=False,
                           legend_orient='vertical',
                           legend_pos='left')
        fabu_type_pie1.render()
        return fabu_type_pie1

    elif zs_mj == 'mj':
        fabu_type_title2 = str(mon)[:4] + '年' + str(
            mon)[-2:] + '月土流网发布土地类型面积占比'
        fabu_type_pie2 = Pie(fabu_type_title2,
                             title_pos='center',
                             width=width,
                             height=height)
        fabu_type_pie2.add("",
                           fabu_type_name2,
                           fabu_type_mj2,
                           rosetype='radius',
                           radius=[25, 50],
                           label_text_color=None,
                           is_label_show=True,
                           is_legend_show=False,
                           legend_orient='vertical',
                           legend_pos='left')
        fabu_type_pie2.render()
        return fabu_type_pie2
Beispiel #12
0
def analyse_touxiang_data():
    # 导入腾讯优图,用来实现人脸检测等功能  https://open.youtu.qq.com
    import TencentYoutuyun
    from pyecharts import Pie
    # 导入jieba模块,用于中文分词
    import jieba
    # 导入matplotlib,用于生成2D图形
    import matplotlib.pyplot as plt
    # 导入wordcount,用于制作词云图
    from wordcloud import WordCloud, STOPWORDS
    # 向腾讯优图平台申请的开发密钥,此处需要替换为自己的密钥
    appid = "----"
    secret_id = "----"
    secret_key = "----"
    userid = "----" # 你的qq号

    end_point = TencentYoutuyun.conf.API_YOUTU_END_POINT  # 优图开放平台
    youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point)

    use_face_man = 0
    use_face_woman = 0
    not_use_face = 0

    base_path = current_dir+'/headImages'
    tag_tpyes = [] # 分词
    for file_name in os.listdir(base_path):
        result = youtu.DetectFace(os.path.join(base_path, file_name))  # 人脸检测与分析
        # print(result)  # 参考 https://open.youtu.qq.com/legency/#/develop/api-face-analysis-detect
        # 判断是否使用人像
        gender=""
        age=0
        beauty=0
        glasses=""
        if result['errorcode'] == 0:  # errorcode为0表示图片中存在人像
            gender = '男' if result['face'][0]['gender'] >= 50 else '女'
            if gender=="男":
                use_face_man+=1
            else:
                use_face_woman+= 1

            age = result['face'][0]['age']
            beauty = result['face'][0]['beauty']  # 魅力值
            glasses = '不戴眼镜 ' if result['face'][0]['glasses'] == 0 else '戴眼镜'
        else:
            not_use_face += 1

        tag_name=""
        result_type = youtu.imagetag(os.path.join(base_path, file_name))  # 头像分类
        if result_type['errorcode'] == 0 and len(result_type["tags"])>0:
            tag_name=max(result_type["tags"], key=lambda item: item['tag_confidence']) ["tag_name"].encode('ISO-8859-1').decode("utf8")
            tag_tpyes.append(tag_name)

        with open(current_dir+'/header.txt', mode='a', encoding='utf-8') as f:
            f.write('%s,%s,%d,%d,%s,%s\n' % (file_name[:-4], gender, age, beauty, glasses,tag_name))

    attr = ['使用人脸头像-男','使用人脸头像-女', '未使用人脸头像']
    value = [use_face_man,use_face_woman, not_use_face]
    pie = Pie('好友头像分析', '', title_pos='center')
    pie.add('', attr, value, radius=[30, 75], is_label_show=True,
            is_legend_show=True, legend_top='bottom')
    # pie.show_config()
    pie.render(current_dir+'/好友头像分析.html')

    # 设置分词
    split = jieba.cut(str(tag_tpyes), cut_all=False)  # False精准模式分词、True全模式分词
    words = ' '.join(split)  # 以空格进行拼接

    # 导入背景图
    bg_image = plt.imread(current_dir+'/010-wechat-bg.jpg')

    # 设置词云参数,参数分别表示:画布宽高、背景颜色、背景图形状、字体、屏蔽词、最大词的字体大小
    wc = WordCloud(width=1024, height=768, background_color='white', mask=bg_image, font_path='STKAITI.TTF',
                max_font_size=400, random_state=50)
    # 将分词后数据传入云图
    wc.generate_from_text(words)
    plt.imshow(wc)  # 绘制图像
    plt.axis('off')  # 不显示坐标轴
    # 保存结果到本地
    wc.to_file(current_dir+'/头像类别.jpg')
Beispiel #13
0
# 训练数据
prediction = gmm.predict(data_new)
# print(prediction)

hero_data.insert(0, '分组', prediction)
hero_data.to_csv('hero_out.csv', index=False, sep=',', encoding='gb18030')


df = hero_data[['分组', '名称']]

grouped = df.groupby(['分组'])
k = []
for name, group in grouped:
    k.append({name: list(group['名称'].values)})

kk = []
for i in k:
    for k, v in i.items():
        kk.append(v)

length = []
key = []
for i in kk:
    key.append(str(i))
    length.append(len(i))
pie = Pie('英雄完全属性分类图', title_pos='center')
pie.add("", key, length,
        is_label_show=True, legend_pos="bottom", legend_orient="vertical",)
pie.render()
Beispiel #14
0
def graphpage(labels,mode_combo,startdate,enddate,optInterval,width1, height1):
    #optInterval='D/W/M' labels

    startdate = startdate.replace("/","-")#convert to tushare readable date
    enddate = enddate.replace("/","-")

    page = Page()

    for label in labels:  # generate numbers of graphs according to numbers of queries in treewidget
        label1 = re.split("-", label)
        overlap = Overlap()

        if label1[2]!="分笔" and label1[2]!="季度饼图": #"K线" "复权" "历史分钟"
            if mode_combo == "复权":
            #if optInterval == "qfq" or optInterval == "hfq":#复权
                array = ts.get_h_data(label1[1], start=startdate, end=enddate, autype="qfq")
                array = array.sort_index()
                time = array.index.format()  # 日期正是index
            elif mode_combo == "K线":
            #elif optInterval.isalnum() :#历史K线
                array = ts.get_k_data(label1[1], start=startdate, end=enddate, ktype=optInterval)
                time = array['date'].tolist()  # array.date
            elif mode_combo == "历史分钟":
                array_bfr = ts.get_tick_data(label1[1], date=startdate)
                array_bfr.sort_values("time")
                a = startdate + " " + array_bfr["time"]
                array_bfr["time"] = a
                array_bfr["time"] = pd.to_datetime(a)
                array_bfr = array_bfr.set_index("time")
                if label1[2] != "Volume" and label1[2] != "Amount":
                    price_df = array_bfr["price"].resample(optInterval).ohlc()  # resample重新取样,选出ohlc=open/high/low,提取除价格之外另外4列.close,tushare是ohcl
                    price_df = price_df.dropna()
                    array = price_df
                    time = price_df.index.format()

                elif label1[2] == "Volume":
                    vols = array_bfr["volume"].resample(optInterval).sum()  #resample重新取样,累加间隔内数值 relevant data processing algorithm taken from Jimmy, Creator of Tushare
                    vols = vols.dropna()
                    vol_df = pd.DataFrame(vols, columns=["volume"])
                    array = vol_df
                    time = vol_df.index.format()
                else:
                    amounts = array_bfr["amount"].resample(optInterval).sum()
                    amounts = amounts.dropna()
                    amount_df = pd.DataFrame(amounts, columns=["amount"])
                    array = amount_df
                    time = amount_df.index.format()

            #绘图方法

            if label1[2] == 'Kline':
                re_array = array[['open', 'close', 'high', 'low']]
                data_li = list(row.tolist() for index, row in re_array.iterrows())  # data_list = list(re_array.as_matrix())
                close = array['close'].tolist()
                kline = Kline(label1[0] + "-" + optInterval, width=width1*10/11, height = (height1*10/11) / len(labels))
                kline.add(label1[0], time, data_li, is_datazoom_show=True, datazoom_type="slider", yaxis_interval=1)
                overlap.add(kline)

                if len(close) > 10:
                    ma10 = calculateMa(close, 10)
                    line1 = Line(title_color="#C0C0C0")
                    line1.add(label1[0] + "-" + "MA10", time, ma10)
                    overlap.add(line1)
                if len(close) > 20:
                    ma20 = calculateMa(close, 20)
                    line2 = Line(title_color="#C0C0C0")
                    line2.add(label1[0] + "-" + "MA20", time, ma20)
                    overlap.add(line2)
                if len(close) > 30:
                    ma30 = calculateMa(close, 30)
                    line3 = Line(title_color="#C0C0C0")
                    line3.add(label1[0] + "-" + "MA30", time, ma30)
                    overlap.add(line3)

                page.add(overlap)
            else:#When label1[2]==open/close/volume
                if label1[2] == 'Open':
                    list_aft = array['open'].tolist()
                elif label1[2] == 'Close':
                    list_aft = close
                elif label1[2] == 'High':
                    list_aft = array['high'].tolist()
                elif label1[2] == 'Low':
                    list_aft = array['low'].tolist()
                elif label1[2] == 'Volume':#volume
                    list_aft = array['volume'].tolist()
                else:#amount
                    list_aft = array['amount'].tolist()

                line = Line(label1[0] + "-" + label1[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(labels))
                line.add(label1[0] + "-" + label1[2], time, list_aft, is_datazoom_show=True, yaxis_max="dataMax",
                         yaxis_min="dataMin", datazoom_type="slider")
                overlap.add(line)
                page.add(overlap)


        elif label1[2]=="分笔":
            array = ts.get_tick_data(label1[1], date=startdate)
            array = array.sort_values("time")
            date = array["time"].tolist()
            amount = array["amount"].tolist()
            atype = array["type"].tolist()
            price = array["price"].tolist()
            flag = ["bar" for i in date]
            for idx, val in enumerate(atype):
                if val == "卖盘":
                    amount[idx] = -amount[idx]
                if val == "中性盘":
                    amount[idx] = 0

            returnarray = list(zip(date, amount, flag, price))

            form = [e[1] for e in returnarray]
            time = [d[0] for d in returnarray]

            bar = Bar(label1[0] + "-" + label1[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(labels))
            bar.add(label1[0] + "-" + label1[2], time, form, is_datazoom_show=True, datazoom_type="slider", yaxis_min="dataMin", yaxis_max="dataMax")
            overlap.add(bar)

            line = Line(label1[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(labels))
            price = [e[3] for e in returnarray]
            line.add(label1[0] + "price", time, price, yaxis_min="dataMin", yaxis_max="dataMax", is_datazoom_show=True,
                     datazoom_type="slider",
                     yaxis_type="value")
            overlap.add(line, yaxis_index=1, is_add_yaxis=True)
            page.add(overlap)
        elif label1[2]=="季度饼图":
            datestr = startdate.split("-")
            thisyear = datestr[0]
            df2 = ts.top10_holders(code=label1[1], gdtype="1")
            test = df2[1]["quarter"].tolist()
            df_ready = df2[1]
            idxlist = []
            for idx, val in enumerate(test):
                a = val.split("-")
                if a[0] == thisyear:
                    # print a[0],idx
                    idxlist.append(idx)
            thing = df_ready.loc[idxlist]
            thing = thing.sort_values(["quarter", "name"])
            # print a[0],id
            name = thing["name"].tolist()
            value = thing["hold"].tolist()
            quarter = thing["quarter"].tolist()
            namearray = [name[i:i + 10] for i in range(0, len(name), 10)]
            valuearray = [value[j:j + 10] for j in range(0, len(value), 10)]
            quarterarray = [quarter[k:k + 10] for k in range(0, len(quarter), 10)]

            flag = ["pie" for i in namearray]
            num = [len(value) for k in namearray]
            returnarray = list(zip(namearray, valuearray, quarterarray, flag, num))

            timeline = Timeline(is_auto_play=False, timeline_bottom=0)  # zip(namearray,valuearray,quarter,flag,num)
            namearray = [c[0] for c in returnarray]
            valuearray = [d[1] for d in returnarray]
            quarter = [e[2] for e in returnarray]
            num = returnarray[0][4]

            for x in range(0, int(num / 10)):
                list1 = valuearray[x]
                names = namearray[x]
                quarters = quarter[x][0]

                for idx, val in enumerate(list1):
                    list1[idx] = float(val)

                pie = Pie(label1[0] + "-" + "前十股东", width=width1 * 10 / 11, height=(height1 * 10 / 11))

                pie.add(label1[0] + "-" + "前十股东", names, list1, radius=[30, 55], is_legend_show=False,
                        is_label_show=True, label_formatter="{b}: {c}\n{d}%")
                timeline.add(pie, quarters)
                # namearray = [y for y in namearray[x]]
            timeline.render()

    page.render()
Beispiel #15
0
def test_timeline_pie():
    style = Style()
    pie_style = style.add(
        is_label_show=True,
        radius=[30, 55],
        rosetype="radius"
    )
    pie_1 = Pie("2012 年销量比例", "数据纯属虚构")
    pie_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_2 = Pie("2013 年销量比例", "数据纯属虚构")
    pie_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_3 = Pie("2014 年销量比例", "数据纯属虚构")
    pie_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_4 = Pie("2015 年销量比例", "数据纯属虚构")
    pie_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_5 = Pie("2016 年销量比例", "数据纯属虚构")
    pie_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    timeline = Timeline(is_auto_play=True, timeline_bottom=0,
                        width=1200, height=600)
    timeline.add(pie_1, '2012 年')
    timeline.add(pie_2, '2013 年')
    timeline.add(pie_3, '2014 年')
    timeline.add(pie_4, '2015 年')
    timeline.add(pie_5, '2016 年')
    timeline.render()
Beispiel #16
0
         data3,
         mark_point=['average'],
         is_datazoom_show=False,
         is_label_show=True)
# line.add("最低气温", cities, data2, mark_line=['average'], is_smooth=True)
# line.render('Line-High-Low.html')
line.render(path='折线图.gif')

# 仪表盘图
gu = Gauge("仪表盘图")
gu.add("指标", "达标", 85)
gu.render("Guage-eg.html")

# 导入饼图Pie
# 设置主标题与副标题,标题设置居中,设置宽度为900
pie = Pie("饼状图", "一年的降水量与蒸发量", title_pos='center', width=900)
# 加入数据,设置坐标位置为【25,50】,上方的colums选项取消显示
pie.add("降水量", columns, data1, center=[25, 50], is_legend_show=True)
# 加入数据,设置坐标位置为【75,50】,上方的colums选项取消显示,显示label标签
pie.add("蒸发量",
        columns,
        data2,
        center=[75, 50],
        is_legend_show=False,
        is_label_show=True)
# 保存图表
pie.render("pie.html")

# 漏斗图+图片
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
value = [20, 40, 60, 80, 100, 120]
Beispiel #17
0
def business(id=None):
    values = defaultdict()
    db_server = db_idc.idc_servers
    db_idc_id = db_idc.idc_id
    db_project = db_op.project_list
    db_third = db_idc.third_resource
    db_business = db_op.business
    db_project_third = db_op.project_third
    db_project_other = db_op.project_other
    business_info = [('项目', '域名', '业务', '业务描述', '联系人', '联系方式')]
    bar = None
    busi_tables = ('日期', 'PV访问量', '平均响应时间', '4xx错误占比', '5xx错误占比')
    busi_counts = OrderedDict()
    try:
        if id:
            #获取业务信息
            try:
                key = 'op_business_counts_tmp'
                business_id = db_business.query.with_entities(
                    db_business.id, db_business.business, db_business.describe,
                    db_business.person, db_business.contact).all()
                business_id = {
                    id: [business, describe, person, contact]
                    for id, business, describe, person, contact in business_id
                }
                business = business_id[int(id)]
            except Exception as e:
                logging.error(e)
            #获取项目信息
            business_values = db_project.query.with_entities(
                distinct(db_project.project)).filter(
                    db_project.business_id == int(id)).all()
            other_values = db_project_other.query.with_entities(
                distinct(db_project_other.project)).filter(
                    db_project_other.business_id == int(id)).all()
            if business_values:
                projects = [project[0] for project in business_values]
                #合并信息
                try:
                    for project in projects:
                        domain = db_project.query.with_entities(
                            distinct(db_project.domain)).filter(
                                db_project.project == project).all()
                        if domain:
                            domain = domain[0][0]
                        else:
                            domain = 'None'
                        project = [project, domain]
                        project.extend(business)
                        business_info.append(project)
                except Exception as e:
                    logging.error(e)
                try:
                    for project in projects:
                        #获取自有项目信息
                        project_val = db_project.query.with_entities(
                            db_project.resource,
                            func.count(db_project.id)).filter(
                                db_project.project == project).group_by(
                                    db_project.resource).all()
                        if project_val:
                            for val in project_val:
                                Redis.hincrby(key, val[0], int(val[1]))
                        #获取第三方项目信息
                        project_third = db_project_third.query.with_entities(
                            db_project_third.third_id,
                            func.count(distinct(db_project_third.third_id))
                        ).filter(db_project_third.project == project).group_by(
                            db_project_third.third_id).all()
                        if project_third:
                            project_third = [
                                list(val) for val in project_third
                            ]
                            for i, val in enumerate(project_third):
                                vals = db_third.query.with_entities(
                                    db_third.resource_type).filter(
                                        db_third.id == val[0]).all()
                                if vals:
                                    project_third[i][0] = vals[0][0]
                            for vals in project_third:
                                Redis.hincrby(key, str(vals[0]), int(vals[1]))
                except Exception as e:
                    logging.error(e)
                try:
                    apps_vals = Redis.hgetall(key)
                    apps_vals = sorted(apps_vals.items(),
                                       key=lambda item: int(item[1]),
                                       reverse=True)
                    pie_vals = [val[0] for val in apps_vals]
                    pie_counts = [val[1] for val in apps_vals]
                    pie = Pie(width='100%', height='100%')
                    pie.add("",
                            pie_vals,
                            pie_counts,
                            radius=[35, 75],
                            is_yaxislabel_align=True,
                            legend_orient='vertical',
                            legend_pos='left',
                            is_toolbox_show=False,
                            is_label_show=True,
                            rosetype='area')
                    values['app'] = pie
                    Redis.delete(key)
                    values['app_lists'] = apps_vals
                except Exception as e:
                    logging.error(e)
                #统计机房信息和服务器数量
                try:
                    idcs = db_idc_id.query.with_entities(
                        db_idc_id.id, db_idc_id.aid).all()
                    idcs = {int(val[0]): val[1] for val in idcs}
                    ids = db_project_third.query.with_entities(
                        db_project_third.third_id).filter(
                            db_project_third.project.in_(
                                tuple(projects))).all()
                    third_ids = [id[0] for id in ids]
                    self_ips = db_project.query.with_entities(
                        distinct(db_project.ip)).filter(
                            db_project.project.in_(tuple(projects))).all()
                    self_ips = [ip[0] for ip in self_ips]
                    third_ips = db_third.query.with_entities(
                        distinct(db_third.ip)).filter(
                            db_third.id.in_(tuple(third_ids))).all()
                    third_ips = [ip[0] for ip in third_ips]
                    idc_vals = db_server.query.with_entities(
                        db_server.idc_id, func.count(db_server.idc_id)).filter(
                            db_server.ip.in_(tuple(self_ips +
                                                   third_ips))).group_by(
                                                       db_server.idc_id).all()
                    idc_vals = [list(val) for val in idc_vals]
                    for val in idc_vals:
                        val[0] = idcs[int(val[0])]
                    for val in idc_vals:
                        Redis.hincrby(key, val[0], val[1])
                    idc_vals = Redis.hgetall(key)
                    pie_idc = Pie(width='100%', height='100%')
                except Exception as e:
                    logging.error(e)
                if idc_vals:
                    try:
                        idc_vals = sorted(idc_vals.items(),
                                          key=lambda item: int(item[1]),
                                          reverse=True)
                        total_vals = reduce(
                            lambda x, y: x + y,
                            [int(vals[1]) for vals in idc_vals])
                        pie_vals = [val[0] for val in idc_vals]
                        pie_counts = [val[1] for val in idc_vals]
                        pie_idc.add("",
                                    pie_vals,
                                    pie_counts,
                                    radius=[35, 75],
                                    is_yaxislabel_align=True,
                                    legend_orient='vertical',
                                    legend_pos='left',
                                    is_toolbox_show=False,
                                    is_label_show=True,
                                    rosetype='area')
                        Redis.delete(key)
                        idc_vals.append(['总计:', total_vals])
                    except Exception as e:
                        logging.error(e)
                values['idc'] = pie_idc
                values['idc_lists'] = idc_vals
                #获取业务相关性能数据
                try:
                    hosts = []
                    dt = datetime.datetime.now()
                    host_vals = [
                        infos[1].split(',') for infos in business_info[1:]
                    ]
                    for vals in host_vals:
                        for val in vals:
                            hosts.append(val)
                except Exception as e:
                    logging.error(e)
                year = time.strftime('%Y', time.localtime())
                for i in range(2, 7):
                    info = []
                    ot = dt - datetime.timedelta(days=i - 1)
                    nt = dt - datetime.timedelta(days=i - 2)
                    ot = ot.strftime('%Y-%m-%dT00:00:00Z')
                    nt = nt.strftime('%Y-%m-%dT00:00:00Z')
                    try:
                        pv_sum = [
                            0,
                        ]
                        for host in hosts:
                            cmd = 'select sum(mean_pv) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s' and host = '%s';" % (
                                ot, nt, host)
                            result = Influx_cli.query(cmd)
                            if result:
                                for infos in result.get_points():
                                    infos = infos
                                    if infos:
                                        pv_sum.append(infos['sum'] * 60)
                        if pv_sum:
                            pv_sum = reduce(lambda x, y: x + y, pv_sum)
                        else:
                            pv_sum = 0.0
                        info.append(int(pv_sum))
                    except Exception as e:
                        logging.error(e)
                    try:
                        avg_resp = [
                            0,
                        ]
                        for host in hosts:
                            cmd = 'select mean(mean_avg_resp) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s'and host = '%s';" % (
                                ot, nt, host)
                            result = Influx_cli.query(cmd)
                            if result:
                                for infos in result.get_points():
                                    infos = infos
                                if infos:
                                    avg_resp.append(infos['mean'])
                        if avg_resp:
                            avg_resp = reduce(lambda x, y: x + y, avg_resp)
                        else:
                            avg_resp = 0.0
                        info.append('%.3f' % avg_resp + 's')
                    except Exception as e:
                        logging.error(e)
                    try:
                        s4 = [
                            0,
                        ]
                        for host in hosts:
                            cmd = 'select sum(mean_status_4xx) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s' and host = '%s';" % (
                                ot, nt, host)
                            result = Influx_cli.query(cmd)
                            if result:
                                for infos in result.get_points():
                                    infos = infos
                                if infos:
                                    s4.append(infos['sum'] * 60 / pv_sum)
                        if s4:
                            s4 = reduce(lambda x, y: x + y, s4) * 100
                        else:
                            s4 = 0.0
                        info.append('%.3f' % s4 + '%')
                        s5 = [
                            0,
                        ]
                        for host in hosts:
                            cmd = 'select sum(mean_status_5xx) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s' and host = '%s';" % (
                                ot, nt, host)
                            result = Influx_cli.query(cmd)
                            if result:
                                for infos in result.get_points():
                                    infos = infos
                                if infos:
                                    s5.append(infos['sum'] * 60 / pv_sum)
                        if s5:
                            s5 = reduce(lambda x, y: x + y, s5) * 100
                        else:
                            s5 = 0.0
                        info.append('%.3f' % s5 + '%')
                    except Exception as e:
                        logging.error(e)
                    busi_counts[ot.split('T')[0]] = info
            if other_values:
                for val in other_values:
                    jar_vals = [val[0], '']
                    jar_vals.extend(business)
                    business_info.append(jar_vals)
        else:
            #获取业务列表
            VALS = db_business.query.with_entities(
                db_business.id, db_business.business,
                db_business.describe).order_by(db_business.id).all()
            vals = {val[0]: val for val in VALS}
            busi_vals = {val[0]: val[1] for val in VALS}
            #获取各业务使用web应用实例数量
            web_vals = db_project.query.with_entities(
                db_project.business_id,
                func.count(db_project.business_id)).filter(
                    and_(
                        db_project.resource.in_(
                            ('php', 'tomcat', 'python', 'java')),
                        db_project.business_id != 0)).group_by(
                            db_project.business_id).order_by(
                                desc(func.count(
                                    db_project.business_id))).all()
            pro_vals = [val[0] for val in web_vals]
            jar_vals = db_project_other.query.with_entities(
                db_project_other.business_id).group_by(
                    db_project_other.business_id).all()
            jar_vals = [val[0] for val in jar_vals]
            for val in jar_vals:
                if val not in pro_vals:
                    pro_vals.append(val)
            values['business'] = [vals[val] for val in pro_vals if val in vals]
            project_vals = [
                busi_vals[val[0]] for val in web_vals if val[0] in busi_vals
            ]
            project_counts = [val[1] for val in web_vals]
            bar = Bar(width='110%', height='250px')
            bar.add("线上业务web应用实例数量",
                    project_vals,
                    project_counts,
                    mark_point=["max", "min"],
                    is_yaxislabel_align=True,
                    is_toolbox_show=False,
                    xaxis_interval=0,
                    xaxis_rotate=30)
    except Exception as e:
        flash(e)
        return render_template('Message.html')
    return render_template('business.html',
                           values=values,
                           id=id,
                           business_info=business_info,
                           bar=bar,
                           busi_counts=busi_counts,
                           busi_tables=busi_tables)
Beispiel #18
0
    def create_charts(self):
        page = Page()
        WIDTH = 1100
        HEIGHT = 550
        style = Style(width=WIDTH, height=HEIGHT)

        X_TIME = [
            '处女座', '摩羯座', '水瓶座', '巨蟹座', '天秤座', '金牛座', '天蝎座', '射手座', '白羊座',
            '双子座', '双鱼座', '狮子座'
        ]

        Y_WEEK = [str(x) for x in range(1998, 2007)]

        RANGE_COLOR = [
            '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
            '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'
        ]
        chart = Bar("10年内各星座住房爱好" + "\n" + "Power by 胡煜", **style.init_style)
        for mystr in list(self.getdata().keys()):
            chart.add(mystr,
                      list(self.getdata()[mystr].keys()),
                      list(self.getdata()[mystr].values()),
                      is_stack=True)
        page.add(chart)
        chart = Bar("10年内各星座住房爱好" + "\n" + "Power by 胡煜", **style.init_style)
        for mystr in list(self.getdata().keys()):
            chart.add(mystr,
                      list(self.getdata()[mystr].keys()),
                      list(self.getdata()[mystr].values()),
                      mark_point=["average"])
        page.add(chart)

        chart = Bar("10年内各星座住房爱好" + "\n" + "Power by 胡煜", **style.init_style)
        for mystr in list(self.getdata().keys()):
            chart.add(mystr,
                      list(self.getdata()[mystr].keys()),
                      list(self.getdata()[mystr].values()),
                      is_convert=True)
        page.add(chart)
        chart = Pie("10年内各星座住房爱好", title_pos='center', **style.init_style)
        for mystr in list(self.getdata().keys()):
            chart.add(mystr,
                      list(self.getdata()[mystr].keys()),
                      list(self.getdata()[mystr].values()),
                      is_random=True,
                      radius=[30, 75],
                      rosetype='area',
                      is_legend_show=False,
                      is_label_show=True)
        page.add(chart)

        data = self.gettotladata()
        chart = Timeline(
            is_auto_play=True,
            timeline_bottom=0,
            width=WIDTH,
            height=HEIGHT,
        )
        for mystr in list(self.getdata().keys()):
            your = str(mystr)
            print(your)
            your = Bar(mystr + "各星座住宿记录数据", "数据真实可靠")
            your.add("",
                     list(self.getdata()[mystr].keys()),
                     list(self.getdata()[mystr].values()),
                     is_legend_show=True)
            chart.add(your, str(mystr) + "年")
        page.add(chart)

        lastdict = {
            '华东': 8347764,
            '中南': 3473591,
            '西北': 1109607,
            '西南': 1105030,
            '华北': 2744619,
            '东北': 1819191
        }
        bar = Bar("全国人民住房信息统计")
        bar.add("区域分类",
                list(lastdict.keys()),
                list(lastdict.values()),
                is_stack=True)
        page.add(bar)
        # infodict = {'江苏': 2399942, '上海': 914870, '湖北': 975236, '山东': 1529117, '江西': 594503, '陕西': 572695, '四川': 665913,
        #             '浙江': 1338150, '北京': 494634, '广西': 193134, '海南': 48342, '辽宁': 750881, '福建': 573289, '湖南': 566187,
        #             '河南': 1119652, '内蒙古': 393545, '天津': 321102, '安徽': 981923, '黑龙江': 580329, '吉林': 457018, '河北': 792687,
        #             '广东': 562808, '重庆': 74491, '山西': 693971, '贵州': 189171, '云南': 142511, '新疆': 145680, '甘肃': 227961,
        #             '青海': 75836, '宁夏': 75110, '西藏': 17526, '澳门': 21805, '香港': 12984, '台湾': 2158}
        # map = Map("全国各地域分布住房信息", width=1200, height=600)
        # map.add("", list(infodict.keys()), list(infodict.values()), maptype='china', is_visualmap=True, visual_text_color='#000')
        # page.add(map)

        # chart = Bar3D("3D 柱状图-默认", **style.init_style)
        # chart.add("你妹", X_TIME, Y_WEEK, [[d[0], d[1], d[2],d[3],d[4],d[5],d[6],d[7],d[8],d[9],d[10],d[11]] for d in data],
        #           is_visualmap=True, visual_range=[0, 70],
        #           visual_range_color=RANGE_COLOR,
        #           grid3d_width=200, grid3d_depth=100)
        # page.add(chart)

        return page
Beispiel #19
0
#! /usr/bin/env python
#coding=utf-8


from pyecharts import Pie

pie = Pie("成功率统计")

attr = ['失败','中断','通过','跳过','未知']
value= [12,22,34,29,16]

pie.add("", attr, value, is_label_show=True)
#pie.render('../html/Pie1.html')
pie.render(path='th.jpeg')
Beispiel #20
0
pie = Pie('饼图', background_color="white", title_text_size=25)
pie.add('',attr,v1,is_label_show = True)


#设置radius参数实现圆环图:radius = [x,y],x是内半径,y是外半径
pie =Pie('圆环图',background_color = 'white',title_pos = 'center')
pie.add('',attr,v1,is_label_show = True,radius=[30, 75],is_legend_show = False)

pie.render()'''

#设置rosetype参数实现南丁格尔图(玫瑰图):
#rosetype有'radius'和'area'两种模式,其中:
#radius通过半径显示数据的大小,扇区圆心角展现数据的百分比;
#area通过半径显示数据的大小,各扇区圆心角相等。
#另外还可以通过设置center参数调整圆心位置(center = [x,y],x为横坐标,y为纵坐标)
'''configure(output_image=True)
pie =Pie('玫瑰图',background_color = 'white')
attr = ['惠州','东莞','广州','深圳','佛山','江门','珠海']
v1 = [12,22,34,29,16,14,18]
pie.add('radius',attr,v1,center = [25,50],radius=[30, 75],rosetype='radius')
pie.add('area',attr,v1,center = [75,50],radius=[30, 75],rosetype='area')
pie.render()'''

configure(output_image=True)
pie = Pie('圆环中的玫瑰图', background_color='white')
attr = ['惠州', '东莞', '广州', '深圳', '佛山', '江门', '珠海']
v1 = [12, 22, 34, 29, 16, 14, 18]
pie.add('', attr, v1, radius=[65, 75], center=[50, 50])
pie.add('', attr, v1, radius=[0, 60], center=[50, 50], rosetype='area')
pie.render()
Beispiel #21
0
def pie(request):
    template = loader.get_template('chart/chart.html')
    attr = ['菜品A', '菜品B', '菜品C', '菜品D', '菜品E', '菜品F']
    pie = Pie("菜品销售占比", width=1400, height=700)
    pie.add("",
            attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55],
            center=[25, 50],
            is_random=True)
    pie.add("",
            attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45],
            center=[25, 50],
            rosetype='area')
    pie.add("",
            attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55],
            center=[65, 50],
            is_random=True)
    pie.add("",
            attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45],
            center=[65, 50],
            rosetype='radius')
    context = dict(myechart=pie.render_embed(),
                   host=REMOTE_HOST,
                   script_list=pie.get_js_dependencies())
    return HttpResponse(template.render(context, request))
Beispiel #22
0
# -*-coding:utf-8-*-

from pyecharts import Bar, Pie, Line
from HouseSpider.mysqlpipelines.sql import Sql

attr = ["工业园区", "吴中", "吴江", "高新区", "姑苏", "相城"]

min_price = []
max_price = []
# line = Line("房租分析折线图")

for i in range(6):
    min_price.append(Sql.select_min_price(attr[i]))  # 最小房租
    max_price.append(Sql.select_max_price(attr[i]))  # 最大房租

# line.add("最低房租", attr, min_price, mark_point=["average"])
# line.add("商最房租", attr, max_price, is_smooth=True, mark_line=["max", "average"])
#
# line.render()

pie = Pie("饼图示例")
pie.add("", attr, min_price, is_label_show=True)
pie.render()
Beispiel #23
0
def test_pie_multiple():
    import random

    attr = ["A", "B", "C", "D", "E", "F"]
    pie = Pie("饼图示例", width=1000, height=600)
    pie.add(
        "",
        attr,
        [random.randint(0, 100) for _ in range(6)],
        radius=[50, 55],
        center=[25, 50],
        is_random=True,
    )
    pie.add(
        "",
        attr,
        [random.randint(20, 100) for _ in range(6)],
        radius=[0, 45],
        center=[25, 50],
        rosetype="area",
    )
    pie.add(
        "",
        attr,
        [random.randint(0, 100) for _ in range(6)],
        radius=[50, 55],
        center=[65, 50],
        is_random=True,
    )
    pie.add(
        "",
        attr,
        [random.randint(20, 100) for _ in range(6)],
        radius=[0, 45],
        center=[65, 50],
        rosetype="radius",
    )
    pie.render()
Beispiel #24
0
#encoding=utf-8
from pyecharts import Pie
attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
v1 = [11, 12, 13, 10, 10, 10]
v2 = [19, 21, 32, 20, 20, 33]
pie = Pie("饼图-玫瑰图示例", title_pos='center', width=900)
pie.add("商品A",
        attr,
        v1,
        center=[25, 50],
        is_random=True,
        radius=[30, 75],
        rosetype='radius')
pie.add("商品B",
        attr,
        v2,
        center=[75, 50],
        is_random=True,
        radius=[30, 75],
        rosetype='area',
        is_legend_show=False,
        is_label_show=True)
pie.show_config()
pie.render()
Beispiel #25
0
def graphpage(items,startdate,enddate,option,width1, height1): #labels:复权ork线or分笔 option:hfq, qfq or 15, 30, D, etc
    page = Page()
    for i in items:#generate numbers of graphs according to numbers of queries in treewidget
        j = re.split("-",i)
        if len(j)==3:
            a = generateline(j[1],j[2],startdate,enddate,option)#stock number, Type, startdate, enddate, 30 or 15 or days
            if a is None:
                continue
            time = [d[0] for d in a]#get time from returned dictionary
            if j[2]!="Kline":

                if len(a[0])==4 and a[0][2]=="bar": #for 分笔data
                    overlap = Overlap()
                    form = [e[1] for e in a]
                    bar = Bar(j[0] + "-" + j[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items))
                    bar.add(j[0] + "-" + j[2], time, form, yaxis_min = "dataMin",yaxis_max = "dataMax",is_datazoom_show = True, datazoom_type = "slider")
                    overlap.add(bar)

                    line = Line(j[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items))
                    price = [e[3] for e in a]
                    line.add(j[0] + "price", time, price, yaxis_min = "dataMin",yaxis_max = "dataMax", is_datazoom_show = True, datazoom_type = "slider",
                            yaxis_type="value")
                    overlap.add(line,yaxis_index=1, is_add_yaxis=True)

                    page.add(overlap)

                if len(a[0])==5 and a[0][3]=="pie":
                    overlap = Overlap()
                    timeline = Timeline(is_auto_play=False, timeline_bottom=0) #zip(namearray,valuearray,quarter,flag,num)
                    namearray = [c[0] for c in a]
                    valuearray = [d[1] for d in a]
                    quarter = [e[2] for e in a]
                    num = a[0][4]

                    for x in range(0, num / 10):
                        list1 = valuearray[x]
                        names = namearray[x]
                        quarters = quarter[x][0]

                        for idx, val in enumerate(list1):
                            list1[idx] = float(val)

                        pie = Pie(j[0]+"-"+"前十股东".decode("utf-8"),width=width1 * 10 / 11, height=(height1 * 10 / 11))

                        pie.add(j[0]+"-"+"前十股东".decode("utf-8"), names, list1, radius=[30, 55], is_legend_show=False,
                                is_label_show=True, label_formatter = "{b}: {c}\n{d}%")
                        # print list
                        # print names
                        # print quarterarray

                        timeline.add(pie, quarters)
                        # namearray = [y for y in namearray[x]]
                    timeline.render()

                    return


                    #need more statement
                else:
                    form = [e[1] for e in a]#for not分笔 data
                    line = Line(j[0] + "-" + j[2], width=width1*10/11, height=(height1*10/11)/len(items))
                    line.add(j[0] + "-" + j[2], time, form, is_datazoom_show=True, datazoom_type="slider",yaxis_min="dataMin",yaxis_max="dataMax")
                    page.add(line)
            else:
                overlap = Overlap()#for k线
                close = zip(*a)[2]
                candle = [[x[1], x[2], x[3], x[4]] for x in a]
                candlestick = Kline(j[0] + "-" + j[2], width=width1*10/11, height = (height1*10/11) / len(items))
                candlestick.add(j[0], time, candle, is_datazoom_show=True, datazoom_type="slider",yaxis_interval = 1)
                overlap.add(candlestick)
                if len(close)>10:
                    ma10 = calculateMa(close, 10)
                    line1 = Line(title_color="#C0C0C0")
                    line1.add(j[0] + "-" + "MA10", time, ma10)
                    overlap.add(line1)
                if len(close)>20:
                    ma20 = calculateMa(close, 20)
                    line2 = Line(title_color="#C0C0C0")
                    line2.add(j[0] + "-" + "MA20", time, ma20)
                    overlap.add(line2)
                if len(close)>30:
                    ma30 = calculateMa(close, 30)
                    line3 = Line(title_color="#C0C0C0")
                    line3.add(j[0] + "-" + "MA30", time, ma30)
                    overlap.add(line3)
                page.add(overlap)
        else:
            for k in range(1, len(j)/3):#if graphs are combined
                j[3*k-1] = re.sub("\n&","",j[3*k-1])
            sizearray=[]
            #if j[1] != "Candlestick"
            layout = Overlap()
            for i in xrange(0, len(j),3):
                array = j[i:i +3]
                b = generateline(array[1],array[2],startdate,enddate,option)
                if b is None:
                    continue
                btime = [d[0] for d in b]
                if array[2] != "Kline":

                    if len(b[0])==4 and b[0][2]=="bar":
                        form = [e[1] for e in b]
                        bar = Bar(array[0] + "-" + array[2], width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items))
                        bar.add(array[0] + "-" + array[2], btime, form, is_datazoom_show=True, datazoom_type="slider",
                                yaxis_min="dataMin", yaxis_max="dataMax")
                        layout.add(bar)
                        line = Line(array[0] + "price", width=width1 * 10 / 11, height=(height1 * 10 / 11) / len(items))
                        price = [e[3] for e in b]
                        line.add(array[0] + "price", btime, price, is_datazoom_show=True, datazoom_type="slider",
                                     yaxis_min="dataMin", yaxis_type="value")
                        layout.add(line, yaxis_index=1, is_add_yaxis=True)




                    else:
                        line = Line(array[0] + "-" + array[2],width=width1*10/11, height=(height1*10/11) / len(items))
                        line.add(array[0]+"-"+array[2], btime, b, is_datazoom_show=True, yaxis_max = "dataMax", yaxis_min = "dataMin",datazoom_type="slider")
                        layout.add(line)
                else:
                    candle = [[x[1], x[2], x[3], x[4]] for x in b]
                    candlestick = Kline(array[0] + "-" + array[1], width=width1*10/11,
                                        height=(height1*10/11) / len(items))
                    candlestick.add(array[0], btime, candle, is_datazoom_show=True, datazoom_type=["slider"])

                    #if i == 0:
                    close = zip(*b)[2]
                    if len(close)>10:
                        ma10 = calculateMa(close, 10)
                        line4 = Line(title_color="#C0C0C0")
                        line4.add(array[0] + "-" + "MA10", btime, ma10)
                        layout.add(line4)
                    if len(close)>20:
                        ma20 = calculateMa(close, 20)
                        line5 = Line(title_color="#C0C0C0")
                        line5.add(array[0] + "-" + "MA20", btime, ma20)
                        layout.add(line5)
                    if len(close)>30:
                        ma30 = calculateMa(close, 30)
                        line6 = Line(title_color="#C0C0C0")
                        line6.add(array[0] + "-" + "MA30", btime, ma30)
                        layout.add(line6)
                    layout.add(candlestick)
            page.add(layout)
    page.render()
def draw_citys_pic(csv_file):
    page = Page(csv_file + ":评论城市分析")
    info = count_city(csv_file)
    geo = Geo("",
              "Ctipsy原创",
              title_pos="center",
              width=1200,
              height=600,
              background_color='#404a59',
              title_color="#fff")
    while True:  # 二次筛选,和pyecharts支持的城市库进行匹配,如果报错则删除该城市对应的统计
        try:
            attr, val = geo.cast(info)
            geo.add("",
                    attr,
                    val,
                    visual_range=[0, 300],
                    visual_text_color="#fff",
                    is_geo_effect_show=False,
                    is_piecewise=True,
                    visual_split_number=6,
                    symbol_size=15,
                    is_visualmap=True)
        except ValueError as e:
            e = str(e)
            e = e.split("No coordinate is specified for ")[1]  # 获取不支持的城市名称
            info.pop(e)
        else:
            break
    info = sorted(info.items(), key=lambda x: x[1], reverse=False)  # list排序
    # print(info)
    info = dict(info)  #list转dict
    # print(info)
    attr, val = [], []
    for key in info:
        attr.append(key)
        val.append(info[key])

    geo1 = Geo("",
               "评论城市分布",
               title_pos="center",
               width=1200,
               height=600,
               background_color='#404a59',
               title_color="#fff")
    geo1.add("",
             attr,
             val,
             visual_range=[0, 300],
             visual_text_color="#fff",
             is_geo_effect_show=False,
             is_piecewise=True,
             visual_split_number=10,
             symbol_size=15,
             is_visualmap=True,
             is_more_utils=True)
    #geo1.render(csv_file + "_城市dotmap.html")
    page.add_chart(geo1)
    geo2 = Geo(
        "",
        "评论来源热力图",
        title_pos="center",
        width=1200,
        height=600,
        background_color='#404a59',
        title_color="#fff",
    )
    geo2.add("",
             attr,
             val,
             type="heatmap",
             is_visualmap=True,
             visual_range=[0, 50],
             visual_text_color='#fff',
             is_more_utils=True)
    #geo2.render(csv_file+"_城市heatmap.html")  # 取CSV文件名的前8位数
    page.add_chart(geo2)
    bar = Bar("", "评论来源排行", title_pos="center", width=1200, height=600)
    bar.add("",
            attr,
            val,
            is_visualmap=True,
            visual_range=[0, 100],
            visual_text_color='#fff',
            mark_point=["average"],
            mark_line=["average"],
            is_more_utils=True,
            is_label_show=True,
            is_datazoom_show=True,
            xaxis_rotate=45)
    #bar.render(csv_file+"_城市评论bar.html")  # 取CSV文件名的前8位数
    page.add_chart(bar)
    pie = Pie("", "评论来源饼图", title_pos="right", width=1200, height=600)
    pie.add("",
            attr,
            val,
            radius=[20, 50],
            label_text_color=None,
            is_label_show=True,
            legend_orient='vertical',
            is_more_utils=True,
            legend_pos='left')
    #pie.render(csv_file + "_城市评论Pie.html")  # 取CSV文件名的前8位数
    page.add_chart(pie)
    page.render(csv_file + "_城市评论分析汇总.html")
Beispiel #27
0
def test_more():
    page = Page()

    # line
    line = Line("折线图示例")
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
    )

    # pie
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    page.add([line, pie])

    # kline
    v1 = [
        [2320.26, 2320.26, 2287.3, 2362.94],
        [2300, 2291.3, 2288.26, 2308.38],
        [2295.35, 2346.5, 2295.35, 2345.92],
        [2347.22, 2358.98, 2337.35, 2363.8],
        [2360.75, 2382.48, 2347.89, 2383.76],
        [2383.43, 2385.42, 2371.23, 2391.82],
        [2377.41, 2419.02, 2369.57, 2421.15],
        [2425.92, 2428.15, 2417.58, 2440.38],
        [2411, 2433.13, 2403.3, 2437.42],
        [2432.68, 2334.48, 2427.7, 2441.73],
        [2430.69, 2418.53, 2394.22, 2433.89],
        [2416.62, 2432.4, 2414.4, 2443.03],
        [2441.91, 2421.56, 2418.43, 2444.8],
        [2420.26, 2382.91, 2373.53, 2427.07],
        [2383.49, 2397.18, 2370.61, 2397.94],
        [2378.82, 2325.95, 2309.17, 2378.82],
        [2322.94, 2314.16, 2308.76, 2330.88],
        [2320.62, 2325.82, 2315.01, 2338.78],
        [2313.74, 2293.34, 2289.89, 2340.71],
        [2297.77, 2313.22, 2292.03, 2324.63],
        [2322.32, 2365.59, 2308.92, 2366.16],
        [2364.54, 2359.51, 2330.86, 2369.65],
        [2332.08, 2273.4, 2259.25, 2333.54],
        [2274.81, 2326.31, 2270.1, 2328.14],
        [2333.61, 2347.18, 2321.6, 2351.44],
        [2340.44, 2324.29, 2304.27, 2352.02],
        [2326.42, 2318.61, 2314.59, 2333.67],
        [2314.68, 2310.59, 2296.58, 2320.96],
        [2309.16, 2286.6, 2264.83, 2333.29],
        [2282.17, 2263.97, 2253.25, 2286.33],
        [2255.77, 2270.28, 2253.31, 2276.22],
    ]
    kline = Kline("K 线图示例")
    kline.add(
        "日K",
        ["2017/7/{}".format(i + 1) for i in range(31)],
        v1,
        is_datazoom_show=True,
    )
    page.add(kline)

    # radar
    schema = [
        ("销售", 6500),
        ("管理", 16000),
        ("信息技术", 30000),
        ("客服", 38000),
        ("研发", 52000),
        ("市场", 25000),
    ]
    v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
    v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
    radar = Radar("雷达图示例")
    radar.config(schema)
    radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True)
    radar.add(
        "实际开销",
        v2,
        label_color=["#4e79a7"],
        is_area_show=False,
        legend_selectedmode="single",
    )
    page.add(radar)

    # scatter3d
    import random

    data = [
        [
            random.randint(0, 100),
            random.randint(0, 100),
            random.randint(0, 100),
        ]
        for _ in range(80)
    ]
    scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600)
    scatter3D.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR)
    page.add(scatter3D)

    # wordcloud
    name = [
        "Sam S Club",
        "Macys",
        "Amy Schumer",
        "Jurassic World",
        "Charter Communications",
        "Chick Fil A",
        "Planet Fitness",
        "Pitch Perfect",
        "Express",
        "Home",
        "Johnny Depp",
        "Lena Dunham",
        "Lewis Hamilton",
        "KXAN",
        "Mary Ellen Mark",
        "Farrah Abraham",
        "Rita Ora",
        "Serena Williams",
        "NCAA baseball tournament",
        "Point Break",
    ]
    value = [
        10000,
        6181,
        4386,
        4055,
        2467,
        2244,
        1898,
        1484,
        1112,
        965,
        847,
        582,
        555,
        550,
        462,
        366,
        360,
        282,
        273,
        265,
    ]
    wordcloud = WordCloud(width=1300, height=620)
    wordcloud.add("", name, value, word_size_range=[30, 100], rotate_step=66)
    page.add(wordcloud)

    # liquid
    liquid = Liquid("水球图示例")
    liquid.add("Liquid", [0.6])
    page.add(liquid)
    assert len(page) == 7
    assert isinstance(page[0], Line)
    assert (
        ("echarts" in page.js_dependencies)
        or ("echarts.min" in page.js_dependencies)
    )
    page.render()
Beispiel #28
0
def analyze():
    biglist = []
    for root, dirs, files, in os.walk(
            "/Users/pony/github/hades/workspace/result/"):
        for file in files:
            if os.path.splitext(file)[1] == '.json':
                filepath = os.path.join(root, file)
                biglist.append(filepath)
    print("共分析%d个文件" % len(biglist))
    bigresultdict = {}
    for filepath in biglist:
        f = open(filepath, 'r')
        data = f.read()
        singledict = json.loads(data)
        bigresultdict[singledict.get('packageName')] = singledict
    shell = analyzeshell(bigresultdict)
    classify = analyzeclassify(bigresultdict)
    per1 = analyzepermission(bigresultdict)
    per2 = analyzepermission2(bigresultdict)
    ad = analyzead(bigresultdict)
    ad2 = analyzead2(bigresultdict)
    nastysdk = analyzenastysdk(bigresultdict)
    nastysdk2 = analyzenastysdk2(bigresultdict)

    pie = Pie("分析样本中的加壳情况", title_pos='center')
    bar1 = Bar("统计应用类型数量", title_pos='center')
    bar2 = Bar("分析哪些应用使用权限最多", title_pos='center')
    pie3 = Pie("分析哪些权限使用最频繁", title_pos='left')
    pie4 = Pie("分析哪些第三方广告使用量最多", title_pos='center')
    bar5 = Bar("分析哪些应用使用广告最多", title_pos='center')
    pie6 = Pie("分析哪些应用使用恶意sdk最多", title_pos='center')
    pie7 = Pie("分析哪些恶意sdk使用量最多", title_pos='center')
    pie.add("apk数量",
            shell.keys(),
            shell.values(),
            is_label_show=True,
            is_more_utils=True,
            legend_pos='left',
            legend_orient='vertical')
    bar1.add("apk数量",
             classify.keys(),
             classify.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='left',
             legend_orient='vertical')
    bar2.add("权限数量",
             per1.keys(),
             per1.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='left',
             legend_orient='vertical')
    pie3.add("apk数量",
             per2.keys(),
             per2.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='bottom',
             legend_orient='vertical')
    pie4.add("apk数量",
             ad.keys(),
             ad.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='left',
             legend_orient='vertical')
    bar5.add("apk数量",
             ad2.keys(),
             ad2.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='left',
             legend_orient='vertical')
    pie6.add("恶意sdk数量",
             nastysdk.keys(),
             nastysdk.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='left',
             legend_orient='vertical')
    pie7.add("恶意sdk数量",
             nastysdk2.keys(),
             nastysdk2.values(),
             is_label_show=True,
             is_more_utils=True,
             legend_pos='left',
             legend_orient='vertical')

    page = Page()
    page.add(pie)
    page.add(bar1)
    page.add(bar2)
    page.add(pie3)
    page.add(pie4)
    page.add(bar5)
    page.add(pie6)
    page.add(pie7)
    page.render("bing2.html")
import pandas as pd
from pyecharts import Pie

df = pd.read_csv('air_tianjin_2017.csv',
                 header=None,
                 names=["Date", "Quality_grade", "AQI", "AQI_rank", "PM"])

rank_message = df.groupby(['Quality_grade'])
rank_com = rank_message['Quality_grade'].agg(['count'])
rank_com.reset_index(inplace=True)
rank_com_last = rank_com.sort_values('count', ascending=False)

attr = rank_com_last['Quality_grade']
v1 = rank_com_last['count']

pie = Pie("2017年天津全年空气质量情况", title_pos='center', title_top=0)
pie.add("",
        attr,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
        legend_top="%10")
pie.render('2017年天津全年空气质量情况.html')
Beispiel #30
0
def weeklyDashboard():
    import jinja2
    loader = jinja2.FileSystemLoader(settings.BASE_DIR +
                                     '/apps/dashboard/docs/',
                                     encoding='utf-8')
    env = jinja2.Environment(loader=loader)
    template = env.get_template("week")
    print('123', connect.keys())
    status_json = connect.get('MANAGER_STATUS')
    manager_status = json.loads(str(status_json, encoding='utf-8'))
    now = datetime.datetime.now().strftime('%Y-%m-%d')
    TMP = settings.DASHBOARD_ROOT + '/' + now
    if not os.path.exists(TMP):
        os.makedirs(TMP)

    dic = {
        'GROUP_COUNT':
        manager_status['group_count'],
        'HOST_COUNT':
        manager_status['host_count'],
        'ALIYUN_COUNT':
        manager_status['position'][0]['value'],
        'VMWARE_COUNT':
        manager_status['position'][1]['value'],
        'MISSION_COUNT':
        OpsModels.Mission.objects.count(),
        'ACTIVITY_USER':
        AuthModels.ExtendUser.objects.count(),
        'WEEK_START': (datetime.datetime.now() -
                       datetime.timedelta(days=7)).strftime("%Y年%m月%d日"),
        'WEEK_END':
        datetime.datetime.now().strftime('%Y年%m月%d日'),
    }

    systype = manager_status['systemtype']
    attr = []
    v1 = []
    for l in systype:
        attr.append(l["name"])
        v1.append(l["value"])
    pie = Pie("操作系统类型", title_pos='right', width=900)
    pie.add("操作系统类型",
            attr,
            v1,
            center=[50, 50],
            is_random=True,
            radius=[30, 75],
            is_legend_show=False,
            is_label_show=True)
    pie.render(path=TMP + '/systype.png')

    groups = manager_status['groups']
    attr = []
    v1 = []
    for l in groups:
        attr.append(l["name"])
        v1.append(l["value"])
    pie = Pie("接管应用与主机总数", title_pos='right', width=900)
    pie.add("接管应用与主机总数",
            attr,
            v1,
            center=[50, 50],
            is_random=True,
            radius=[30, 75],
            is_legend_show=False,
            is_label_show=True)
    pie.render(path=TMP + '/group.png')

    if ExpiredAliyunECS.objects.count() != 0:
        ecsquery = ExpiredAliyunECS.objects.all()
        dic['ECS_EXPIRED'] = ecsquery

    if ExpiredAliyunRDS.objects.count() != 0:
        rdsquery = ExpiredAliyunRDS.objects.all()
        dic['RDS_EXPIRED'] = rdsquery

    if ExpiredAliyunKVStore.objects.count() != 0:
        kvsquery = ExpiredAliyunKVStore.objects.all()
        dic['KVSTORE_EXPIRED'] = kvsquery

    if ExpiredAliyunMongoDB.objects.count() != 0:
        kvsquery = ExpiredAliyunMongoDB.objects.all()
        dic['MONGODB_EXPIRED'] = kvsquery

    markdown = template.render(dic)

    with open(TMP + '/index.md', 'w') as f:
        f.write(markdown)

    #    <link href="../static/github.css" rel="stylesheet">
    html = '''
        <html lang="zh-cn">
        <head>
        <meta content="text/html; charset=utf-8" http-equiv="content-type" />
        <link href="../static/screen.css" rel="stylesheet">
        </head>
        <body>
        %s
        </body>
        </html>
        '''

    import markdown2
    html = html % markdown2.markdown(markdown,
                                     extras=['tables', 'break-on-newline'])

    with open(TMP + '/index.html', 'w') as f:
        f.write(html)

    msg = '本周平台周报地址http://deveops.8531.cn:8888/media/dashboard/' + datetime.datetime.now(
    ).strftime('%Y-%m-%d') + '/index.html'
    smtp.sendMail('devEops平台运维周报', msg,
                  ['*****@*****.**'
                   ])  #,'*****@*****.**','*****@*****.**','*****@*****.**'])
Beispiel #31
0
def jiaoyi_liuzhuan_mon(conn, width, height, zs_mj, mon):
    sql_jiaoyi_liuzhuan = "select liuzhuan,count,mj from kanban_jiaoyi_liuzhuan where year(date_sub(create_date,interval 1 month)) ='%s'" \
                          "and month(date_sub(create_date,interval 1 month))='%s'"%(str(mon)[:4],str(mon)[-2:])
    data_jiaoyi_liuzhuan = pd.read_sql(sql_jiaoyi_liuzhuan, conn)

    data_jiaoyi_liuzhuan_count = data_jiaoyi_liuzhuan.sort_values(
        'count', ascending=False)
    data_jiaoyi_liuzhuan_mj = data_jiaoyi_liuzhuan.sort_values('mj',
                                                               ascending=False)

    jiaoyi_liuzhuan_name1 = list(data_jiaoyi_liuzhuan_count.iloc[:, 0])
    jiaoyi_liuzhuan_count1 = list(data_jiaoyi_liuzhuan_count.iloc[:, 1])
    jiaoyi_liuzhuan_name2 = list(data_jiaoyi_liuzhuan_mj.iloc[:, 0])
    jiaoyi_liuzhuan_mj2 = list(data_jiaoyi_liuzhuan_mj.iloc[:, 2])

    if zs_mj == 'zs':
        jiaoyi_liuzhuan_title1 = str(mon)[:4] + '年' + str(
            mon)[-2:] + '月土流网交易土地流转类型宗数占比'
        jiaoyi_liuzhuan_pie1 = Pie(jiaoyi_liuzhuan_title1,
                                   title_pos='center',
                                   width=width,
                                   height=height)
        jiaoyi_liuzhuan_pie1.add("",
                                 jiaoyi_liuzhuan_name1,
                                 jiaoyi_liuzhuan_count1,
                                 radius=[25, 50],
                                 label_text_color=None,
                                 is_label_show=True,
                                 is_legend_show=False,
                                 legend_orient='vertical',
                                 legend_pos='left')
        jiaoyi_liuzhuan_pie1.render()
        return jiaoyi_liuzhuan_pie1

    elif zs_mj == 'mj':
        jiaoyi_liuzhuan_title2 = str(mon)[:4] + '年' + str(
            mon)[-2:] + '月土流网交易土地流转类型面积占比'
        jiaoyi_liuzhuan_pie2 = Pie(jiaoyi_liuzhuan_title2,
                                   title_pos='center',
                                   width=width,
                                   height=height)
        jiaoyi_liuzhuan_pie2.add("",
                                 jiaoyi_liuzhuan_name2,
                                 jiaoyi_liuzhuan_mj2,
                                 radius=[25, 50],
                                 label_text_color=None,
                                 is_label_show=True,
                                 is_legend_show=False,
                                 legend_orient='vertical',
                                 legend_pos='left')
        jiaoyi_liuzhuan_pie2.render()
        return jiaoyi_liuzhuan_pie2
Beispiel #32
0
 def showPie(self, title, attr, value):
     from pyecharts import Pie
     pie = Pie(title)
     pie.add("aa", attr, value, is_label_show=True)
     pie.render()
Beispiel #33
0
bot = Bot(cache_path=True)  #定义一个微信机器人
friends = bot.friends(update=False)  #获取更新好友列表
male = female = other = 0

for i in friends[1:]:  #[1:]是因为整个好友列表里面自己市在第一个,排除掉
    sex = i.sex
    if sex == 1:
        male += 1
    elif sex == 2:
        female += 1
    else:
        other += 1
total = len(friends[1:])  #计算总数

#下面为分析
attr = ["男性", "女性", "其他"]
v1 = [float(male), float(female), float(other)]
pie = Pie("饼图-圆环图示例", title_pos='center')
pie.add("",
        attr,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient='vertical',
        legend_pos='left')
pie.render("sex.html")

#摘抄:https://www.jianshu.com/p/c0baf3c6db15
# 分析微信好友男女比例
Beispiel #34
0
def DrawPie(lst):
    image=Pie("", width=600, height=450)
    image.add("", lst[0], lst[1], is_label_show=True)
    image.render("./SE12_Cache/Pie.html")
Beispiel #35
0
def zd_fenbu():
    # tushare
    stockbasicinfo = ts.get_stock_basics()
    '''代码排序'''
    stockbasicinfo = stockbasicinfo.sort_index()
    '''股票总数'''
    stocknum = len(stockbasicinfo)
    # stockcode = stockbasicinfo.index[0]

    # 所有票的url拼接地址,用sina api去获取数据,因为tushare获取实时数据不稳定
    urllist = []
    for i in range(0, stocknum):
        stockcode = stockbasicinfo.index[i]
        stockcodeint = int(stockbasicinfo.index[i])
        if stockcodeint >= 600000:
            urllist.append('sh' + str(stockcode))
        else:
            urllist.append('sz' + str(stockcode))
    urllen = len(urllist)
    # print(urllen, urllist)
    (x, y) = divmod(urllen, 9)
    urlchar = ','.join(urllist)
    # print(urlchar)
    # 总共分成9份,因为sina每次请求不超过800
    urlbase = 'http://hq.sinajs.cn/list='
    url1 = urlbase + urlchar[0:9 * x - 1]
    url2 = urlbase + urlchar[9 * x * 1:9 * x * 2 - 1]
    url3 = urlbase + urlchar[9 * x * 2:9 * x * 3 - 1]
    url4 = urlbase + urlchar[9 * x * 3:9 * x * 4 - 1]
    url5 = urlbase + urlchar[9 * x * 4:9 * x * 5 - 1]
    url6 = urlbase + urlchar[9 * x * 5:9 * x * 6 - 1]
    url7 = urlbase + urlchar[9 * x * 6:9 * x * 7 - 1]
    url8 = urlbase + urlchar[9 * x * 7:9 * x * 8 - 1]
    url9 = urlbase + urlchar[9 * x * 8:]
    datatemp1 = requests.get(url1)
    datatemp2 = requests.get(url2)
    datatemp3 = requests.get(url3)
    datatemp4 = requests.get(url4)
    datatemp5 = requests.get(url5)
    datatemp6 = requests.get(url6)
    datatemp7 = requests.get(url7)
    datatemp8 = requests.get(url8)
    datatemp9 = requests.get(url9)
    # 获取的数据进行合并
    urldata = datatemp1.text + datatemp2.text + datatemp3.text + datatemp4.text + datatemp5.text + datatemp6.text + datatemp7.text + datatemp8.text + datatemp9.text
    urlsplit = re.split(r'=', urldata)
    # print(len(urlsplit))
    validnum = 0
    validzflist = []
    validyes10 = 0
    validyes7 = 0
    validyes5 = 0
    validyes3 = 0
    validyes1 = 0
    validyes0 = 0
    valid0 = 0
    validno0 = 0
    validno1 = 0
    validno3 = 0
    validno5 = 0
    validno7 = 0
    validno10 = 0
    # 数据分割,提取,整理
    for i in range(1, len(urlsplit)):
        if len(urlsplit[i]) > 100:
            urldataone = re.split(r',', urlsplit[i])
            yesprice = float(urldataone[2])
            nowprice = float(urldataone[3])
            amount = float(urldataone[9])
            buyonevol = float(urldataone[10])
            sellonevol = float(urldataone[20])
            if amount < 0.1:
                pass
            else:
                if nowprice < 0.1:
                    pass
                else:
                    if yesprice < 0.1:
                        pass
                    else:
                        zdf = int(10000 *
                                  (nowprice / yesprice - 1) + 0.5) / 100
                        if abs(zdf) < 11:
                            validnum += 1
                            validzflist.append(zdf)
                            if zdf >= 9.8 and sellonevol < 0.1:
                                validyes10 += 1
                            if zdf >= 7 and sellonevol > 0.1:
                                validyes7 += 1
                            if 5 <= zdf < 7:
                                validyes5 += 1
                            if 3 <= zdf < 5:
                                validyes3 += 1
                            if 1 <= zdf < 3:
                                validyes1 += 1
                            if 0.0001 <= zdf < 1:
                                validyes0 += 1
                            if abs(zdf) <= 0.0001:
                                valid0 += 1
                            if -1 < zdf < -0.0001:
                                validno0 += 1
                            if -3 < zdf <= -1:
                                validno1 += 1
                            if -5 < zdf <= -3:
                                validno3 += 1
                            if -7 < zdf <= -5:
                                validno5 += 1
                            if zdf <= -7 and buyonevol > 0.1:
                                validno7 += 1
                            if zdf <= -9.8 and buyonevol < 0.1:
                                validno10 += 1
    # 数据整理
    v11 = [
        0, 0, 0, 0, 0, 0, 0, validyes0, validyes1, validyes3, validyes5,
        validyes7, 0
    ]
    v22 = [
        0, validno7, validno5, validno3, validno1, validno0, 0, 0, 0, 0, 0, 0,
        0
    ]
    v00 = [0, 0, 0, 0, 0, 0, valid0, 0, 0, 0, 0, 0, 0]
    vzt = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, validyes10]
    vdt = [validno10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    attr = [
        '-10%', '>-7%', '-7~5%', '-5~3%', '-3~1%', '-1~0%', '0', '0~1%',
        '1~3%', '3~5%', '5~7%', '>7%', '10%'
    ]

    # 调用pyecharts
    title = ' 涨跌分布:↑' + str(validyes0+validyes1+validyes3+validyes5+validyes7+validyes10) +  \
            ' ↓' + str(validno0+validno1+validno3+validno5+validno7+validno10) + '  →' + str(valid0)
    subtitle = '    GZH: 摸鱼大佬'
    # bar
    bar = Bar(title,
              subtitle,
              title_pos=0.1,
              subtitle_text_size=15,
              subtitle_color='#aa8')
    # bar.use_theme("shine")
    bar.add("涨", attr, v11, bar_category_gap=0, mark_point=['max', 'average'])
    bar.add("", attr, vzt, bar_category_gap=0, mark_point=['max'])
    bar.add("平", attr, v00, bar_category_gap=0, mark_point=['max'])
    bar.add("跌", attr, v22, bar_category_gap=0, mark_point=['max', 'average'])
    bar.add("", attr, vdt, bar_category_gap=0, mark_point=['max'])
    # bar_render_path = save_path_zdffb[:-12] + 'bar_tozoom_' + date_zdffb + '.png'
    # bar.render(path=bar_render_path)
    # pie
    attrpie = ['涨', '平', '跌']
    vpie = [
        validyes0 + validyes1 + validyes3 + validyes5 + validyes7 + validyes10,
        valid0,
        validno0 + validno1 + validno3 + validno5 + validno7 + validno10
    ]
    pie = Pie("涨跌饼图", title_pos='center', width=400, height=400)
    pie.add("",
            attrpie,
            vpie,
            radius=[6, 15],
            label_text_color=None,
            is_label_show=True,
            legend_orient='vertical',
            legend_pos='left')
    # pie_render_path = save_path_zdffb[:-12] + 'pie_tozoom_' + date_zdffb + '.png'
    # pie.render(path=pie_render_path)

    # pic_zoom(bar_render_path, save_path_zdffb, 740)
    # print('zdf_distribution done: ' + save_path_zdffb)
    # return bar_render_path
    return bar, pie
Beispiel #36
0
# Author : Троцкий

# 2019-03-06 10:31

from pyecharts import Pie

import sql

attr = ['无情铁手', '宽油', '王刚', '宽水', '劝退', '宽饭', '摊主']

v1 = sql.get_data()

pie = Pie('关键词分布')

pie.add('', attr, v1, is_label_show=True)

pie.render()
Beispiel #37
0
def test_grid():

    # grid_0
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=720, is_grid=True)
    bar.add("商家A", attr, v1, is_stack=True, grid_bottom="60%")
    bar.add("商家B", attr, v2, is_stack=True, grid_bottom="60%")
    line = Line("折线图示例", title_top="50%")
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"])
    line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"],
             mark_line=["average"], legend_top="50%")
    bar.grid(line.get_series(), grid_top="60%")
    bar.show_config()
    bar.render()

    # grid_1
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter(width=1200, is_grid=True)
    scatter.add("散点图示例", v1, v2, grid_left="60%", legend_pos="70%")
    es = EffectScatter()
    es.add("动态散点图示例", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0],
           effect_scale=6, legend_pos="20%")
    scatter.grid(es.get_series(), grid_right="60%")
    scatter.show_config()
    scatter.render()

    # grid_2
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%", is_grid=True)
    bar.add("商家A", attr, v1, is_stack=True, grid_bottom="60%", grid_left="60%")
    bar.add("商家B", attr, v2, is_stack=True, grid_bottom="60%", grid_left="60%", legend_pos="80%")
    line = Line("折线图示例")
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"], mark_line=["average"])
    line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"],
             mark_line=["average"], legend_pos="20%")
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    scatter = Scatter("散点图示例", title_top="50%", title_pos="65%")
    scatter.add("scatter", v1, v2, legend_top="50%", legend_pos="80%")
    es = EffectScatter("动态散点图示例", title_top="50%")
    es.add("es", [11, 11, 15, 13, 12, 13, 10], [1, -2, 2, 5, 3, 2, 0], effect_scale=6,
           legend_top="50%", legend_pos="20%")
    bar.grid(line.get_series(), grid_bottom="60%", grid_right="60%")
    bar.grid(scatter.get_series(), grid_top="60%", grid_left="60%")
    bar.grid(es.get_series(), grid_top="60%", grid_right="60%")
    bar.show_config()
    bar.render()

    # grid_3
    line = Line("折线图示例", width=1200, is_grid=True)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"],
             mark_line=["average"], grid_right="65%")
    line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"],
             mark_line=["average"], legend_pos="20%")
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例", title_pos="45%")
    pie.add("", attr, v1, radius=[30, 55], legend_pos="65%", legend_orient='vertical')
    line.grid(pie.get_series(), grid_left="60%")
    line.show_config()
    line.render()

    # grid_4
    line = Line("折线图示例", width=1200, is_grid=True)
    attr = ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    line.add("最高气温", attr, [11, 11, 15, 13, 12, 13, 10], mark_point=["max", "min"],
             mark_line=["average"], grid_right="60%")
    line.add("最低气温", attr, [1, -2, 2, 5, 3, 2, 0], mark_point=["max", "min"],
             mark_line=["average"], legend_pos="20%", grid_right="60%")
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    value = [20, 40, 60, 80, 100, 120]
    v1 = [[2320.26, 2320.26, 2287.3, 2362.94],
          [2300, 2291.3, 2288.26, 2308.38],
          [2295.35, 2346.5, 2295.35, 2345.92],
          [2347.22, 2358.98, 2337.35, 2363.8],
          [2360.75, 2382.48, 2347.89, 2383.76],
          [2383.43, 2385.42, 2371.23, 2391.82],
          [2377.41, 2419.02, 2369.57, 2421.15],
          [2425.92, 2428.15, 2417.58, 2440.38],
          [2411, 2433.13, 2403.3, 2437.42],
          [2432.68, 2334.48, 2427.7, 2441.73],
          [2430.69, 2418.53, 2394.22, 2433.89],
          [2416.62, 2432.4, 2414.4, 2443.03],
          [2441.91, 2421.56, 2418.43, 2444.8],
          [2420.26, 2382.91, 2373.53, 2427.07],
          [2383.49, 2397.18, 2370.61, 2397.94],
          [2378.82, 2325.95, 2309.17, 2378.82],
          [2322.94, 2314.16, 2308.76, 2330.88],
          [2320.62, 2325.82, 2315.01, 2338.78],
          [2313.74, 2293.34, 2289.89, 2340.71],
          [2297.77, 2313.22, 2292.03, 2324.63],
          [2322.32, 2365.59, 2308.92, 2366.16],
          [2364.54, 2359.51, 2330.86, 2369.65],
          [2332.08, 2273.4, 2259.25, 2333.54],
          [2274.81, 2326.31, 2270.1, 2328.14],
          [2333.61, 2347.18, 2321.6, 2351.44],
          [2340.44, 2324.29, 2304.27, 2352.02],
          [2326.42, 2318.61, 2314.59, 2333.67],
          [2314.68, 2310.59, 2296.58, 2320.96],
          [2309.16, 2286.6, 2264.83, 2333.29],
          [2282.17, 2263.97, 2253.25, 2286.33],
          [2255.77, 2270.28, 2253.31, 2276.22]]
    kline = Kline("K 线图示例", title_pos="60%")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)], v1, legend_pos="80%")
    line.grid(kline.get_series(), grid_left="55%")
    line.show_config()
    line.render()

    # grid_5
    import random
    x_axis = ["12a", "1a", "2a", "3a", "4a", "5a", "6a", "7a", "8a", "9a", "10a", "11a",
              "12p", "1p", "2p", "3p", "4p", "5p", "6p", "7p", "8p", "9p", "10p", "11p"]
    y_aixs = ["Saturday", "Friday", "Thursday", "Wednesday", "Tuesday", "Monday", "Sunday"]
    data = [[i, j, random.randint(0, 50)] for i in range(24) for j in range(7)]
    heatmap = HeatMap("热力图示例", height=700, is_grid=True)
    heatmap.add("热力图直角坐标系", x_axis, y_aixs, data, is_visualmap=True, visual_top="45%",
                visual_text_color="#000", visual_orient='horizontal', grid_bottom="60%")
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", title_top="52%")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True, legend_top="50%")
    heatmap.grid(bar.get_series(), grid_top="60%")
    heatmap.show_config()
    heatmap.render()
Beispiel #38
0
def myechart(request, pk):
    school = get_object_or_404(Food_Struct, pk=pk)
    school2 = get_object_or_404(School, pk=pk)
    nutri_school = get_object_or_404(Nutri_of_Food, pk=pk)
    students = school2.students
    template = loader.get_template("hele/pyecharts.html")
    mypie = Pie("每人日均餐标结构(单位:%)", title_pos="center")
    value = [
        school.rice, school.ganhuo, school.cake, school.egg, school.chicken,
        school.ricenoodle, school.milk, school.beef, school.oil,
        school.vegitable, school.flavor, school.pock
    ]
    attr = [
        "大米", "干货", "糕点", "鸡蛋", "鸡鸭肉", "米粉", "奶制品", "牛肉", "食用油", "蔬菜", "调味品",
        "猪肉"
    ]
    struct_value = []
    for i in value:
        k = roundfunc(i)
        struct_value.append(k)
    total = roundfunc(school.total)
    mypie.add("", attr, value, is_label_show=True, is_legend_show=False)
    mybar = Bar("每人日均食物摄入结构(单位:g)", title_pos="center")
    nutri_value = [
        nutri_school.xuqin, nutri_school.fish, nutri_school.soilbean,
        nutri_school.egg, nutri_school.gushu, nutri_school.milk,
        nutri_school.sault, nutri_school.vigetable, nutri_school.fruit,
        nutri_school.oil
    ]
    standart_value = [50, 50, 40, 50, 350, 200, 5, 400, 250, 30]
    nutri_attr = [
        "畜禽肉", "鱼虾类", "大豆坚果", "蛋类", "谷薯类", "奶制品", "食盐", "蔬菜类", "水果类", "植物油"
    ]
    mybar.add("学生实际值",
              nutri_attr,
              nutri_value,
              is_label_show=True,
              is_legend_show=True,
              legend_top="bottom")
    mybar.add("标准摄入值",
              nutri_attr,
              standart_value,
              is_label_show=True,
              is_legend_show=True,
              legend_top="bottom")
    context = dict(
        school=school,
        town_list=District.objects.all(),
        town=school2.district,
        school_name=school.name.name,
        next_school=next_school(school2.id),
        school_student=students,
        total=total,
        nutr_total=nutri_school.total,
        pie_myecharts=mypie.render_embed(),
        bar_myecharts=mybar.render_embed(),
        host=REMOTE_HOST,
        pie_script_list=mypie.get_js_dependencies(),
        bar_script_list=mybar.get_js_dependencies(),
    )
    return HttpResponse(template.render(context, request))
Beispiel #39
0
def interface_report():
    try:
        Bars = []
        searchs = []
        db_project = db_op.project_list
        db_idcs = db_idc.idc_id
        db_servers = db_idc.idc_servers
        db_project_third = db_op.project_third
        db_third = db_idc.third_resource
        Infos = defaultdict()
        values = OrderedDict()
        dt = datetime.datetime.now()
        #获取域名列表
        hosts = RC_CLUSTER.smembers(
            'api_domain_lists_%s' %
            time.strftime('%Y-%m-%d', time.localtime()))
        hosts = [host for host in hosts]
        if hosts:
            searchs = json.dumps([{
                "id": str(i),
                "text": str(host)
            } for i, host in enumerate(hosts)])
        #获取域名和接口信息
        if 'business_bigdata_select_host' in request.cookies and 'business_bigdata_select_uri' in request.cookies:
            host = request.cookies['business_bigdata_select_host']
            uri = urllib.parse.unquote(
                request.cookies['business_bigdata_select_uri'])
            #获取接口相关的资产信息
            projects = db_project.query.with_entities(
                db_project.ip, db_project.ssh_port,
                db_project.resource).filter(
                    db_project.domain.like('%{0},%'.format(host))).all()
            if projects:
                idc_lists = db_idcs.query.with_entities(
                    db_idcs.id, db_idcs.aid).all()
                idc_lists = {idcs[0]: idcs[-1] for idcs in idc_lists}
                third_lists = db_third.query.with_entities(
                    db_third.id, db_third.resource_type).all()
                third_lists = {third[0]: third[-1] for third in third_lists}
                ips = [val[0] for val in projects]
                resource = projects[0][-1]
                idc_ids = db_servers.query.with_entities(
                    db_servers.idc_id, func.count(db_servers.idc_id)).filter(
                        db_servers.ip.in_(tuple(ips))).group_by(
                            db_servers.idc_id).all()
                if idc_ids:
                    idc_ids = [list(ids) for ids in idc_ids]
                    for ids in idc_ids:
                        ids[0] = idc_lists[ids[0]]
                    RC.delete('idc_incrs')
                    for ids in idc_ids:
                        RC.hincrby('idc_incrs', ids[0], ids[1])
                    idc_ids = RC.hgetall('idc_incrs')
                    idc_attr = [ids for ids in idc_ids]
                    idc_vals = [int(idc_ids[ids]) for ids in idc_ids]
                    pie = Pie("%s台%s服务器机房分布" % (len(set(projects)), resource),
                              width='100%',
                              height='270px',
                              title_pos='center',
                              title_text_size=14)
                    pie.add("",
                            idc_attr,
                            idc_vals,
                            is_label_show=True,
                            is_toolbox_show=False,
                            is_legend_show=False,
                            legend_orient='vertical',
                            legend_pos='left',
                            radius=[0, 65],
                            is_random=True)
                    Infos['pie'] = pie
            project = db_project.query.with_entities(
                db_project.project).filter(
                    db_project.domain.like('%{0},%'.format(host))).all()
            #获取接口相关的应用服务资源
            if project:
                project = project[0][0]
                third_vals = db_project_third.query.with_entities(
                    db_project_third.third_id,
                    func.count(db_project_third.third_id)).filter(
                        db_project_third.project == project).group_by(
                            db_project_third.third_id).all()
                if third_vals:
                    third_vals = [list(val) for val in third_vals]
                    for val in third_vals:
                        val[0] = third_lists[val[0]]
                    RC.delete('third_incrs')
                    for val in third_vals:
                        RC.hincrby('third_incrs', val[0], val[1])
                    third_vals = RC.hgetall('third_incrs')
                    third_vals[resource] = len(projects)
                    third_attr = [val for val in third_vals]
                    third_counts = [int(third_vals[val]) for val in third_vals]
                    pie_third = Pie("应用服务资源分布",
                                    width='100%',
                                    height='270px',
                                    title_pos='center',
                                    title_text_size=14)
                    pie_third.add(
                        "",
                        third_attr,
                        third_counts,
                        is_label_show=True,
                        is_toolbox_show=False,
                        legend_orient='vertical',
                        legend_pos='right',
                        radius=[55, 65],
                        is_random=True,
                        is_legend_show=False,
                    )
                    Infos['pie_third'] = pie_third
            #接口性能数据获取
            year = time.strftime('%Y', time.localtime())
            for i in range(2, 9):
                ot = dt - datetime.timedelta(days=i - 1)
                nt = dt - datetime.timedelta(days=i - 2)
                ot = ot.strftime('%Y-%m-%dT00:00:00Z')
                nt = nt.strftime('%Y-%m-%dT00:00:00Z')
                try:
                    pv_sum = 0.0
                    cmd = 'select sum(mean_pv) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s' and host='%s' and uri = '%s';" % (
                        ot, nt, host, uri)
                    result = Influx_cli.query(cmd)
                    if result:
                        for infos in result.get_points():
                            infos = infos
                        if infos:
                            pv_sum = infos['sum']
                except Exception as e:
                    logging.error(e)
                try:
                    values['avg_resp'] = 0.0
                    cmd = 'select mean(mean_avg_resp) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s'and host='%s' and uri = '%s';" % (
                        ot, nt, host, uri)
                    result = Influx_cli.query(cmd)
                    if result:
                        for infos in result.get_points():
                            infos = infos
                        if infos:
                            values['avg_resp:%s' %
                                   ot.split('T')[0]] = '%.2f' % infos['mean']
                except Exception as e:
                    logging.error(e)
                try:
                    s4 = 0.0
                    cmd = 'select sum(mean_status_4xx) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s' and host='%s' and uri = '%s';" % (
                        ot, nt, host, uri)
                    result = Influx_cli.query(cmd)
                    if result:
                        for infos in result.get_points():
                            infos = infos
                        if infos:
                            s4 = infos['sum']
                    s5 = 0.0
                    cmd = 'select sum(mean_status_5xx) from ' + 'analysis%s' % year + " where time >='%s' and time < '%s' and host='%s' and uri = '%s';" % (
                        ot, nt, host, uri)
                    result = Influx_cli.query(cmd)
                    if result:
                        for infos in result.get_points():
                            infos = infos
                        if infos:
                            s5 = infos['sum']
                    if pv_sum > 0:
                        values['status_sum:%s' % ot.split('T')[0]] = float(
                            '%.2f' % (float(s4 + s5) / pv_sum * 100))
                except Exception as e:
                    logging.error(e)
                values['pv_sum:%s' % ot.split('T')[0]] = int(pv_sum) * 60
            #接口性能展示
            if values:
                #pv总数
                bar_pv = Bar("PV访问量",
                             width='105%',
                             height='270px',
                             title_pos='center',
                             title_text_size=14)
                vals = [(val.split(':')[-1], values[val]) for val in values
                        if 'pv_sum:' in val]
                if vals:
                    bar_vals = [val[0] for val in vals]
                    bar_counts = [val[-1] for val in vals]
                    bar_pv.add('',
                               bar_vals,
                               bar_counts,
                               is_label_show=True,
                               is_toolbox_show=False,
                               legend_orient='vertical',
                               legend_pos='right',
                               xaxis_interval=0,
                               is_random=True)
                    Bars.append(bar_pv)
                #平均响应时间
                line_resp = Line("平均响应时间",
                                 width='105%',
                                 height='270px',
                                 title_pos='center',
                                 title_text_size=14)
                vals = [(val.split(':')[-1], values[val]) for val in values
                        if 'avg_resp:' in val]
                if vals:
                    line_vals = [val[0] for val in vals]
                    line_counts = [val[-1] for val in vals]
                    line_resp.add('',
                                  line_vals,
                                  line_counts,
                                  is_label_show=True,
                                  is_toolbox_show=False,
                                  legend_orient='vertical',
                                  legend_pos='right',
                                  xaxis_interval=0,
                                  yaxis_formatter='s',
                                  is_random=True,
                                  is_smooth=False,
                                  mark_point=["min", "max"])
                    Bars.append(line_resp)
                #错误状态码占比
                line_status = Line("错误码占比",
                                   width='105%',
                                   height='270px',
                                   title_pos='center',
                                   title_text_size=14)
                vals = [(val.split(':')[-1], values[val]) for val in values
                        if 'status_sum:' in val]
                if vals:
                    line_vals = [val[0] for val in vals]
                    line_counts = [val[-1] for val in vals]
                    line_status.add('',
                                    line_vals,
                                    line_counts,
                                    is_fill=True,
                                    is_label_show=True,
                                    is_smooth=False,
                                    is_toolbox_show=False,
                                    legend_orient='vertical',
                                    legend_pos='right',
                                    xaxis_interval=0,
                                    yaxis_formatter='%',
                                    is_random=True,
                                    mark_line=["max", "min"])
                    Bars.append(line_status)
    except Exception as e:
        logging.error(e)
    return render_template('interface_report.html',
                           Bars=Bars,
                           Infos=Infos,
                           searchs=searchs)
Beispiel #40
0
def test_more_charts():
    page = Page()

    # line
    line = Line("折线图示例")
    line.add(
        "最高气温",
        WEEK,
        [11, 11, 15, 13, 12, 13, 10],
        mark_point=["max", "min"],
        mark_line=["average"],
    )
    line.add(
        "最低气温",
        WEEK,
        [1, -2, 2, 5, 3, 2, 0],
        mark_point=["max", "min"],
        mark_line=["average"],
    )

    # pie
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos="center")
    pie.add(
        "",
        CLOTHES,
        v1,
        radius=[40, 75],
        label_text_color=None,
        is_label_show=True,
        legend_orient="vertical",
        legend_pos="left",
    )

    page.add([line, pie])

    # kline
    v1 = [
        [2320.26, 2320.26, 2287.3, 2362.94],
        [2300, 2291.3, 2288.26, 2308.38],
        [2295.35, 2346.5, 2295.35, 2345.92],
        [2347.22, 2358.98, 2337.35, 2363.8],
        [2360.75, 2382.48, 2347.89, 2383.76],
        [2383.43, 2385.42, 2371.23, 2391.82],
        [2377.41, 2419.02, 2369.57, 2421.15],
        [2425.92, 2428.15, 2417.58, 2440.38],
        [2411, 2433.13, 2403.3, 2437.42],
        [2432.68, 2334.48, 2427.7, 2441.73],
        [2430.69, 2418.53, 2394.22, 2433.89],
        [2416.62, 2432.4, 2414.4, 2443.03],
        [2441.91, 2421.56, 2418.43, 2444.8],
        [2420.26, 2382.91, 2373.53, 2427.07],
        [2383.49, 2397.18, 2370.61, 2397.94],
        [2378.82, 2325.95, 2309.17, 2378.82],
        [2322.94, 2314.16, 2308.76, 2330.88],
        [2320.62, 2325.82, 2315.01, 2338.78],
        [2313.74, 2293.34, 2289.89, 2340.71],
        [2297.77, 2313.22, 2292.03, 2324.63],
        [2322.32, 2365.59, 2308.92, 2366.16],
        [2364.54, 2359.51, 2330.86, 2369.65],
        [2332.08, 2273.4, 2259.25, 2333.54],
        [2274.81, 2326.31, 2270.1, 2328.14],
        [2333.61, 2347.18, 2321.6, 2351.44],
        [2340.44, 2324.29, 2304.27, 2352.02],
        [2326.42, 2318.61, 2314.59, 2333.67],
        [2314.68, 2310.59, 2296.58, 2320.96],
        [2309.16, 2286.6, 2264.83, 2333.29],
        [2282.17, 2263.97, 2253.25, 2286.33],
        [2255.77, 2270.28, 2253.31, 2276.22],
    ]
    kline = Kline("K 线图示例")
    kline.add(
        "日K",
        ["2017/7/{}".format(i + 1) for i in range(31)],
        v1,
        is_datazoom_show=True,
    )
    page.add(kline)

    # radar
    schema = [
        ("销售", 6500),
        ("管理", 16000),
        ("信息技术", 30000),
        ("客服", 38000),
        ("研发", 52000),
        ("市场", 25000),
    ]
    v1 = [[4300, 10000, 28000, 35000, 50000, 19000]]
    v2 = [[5000, 14000, 28000, 31000, 42000, 21000]]
    radar = Radar("雷达图示例")
    radar.config(schema)
    radar.add("预算分配", v1, is_splitline=True, is_axisline_show=True)
    radar.add(
        "实际开销",
        v2,
        label_color=["#4e79a7"],
        is_area_show=False,
        legend_selectedmode="single",
    )
    page.add(radar)

    # scatter3d
    data = [[
        random.randint(0, 100),
        random.randint(0, 100),
        random.randint(0, 100),
    ] for _ in range(80)]
    scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600)
    scatter3D.add("", data, is_visualmap=True, visual_range_color=RANGE_COLOR)
    page.add(scatter3D)

    # wordcloud
    name = [
        "Sam S Club",
        "Macys",
        "Amy Schumer",
        "Jurassic World",
        "Charter Communications",
        "Chick Fil A",
        "Planet Fitness",
        "Pitch Perfect",
        "Express",
        "Home",
        "Johnny Depp",
        "Lena Dunham",
        "Lewis Hamilton",
        "KXAN",
        "Mary Ellen Mark",
        "Farrah Abraham",
        "Rita Ora",
        "Serena Williams",
        "NCAA baseball tournament",
        "Point Break",
    ]
    value = [
        10000,
        6181,
        4386,
        4055,
        2467,
        2244,
        1898,
        1484,
        1112,
        965,
        847,
        582,
        555,
        550,
        462,
        366,
        360,
        282,
        273,
        265,
    ]
    wordcloud = WordCloud(width=1300, height=620)
    wordcloud.add("", name, value, word_size_range=[30, 100], rotate_step=66)
    page.add(wordcloud)

    # liquid
    liquid = Liquid("水球图示例")
    liquid.add("Liquid", [0.6])
    page.add(liquid)
    assert len(page) == 7
    assert isinstance(page[0], Line)
    assert ("echarts" in page.js_dependencies) or ("echarts.min"
                                                   in page.js_dependencies)
    page.render()
Beispiel #41
0
def test_pie_default():
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例")
    pie.add("", CLOTHES, v1, is_label_show=True)
    pie.render()
Beispiel #42
0
def test_pie_multiple():
    import random
    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    pie = Pie("饼图示例", width=1000, height=600)
    pie.add("", attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55], center=[25, 50], is_random=True)
    pie.add("", attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45], center=[25, 50], rosetype='area')
    pie.add("", attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55], center=[65, 50], is_random=True)
    pie.add("", attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45], center=[65, 50], rosetype='radius')
    pie.render()
def draw_height_pie(data):
    pie = Pie("妹子身高分布饼图-圆环图", title_pos='center')
    pie.add("", height_interval, data, radius=[40, 75], label_text_color=None,
            is_label_show=True, legend_orient='vertical', is_random=True,
            legend_pos='left')
    return pie
Beispiel #44
0
def create_simple_pie():
    pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
    pie.add(
        "",
        ["剧情", ""],
        [25, 75],
        center=[10, 30],
        radius=[18, 24],
        label_pos='center',
        is_label_show=True,
        label_text_color=None,
    )
    pie.add("", ["奇幻", ""], [24, 76],
            center=[30, 30],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None,
            legend_pos='left')
    pie.add("", ["爱情", ""], [14, 86],
            center=[50, 30],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["惊悚", ""], [11, 89],
            center=[70, 30],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["冒险", ""], [27, 73],
            center=[90, 30],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["动作", ""], [15, 85],
            center=[10, 70],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["喜剧", ""], [54, 46],
            center=[30, 70],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["科幻", ""], [26, 74],
            center=[50, 70],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["悬疑", ""], [25, 75],
            center=[70, 70],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None)
    pie.add("", ["犯罪", ""], [28, 72],
            center=[90, 70],
            radius=[18, 24],
            label_pos='center',
            is_label_show=True,
            label_text_color=None,
            is_legend_show=True,
            legend_top="center")
    pie.renderer = 'svg'
    return pie
Beispiel #45
0
def test_timeline_pie():
    style = Style()
    pie_style = style.add(
        is_label_show=True, radius=[30, 55], rosetype="radius"
    )
    pie_1 = Pie("2012 年销量比例", "数据纯属虚构")
    pie_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_2 = Pie("2013 年销量比例", "数据纯属虚构")
    pie_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_3 = Pie("2014 年销量比例", "数据纯属虚构")
    pie_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_4 = Pie("2015 年销量比例", "数据纯属虚构")
    pie_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    pie_5 = Pie("2016 年销量比例", "数据纯属虚构")
    pie_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)], **pie_style)

    timeline = Timeline(
        is_auto_play=True, timeline_bottom=0, width=1200, height=600
    )
    timeline.add(pie_1, "2012 年")
    timeline.add(pie_2, "2013 年")
    timeline.add(pie_3, "2014 年")
    timeline.add(pie_4, "2015 年")
    timeline.add(pie_5, "2016 年")
    assert len(timeline.options.get("baseOption").get("series")) == 0
    timeline.render()
            return country_1


#map() 会根据提供的函数对指定序列做映射。
# 对data['pub_time']全部使用get_country函数,与apply类似,但apply一般用于数据分组后再进行函数套用
data['country'] = data['pub_time'].map(get_country)
#如果直接使用,只能对单独元素进行操作
#print(data['pub_time'][0].split('('))
#data.head()
country = data.groupby('country')['country'].count()

from pyecharts import Pie

attr = list(country.index)
v1 = list(country)
pie = Pie("", title_pos='center')
pie.add(
    "",
    attr,
    v1,
    radius=[40, 75],
    label_text_color=None,
    is_label_show=True,
    legend_orient="vertical",
    legend_pos="left",
)
pie.render(r'E:\vscode_code\GitHub项目\爬虫+数据分析\猫眼\电影国家分布情况.html')

#提取人名
str = ''
for i in range(100):
Beispiel #47
0
def test_pie():

    # pie_0
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图示例")
    pie.add("", attr, v1, is_label_show=True)
    pie.show_config()
    pie.render()

    # pie_1
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    pie = Pie("饼图-圆环图示例", title_pos='center')
    pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical',
            legend_pos='left')
    pie.show_config()
    pie.render()

    # pie_2
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [11, 12, 13, 10, 10, 10]
    v2 = [19, 21, 32, 20, 20, 33]
    pie = Pie("饼图-玫瑰图示例", title_pos='center', width=900)
    pie.add("商品A", attr, v1, center=[25, 50], is_random=True, radius=[30, 75], rosetype='radius')
    pie.add("商品B", attr, v2, center=[75, 50], is_random=True, radius=[30, 75], rosetype='area', is_legend_show=False,
            is_label_show=True)
    pie.show_config()
    pie.render()

    # pie_3
    pie = Pie("饼图示例", title_pos='center', width=1000, height=600)
    pie.add("", ['A', 'B', 'C', 'D', 'E', 'F'], [335, 321, 234, 135, 251, 148], radius=[40, 55], is_label_show=True)
    pie.add("", ['H', 'I', 'J'], [335, 679, 204], radius=[0, 30], legend_orient='vertical', legend_pos='left')
    pie.show_config()
    pie.render()

    # pie_4
    import random
    attr = ['A', 'B', 'C', 'D', 'E', 'F']
    pie = Pie("饼图示例", width=1000, height=600)
    pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[25, 50], is_random=True)
    pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[25, 50], rosetype='area')
    pie.add("", attr, [random.randint(0, 100) for _ in range(6)], radius=[50, 55], center=[65, 50], is_random=True)
    pie.add("", attr, [random.randint(20, 100) for _ in range(6)], radius=[0, 45], center=[65, 50], rosetype='radius')
    pie.show_config()
    pie.render()

    # Pie_5
    pie = Pie('各类电影中"好片"所占的比例', "数据来着豆瓣", title_pos='center')
    pie.add("", ["剧情", ""], [25, 75], center=[10, 30], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None, )
    pie.add("", ["奇幻", ""], [24, 76], center=[30, 30], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None, legend_pos='left')
    pie.add("", ["爱情", ""], [14, 86], center=[50, 30], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["惊悚", ""], [11, 89], center=[70, 30], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["冒险", ""], [27, 73], center=[90, 30], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["动作", ""], [15, 85], center=[10, 70], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["喜剧", ""], [54, 46], center=[30, 70], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["科幻", ""], [26, 74], center=[50, 70], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["悬疑", ""], [25, 75], center=[70, 70], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None)
    pie.add("", ["犯罪", ""], [28, 72], center=[90, 70], radius=[18, 24],
            label_pos='center', is_label_show=True, label_text_color=None, is_legend_show=True, legend_top="center")
    pie.show_config()
    pie.render()
Beispiel #48
0
    page = Page()

    # line
    item_name_list, item_num_list = counter2list(dict2sorted_by_key(date_msg_counter))
    line = Line("群心情走势图", "截至日期:%s" % item_name_list[len(item_name_list) - 1], title_text_size=30,
                subtitle_text_size=18, title_pos='center')
    line.add("", item_name_list, item_num_list, mark_point=["max"], legend_pos='65%',
             xaxis_interval=2, xaxis_rotate=27, xaxis_label_textsize=20, yaxis_label_textsize=20, yaxis_name_pos='end',
             yaxis_pos="%50", is_label_show=True)
    page.add(line)

    # pie
    attr = ["总发言数", "日均发言", "发言最多", "发言最少"]
    v1 = [len(msg_list), math.floor(len(msg_list) / len(date_msg_counter)), most_msg_count[1],
          dict_sorted_by_value[0][1]]
    pie = Pie("群聊数据统计", title_pos='center')
    pie.add("", attr, v1, radius=[40, 75], label_text_color=None, is_label_show=True, legend_orient='vertical',
            legend_pos='left')
    page.add(pie)

    # bar
    bar = Bar("群聊情感分析", title_pos='center')
    item_name_list, item_num_list = emotions_count(emotions)
    bar.add("", item_name_list, item_num_list, title_pos='center', is_label_show=True, xaxis_label_textsize=20,
            yaxis_label_textsize=20)
    page.add(bar)

    # graph
    nodes = [{"name": earlest_time_node, "symbolSize": 30},
             {"name": latest_time_node, "symbolSize": 50},
             {"name": earlest_msg_node, "symbolSize": 30},
Beispiel #49
0
def maps(city, job):
    # # ---------------------------------------薪资频数分布图-----------------------------------
    # #
    # #
    # # 饼图  薪资频数分布图
    if city == '全国' or job == '':
        a = list(JobMsg.objects.all().values_list('job_meanmoney', ))
    else:
        a = list(
            JobMsg.objects.filter(job_name__icontains=job).values_list(
                'job_meanmoney', ))
    # print(a)
    mm = {
        '0-2000': 0,
        '2000-4000': 0,
        '4000-6000': 0,
        '6000-8000': 0,
        '8000-10000': 0,
        '10000-15000': 0,
        '15000-20000': 0,
        '20000-30000': 0,
        '30000以上': 0
    }
    for i in a:
        if int(i[0]) < 2000:
            mm['0-2000'] += 1
        elif int(i[0]) < 4000:
            mm['2000-4000'] += 1
        elif int(i[0]) < 6000:
            mm['4000-6000'] += 1
        elif int(i[0]) < 8000:
            mm['6000-8000'] += 1
        elif int(i[0]) < 10000:
            mm['8000-10000'] += 1
        elif int(i[0]) < 15000:
            mm['10000-15000'] += 1
        elif int(i[0]) < 20000:
            mm['15000-20000'] += 1
        elif int(i[0]) < 30000:
            mm['20000-30000'] += 1
        else:
            mm['30000以上'] += 1

    # ss = {}
    # for i in mm:
    #     if mm.count(i) >= 1:
    #         ss[i] = mm.count(i)
    key = list(mm.keys())
    value = list(mm.values())
    pie = Pie(title="薪资所占比例图",
              title_pos='left',
              width=1000,
              height=350,
              title_text_size=18)
    # pie.add(
    #     "",
    #     key,
    #     value,
    #     radius=[35, 60],
    #     center=[65, 50],
    #     legend_pos="80%",
    #     legend_orient="vertical",
    # )

    # 选图
    # pie.add("", key, value, radius=[35, 50], label_text_color=None, title_pos='left',
    #         is_label_show=True, legend_orient='vertical')
    #
    # pie.add("商品A", key, value, center=[65, 50], is_random=True,
    #         radius=[35, 50], rosetype='radius', legend_pos='left', legend_orient='vertical')

    pie.add("薪资频数分布图",
            key,
            value,
            center=[45, 50],
            is_random=True,
            radius=[35, 60],
            rosetype='area',
            legend_pos='left',
            legend_orient='vertical',
            is_legend_show=False,
            is_label_show=True)
    return pie
Beispiel #50
0
def qianChengWuYou(position, city):
    start_url = "https://search.51job.com/list/{},000000,0000,00,9,99,{},2,{}.html?lang=c&stype=&postchannel=0000&workyear=99&cotype=99&degreefrom=99&jobterm=99&companysize=99&providesalary=99&lonlat=0%2C0&radius=-1&ord_field=0&confirmdate=9&fromType=&dibiaoid=0&address=&line=&specialarea=00&from=&welfare="
    city_code = {
        "北京": "010000",
        "上海": "020000",
        "广州": "030200",
        "深圳": "040000",
        "武汉": "180200",
        "西安": "200200",
        "杭州": "080200",
        "南京": "070200",
        "成都": "090200",
        "重庆": "060000",
        "东莞": "030800",
        "大连": "230300",
        "沈阳": "230200",
        "苏州": "070300",
        "昆明": "250200",
        "长沙": "190200",
        "合肥": "150200",
        "宁波": "080300",
        "郑州": "170200",
        "天津": "050000",
        "青岛": "120300",
        "济南": "120200",
        "哈尔滨": "220200",
        "长春": "240200",
        "福州": "110200"
    }
    headers = {
        "Accept":
        "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Host":
        "search.51job.com",
        "Referer":
        start_url.format(quote(city_code[city]), quote(position), 1),
        "User-Agent":
        "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36",
    }
    rsp = requests.get(start_url.format(quote(city_code[city]),
                                        quote(position), 1),
                       headers=headers)
    html = etree.HTML(rsp.content)
    pages = html.xpath(
        '//*[@id="resultList"]/div[2]/div[5]/text()')[1].replace(" / ", "")
    districts = dict()
    districts = qianChengWuYou_parse_html(html, districts)
    for i in range(2, int(pages)):
        headers["Referer"] = start_url.format(quote(city_code[city]),
                                              quote(position), i)
        rsp = requests.get(start_url.format(quote(city_code[city]),
                                            quote(position), 1),
                           headers=headers)
        html = etree.HTML(rsp.content)
        districts = qianChengWuYou_parse_html(html, districts)
        time.sleep(0.02)
    pie = Pie("前程无忧职位信息统计",
              "{}{}职位行政区分布".format(city, position),
              title_pos='center',
              width=1300)
    columns = districts.keys()
    data = districts.values()
    # 加入数据,设置坐标位置为【75,50】,上方的colums选项取消显示,显示label标签
    pie.add("统计",
            columns,
            data,
            center=[50, 60],
            is_legend_show=False,
            is_label_show=True)
    # 保存图表
    pie.render(
        "/home/itianeru/PycharmProjects/RHFW/RHFW/pjob/templates/pjob/{}_{}.html"
        .format(city, position))