Esempio n. 1
0
def main():

    dutPl0 = []
    dutpl1 = []
    maxCntPl0 = []
    maxCntPl1 = []
    page = Page("Cluster Padding Figure")
    txtFiles = [name for name in os.listdir('./') if name.endswith('.txt')]
    for textLogName in txtFiles:
        waferNum = re.split(r'_', textLogName)
        with open(textLogName, 'rt') as clusterFile:
            for line in clusterFile:
                if re.match(r'IncomingBBKCount[A-Za-z0-9_.\+\-\*\/\s]*BBKP', line):
                    splitColon  = re.split(r'\s*[:]\s*', line)
                    splitColon1 = splitColon[0]
                    splitColon2 = splitColon[1]
                    splitColon3 = splitColon[2]
                    listBlk     = re.split(r'\s*[\s]\s*', splitColon3)
                    padBlk = paddingBlk(listBlk)
                    maxCnt = clusterBlk(padBlk)
                    splitSpace = re.split(r'\s*[\s]\s*', splitColon1)
                    intDut = int(splitSpace[1].replace('DUT', ''))
                    if splitSpace[2] == "BBKP0":
                        dutPl0.append(intDut)
                        maxCntPl0.append(maxCnt)
                    else:
                        dutpl1.append(intDut)
                        maxCntPl1.append(maxCnt)
        scatter = Scatter(waferNum[2])
        scatter.add("PL0", dutPl0, maxCntPl0, xaxis_name = "DUT", yaxis_name = "Max Padding BB", is_more_utils = True)
        scatter.add("PL1", dutpl1, maxCntPl1, xaxis_name = "DUT", yaxis_name = "Max Padding BB", is_more_utils = True)
        page.add(scatter)
    page.render()
Esempio n. 2
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
Esempio n. 3
0
def main():
    '''
    # 测试词云图
    x = [
        "python", "lxj", "zj", "big data", "python", "lxj", "zj", "big data",
        "python", "lxj", "zj", "big data", "python", "lxj", "zj", "big data"
        ]
    y = [
        10000, 8000, 6000, 3000, 10000, 8000, 6000, 3000,
        10000, 8000, 6000, 3000, 10000, 8000, 6000, 3000
        ]
    label = "词云"
    wordCloud(x, y, label)
    '''
    '''
    # 测试统计图表    
    x = ["衬衫", "袜子", "高跟鞋", "羊毛衫", "裤子"]
    y1 = [5, 10, 38, 75, 90]
    y2 = [15, 4, 70, 25, 190]
    label = "服装"
    type = 2
    get_charts(x, y, label, type)
    '''
    '''
    # 测试多个统计图
    page = Page()
    get_otherCharts(page)
    '''

    # 测试三维散点图
    page = Page()
    get_scatter3D(page)
Esempio n. 4
0
def create_experience(data, title):
    page = Page()
    style = Style(width=800,
                  title_pos="center",
                  height=400,
                  background_color='#c4ccd3')
    kwargs = dict(radius=(40, 75),
                  label_text_color=None,
                  is_label_show=True,
                  legend_orient='her',
                  legend_pos='left')
    experience_chart = Pie(title, **style.init_style)
    attr, value = experience_chart.cast(data)
    experience_chart.add("", attr, value, **kwargs)
    page.add(experience_chart)
    return page
Esempio n. 5
0
def create_charts():
    page = Page()

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

    df = pd.read_csv('./data_cleaned.csv')
    STREET_NAME = df.STREET_NAME.value_counts()
    chart = Bar("街道种类", **style.init_style)
    chart.add(
        "",
        STREET_NAME.index,
        STREET_NAME.values,
        mark_point=["max", "min"],
        mark_line=["average"],
        is_stack=True,
    )
    page.add(chart)

    chart = Timeline(is_auto_play=True,
                     timeline_bottom=0,
                     width=WIDTH,
                     height=HEIGHT)
    for name, c in df.groupby('STREET_NAME'):
        EVENT_TYPE_NAME = c.EVENT_TYPE_NAME.value_counts()
        chart_1 = Bar("各社区事件类型", **style.init_style)
        chart_1.add("",
                    EVENT_TYPE_NAME.index,
                    EVENT_TYPE_NAME.values,
                    mark_point=["max", "min"],
                    mark_line=["average"],
                    is_stack=True)
        chart.add(chart_1, name)
    page.add(chart)

    table = pd.pivot_table(df,
                           index=['STREET_NAME'],
                           columns=['EVENT_TYPE_NAME'],
                           values=['SUB_TYPE_NAME'],
                           aggfunc='count',
                           fill_value=0,
                           margins=1)
    table = table.ix[:-1, :-1]
    comm = list(table.index)
    name = [i[1] for i in table]
    value = [[i, j, float(table.values[i][j])] for i in range(len(comm))
             for j in range(len(name))]
    chart = HeatMap("街道与事件热力图", width=WIDTH, height=HEIGHT)
    chart.add("",
              comm,
              name,
              value,
              is_visualmap=True,
              visual_text_color="#000",
              visual_orient='horizontal')
    page.add(chart)

    return page
Esempio n. 6
0
File: bar.py Progetto: pipoted/bs
def create_charts():
    page = Page()

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

    attr = ["{}天".format(i) for i in range(30)]
    v1 = [random.randint(1, 30) for _ in range(30)]
    chart = Bar("柱状图-数据缩放(inside)", **style.init_style)
    chart.add("",
              attr,
              v1,
              is_datazoom_show=True,
              datazoom_type='inside',
              datazoom_range=[10, 60])
    page.add(chart)

    return page
Esempio n. 7
0
def create_clound_charts(data, title):
    '''词云图'''
    page = Page()
    # print(data)

    style = Style(
        width=2000,
        height=1000,
        title_pos="center",
    )

    chart = WordCloud(title, **style.init_style)
    attr, value = chart.cast(data)
    chart.add("", attr, value, shape='circle')
    page.add(chart)

    return page
def getProvinceCount(cityCount,countName):
    indexs = []
    counts = []
    for index in cityCount.index:
        indexs.append(index)
        counts.append(cityCount[index])
    page = Page()
    labels = [indexs]
    sizes = [counts]
    attr = indexs
    v1 = counts
    bar = Bar(countName)
    bar.add("地区分布", attr, v1, is_stack=True, is_label_show=True, is_datazoom_show=True,
            is_random=True)
    page.add(bar)
    bar.show_config()
    bar.render()
Esempio n. 9
0
def create_three():
    page = Page(page_title=TEST_PAGE_TITLE)

    # bar
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    bar.add("商家B", CLOTHES, v2, is_stack=True)
    page.add(bar)

    # 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)

    # guangdong
    value = [20, 190, 253, 77, 65]
    attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    map = Map("广东地图示例", width=1200, height=600)
    map.add("", attr, value, maptype='广东', is_visualmap=True,
            visual_text_color='#000')
    page.add(map)

    return page
Esempio n. 10
0
def create_charts():
    page = Page()

    data = [
        ['2015/11/08', 10, 'DQ'], ['2015/11/09', 15, 'DQ'], ['2015/11/10', 35, 'DQ'],
        ['2015/11/14', 7, 'DQ'], ['2015/11/15', 2, 'DQ'], ['2015/11/16', 17, 'DQ'],
        ['2015/11/17', 33, 'DQ'], ['2015/11/18', 40, 'DQ'], ['2015/11/19', 32, 'DQ'],
        ['2015/11/20', 26, 'DQ'], ['2015/11/21', 35, 'DQ'], ['2015/11/22', 40, 'DQ'],
        ['2015/11/23', 32, 'DQ'], ['2015/11/24', 26, 'DQ'], ['2015/11/25', 22, 'DQ'],
        ['2015/11/08', 35, 'TY'], ['2015/11/09', 36, 'TY'], ['2015/11/10', 37, 'TY'],
        ['2015/11/11', 22, 'TY'], ['2015/11/12', 24, 'TY'], ['2015/11/13', 26, 'TY'],
        ['2015/11/14', 34, 'TY'], ['2015/11/15', 21, 'TY'], ['2015/11/16', 18, 'TY'],
        ['2015/11/17', 45, 'TY'], ['2015/11/18', 32, 'TY'], ['2015/11/19', 35, 'TY'],
        ['2015/11/20', 30, 'TY'], ['2015/11/21', 28, 'TY'], ['2015/11/22', 27, 'TY'],
        ['2015/11/23', 26, 'TY'], ['2015/11/24', 15, 'TY'], ['2015/11/25', 30, 'TY'],
        ['2015/11/26', 35, 'TY'], ['2015/11/27', 42, 'TY'], ['2015/11/28', 42, 'TY'],
        ['2015/11/08', 21, 'SS'], ['2015/11/09', 25, 'SS'], ['2015/11/10', 27, 'SS'],
        ['2015/11/11', 23, 'SS'], ['2015/11/12', 24, 'SS'], ['2015/11/13', 21, 'SS'],
        ['2015/11/14', 35, 'SS'], ['2015/11/15', 39, 'SS'], ['2015/11/16', 40, 'SS'],
        ['2015/11/17', 36, 'SS'], ['2015/11/18', 33, 'SS'], ['2015/11/19', 43, 'SS'],
        ['2015/11/20', 40, 'SS'], ['2015/11/21', 34, 'SS'], ['2015/11/22', 28, 'SS'],
        ['2015/11/14', 7, 'QG'], ['2015/11/15', 2, 'QG'], ['2015/11/16', 17, 'QG'],
        ['2015/11/17', 33, 'QG'], ['2015/11/18', 40, 'QG'], ['2015/11/19', 32, 'QG'],
        ['2015/11/20', 26, 'QG'], ['2015/11/21', 35, 'QG'], ['2015/11/22', 40, 'QG'],
        ['2015/11/23', 32, 'QG'], ['2015/11/24', 26, 'QG'], ['2015/11/25', 22, 'QG'],
        ['2015/11/26', 16, 'QG'], ['2015/11/27', 22, 'QG'], ['2015/11/28', 10, 'QG'],
        ['2015/11/08', 10, 'SY'], ['2015/11/09', 15, 'SY'], ['2015/11/10', 35, 'SY'],
        ['2015/11/11', 38, 'SY'], ['2015/11/12', 22, 'SY'], ['2015/11/13', 16, 'SY'],
        ['2015/11/14', 7, 'SY'], ['2015/11/15', 2, 'SY'], ['2015/11/16', 17, 'SY'],
        ['2015/11/17', 33, 'SY'], ['2015/11/18', 40, 'SY'], ['2015/11/19', 32, 'SY'],
        ['2015/11/20', 26, 'SY'], ['2015/11/21', 35, 'SY'], ['2015/11/22', 4, 'SY'],
        ['2015/11/23', 32, 'SY'], ['2015/11/24', 26, 'SY'], ['2015/11/25', 22, 'SY'],
        ['2015/11/26', 16, 'SY'], ['2015/11/27', 22, 'SY'], ['2015/11/28', 10, 'SY'],
        ['2015/11/08', 10, 'DD'], ['2015/11/09', 15, 'DD'], ['2015/11/10', 35, 'DD'],
        ['2015/11/11', 38, 'DD'], ['2015/11/12', 22, 'DD'], ['2015/11/13', 16, 'DD'],
        ['2015/11/14', 7, 'DD'], ['2015/11/15', 2, 'DD'], ['2015/11/16', 17, 'DD'],
        ['2015/11/17', 33, 'DD'], ['2015/11/18', 4, 'DD'], ['2015/11/19', 32, 'DD'],
        ['2015/11/20', 26, 'DD'], ['2015/11/21', 35, 'DD'], ['2015/11/22', 40, 'DD'],
        ['2015/11/23', 32, 'DD'], ['2015/11/24', 26, 'DD'], ['2015/11/25', 22, 'DD']
    ]
    chart = ThemeRiver("主题河流图", width=WIDTH, height=HEIGHT)
    chart.add(['DQ', 'TY', 'SS', 'QG', 'SY', 'DD'], data, is_label_show=True)
    page.add(chart)

    return page
Esempio n. 11
0
def scatter3d():
    from pyecharts import Scatter3D, Page, Bar

    import random
    page = Page()
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("3D柱状图示例")
    bar.add('商家A', attr, v1)
    bar.add('商家B', attr, v2)
    page.add(bar)
    data = [[
        random.randint(0, 100),
        random.randint(0, 100),
        random.randint(0, 100)
    ] for _ in range(80)]
    range_color = [
        '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
        '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'
    ]
    scatter3D = Scatter3D("3D 散点图 demo", width=1200, height=600)
    scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color)
    page.add(scatter3D)
    return page.render_embed()
Esempio n. 12
0
def make_plot(city):

    city_dict = make_city_dict()

    # 倒入包
    data = pd.read_csv('csv_files/%s/room_type.csv' % city)
    # 读取数据

    configure(global_theme='vintage')
    # 设置主题

    attr = data["室厅厨卫 布局"].tolist()
    v1 = data["数量"].tolist()
    # 数据处理

    bar = Bar(title="%s各二手房 室厅厨卫 布局 条形图" % city_dict[city],
              width=1200,
              height=600)
    bar.add(
        "数量",
        attr,
        v1,
        mark_point=["max", "min"],
        xaxis_rotate=35,
        mark_point_textcolor='#000',
        mark_point_symbol="pin",
    )
    pie = Pie("%s二手房 室厅厨卫 布局 饼状图" % city_dict[city],
              title_pos="left",
              width=1200,
              height=600)
    pie.add("",
            attr,
            v1,
            radius=[40, 80],
            label_text_color=None,
            is_label_show=True,
            legend_orient="vertical",
            legend_pos="right",
            is_toolbox_show=False)

    page = Page()
    page.add_chart(bar)
    page.add_chart(pie)
    return page
Esempio n. 13
0
	def page_all_bivar(data,num_fea,cat_fea,tar,draw_order=['none'],out=False,file_name='bivar.html',
						draw_type='line',bins=20,tree_depth=4,woe = None,d_reorder=False,
						custom_bin=[],cut_num=None,cut_start=None,fill_na=-99999):
		#print all bivar picture on one html page
		#page_all_bivar(data=df,num_fea=numerical_col,cat_fea=category_col,tar='pass',out=True)
		page = Page()
		if len(num_fea) != 0:
			for c in data[num_fea]:
				keep_draw = True
				for k in draw_order:
					while keep_draw == True:
						try:
							temp = draw.bivar(data=data,feature=c,target=tar,t_type='c',draw_type='line',
							bins=20,tree_depth=4,woe = None,d_reorder=False,custom_bin=[],cut_num=None,
							cut_start=None,fill_na=-99999)
							page.add(temp)
							keep_draw = False
						except:
							continue
		if len(cat_fea) != 0:
			for d in data[cat_fea]:
				try:
					temp = draw.bivar(data=data,feature=d,target=tar,t_type='d',d_reorder = d_reorder)
					page.add(temp)
				except:
					continue
		if len(num_fea+cat_fea) == 0:
			return 'no such feature in function'
		if out:
			return page.render(file_name)
		else:
			return page
Esempio n. 14
0
 def __init__(self, path, ispage=True):
     self.page = Page()
     self.overlap = Overlap()
     self.ispage = ispage
     self.path = path
     self.range_color = [
         "#313695",
         "#4575b4",
         "#74add1",
         "#abd9e9",
         "#e0f3f8",
         "#ffffbf",
         "#fee090",
         "#fdae61",
         "#f46d43",
         "#d73027",
         "#a50026",
     ]
Esempio n. 15
0
def top_rend():
    page = Page()
    allmovietype = filewr(movie_type_top, movietype)
    allcritic = filewr(all_type_critic_top, allresultfile)
    allmoviecritic = filewr(movie_name_top, mostmoviefile)
    allonecritic = filewr(movie_critic_top, moviecritic)

    mostmovietype = visual(allmovietype, "电影类型数量排行榜", "电影数")
    mosttypecritic = visual(allcritic, "电影类型评论排行榜", "评论数量")
    mostmoviecritic = visual(allmoviecritic, "电影评论排行榜", "评论数量")
    mostonecritic = visual(allonecritic, "评论中词汇排行榜", "词语权重")

    page.add(mostmovietype)
    page.add(mosttypecritic)
    page.add(mostmoviecritic)
    page.add(mostonecritic)

    return page
Esempio n. 16
0
def test_page_add_chart():
    nc = (Page().add_chart(MagicMock(page_title="Line-Chart"),
                           name="line").add_chart(
                               MagicMock(page_title="Bar-Chart")))
    nc["map"] = MagicMock(page_title="Map-Chart")
    eq_("Line-Chart", nc["line"].page_title)
    eq_("Bar-Chart", nc["c1"].page_title)
    assert_list_equal(["Line-Chart", "Bar-Chart", "Map-Chart"],
                      [c.page_title for c in nc])
Esempio n. 17
0
def test_page_init():
    line = MagicMock(page_title="Line-Chart")
    bar = MagicMock(page_title="Bar-Chart")
    page = Page(line=line, bar=bar)
    eq_("Line-Chart", page["line"].page_title)
    assert "line" in page
    assert "bar" in page
    if PY36:
        eq_("Line-Chart", page[0].page_title)
Esempio n. 18
0
def get_all_div():
    page = Page()
    t1 = create_wordcloud()
    t2 = create_map()
    t3 = create_pie()
    t4 = create_bar()
    page.add(t1)
    page.add(t2)
    page.add(t3)
    page.add(t4)
    page.render()
Esempio n. 19
0
def data_show1():  # 公交IC卡分析
    data = getICdata()
    minute = 60
    line_no = list(data.line_id.unique())
    # 1
    # data_101 = data[data.line_id.isin(line_no)].sort_values(by='TXNDATE').reset_index(drop=True)
    # 2
    data_101 = data.sort_values(by='TXNDATE').reset_index(drop=True)
    data_101['time_2_seconds'] = data_101.TXNDATE.apply(lambda x: x.time())
    data_101['time_2_seconds'] = data_101['time_2_seconds'].map(str).map(t2s)
    # 站点客流量排序
    station_num = data_101['STATION_NAME'].value_counts().sort_values(
        ascending=False)  # 大到小
    station_num_head10 = station_num.head(10)

    # 1个小时一划分客流量
    time_2_seconds_bins = [
        i * minute * 60 for i in range(int(24 / (minute / 60)) + 1)
    ]
    labels = [i for i in range(1, int(24 / (minute / 60)) + 1)]
    Time_groups = pd.cut(data_101['time_2_seconds'],
                         time_2_seconds_bins,
                         labels=labels).rename('time_2_seconds_labels')
    passenger_num = Time_groups.value_counts().sort_index()

    from pyecharts import Bar, Scatter3D, EffectScatter, Overlap, Line, Pie
    from pyecharts import Page, configure
    configure(global_theme='shine')  # 更改主题
    page = Page()
    bar1 = Bar("乘客量top10的站点", "图一")
    bar1.add("乘客量top10的站点",
             station_num_head10.index,
             station_num_head10.values,
             xaxis_rotate=45,
             is_mor_utils=True)
    line1 = Line()
    line1.add("乘客量top10的站点(折线图)", station_num_head10.index,
              station_num_head10.values)
    overlap_1 = Overlap()
    overlap_1.add(bar1)
    overlap_1.add(line1)
    bar2 = Bar("全天一小时时段区间乘客登车数量", "图二")
    bar2.add("不同时段区间乘客数量",
             passenger_num.index,
             passenger_num.values,
             xaxis_rotate=90,
             is_mor_utils=True,
             mark_point=["min", "max"])
    # bar.print_echarts_options() # 该行只为了打印配置项,方便调试时使用
    page.add(overlap_1)
    page.add(bar2)
    page.render('app/templates/render/passenger_top10.html')  # 生成本地 HTML 文件

    return render_template('render/passenger_top10.html')
Esempio n. 20
0
def CreateCharts():
    page = Page()

    # 获取到 Chart1() 函数绘制的图,并添加到 page 中
    chart1 = Chart1()
    page.add(chart1)

    # 获取到 Chart2() 函数绘制的图,并添加到 page 中
    chart2 = Chart2()
    page.add(chart2)

    chart3 = Chart3()
    page.add(chart3)

    chart4 = Chart4()
    page.add(chart4)

    app.kill()
    return page
Esempio n. 21
0
def get_all_div(sou1):
    page = Page()
    t1 = create_wordcloud(sou1)
    t2 = create_map()
    t3 = create_pie()
    t4 = create_bar()
    page.add(t1)
    page.add(t2)
    page.add(t3)
    page.add(t4)
    name = str(sou1) + '.html'
    page.render(name)
Esempio n. 22
0
def create_charts():
    page = Page()

    style = Style(width=1100, height=600)

    # value = [155, 10, 66, 78]
    # attr = ["福建", "山东", "北京", "上海"]
    # chart = Map("全国地图", **style.init_style)
    # chart.add("", attr, value, maptype='china', is_label_show=True)
    # page.add(chart)

    value = [155, 10, 66, 78, 33, 80, 190, 53, 49.6]
    attr = ["福建", "山东", "北京", "上海", "甘肃", "新疆", "河南", "广西", "西藏"]
    chart = Map("全国地图-视觉通道", **style.init_style)
    chart.add("",
              attr,
              value,
              maptype='china',
              is_visualmap=True,
              visual_text_color='#000')
    page.add(chart)

    # value = [20, 190, 253, 77, 65]
    # attr = ['汕头市', '汕尾市', '揭阳市', '阳江市', '肇庆市']
    # chart = Map("广东地图", **style.init_style)
    # chart.add("", attr, value, maptype='广东',
    #           is_visualmap=True, visual_text_color='#000')
    # page.add(chart)
    #
    # value = [95.1, 23.2, 43.3, 66.4, 88.5, 0.1]
    # attr = ["China", "Canada", "Brazil", "Russia",
    #         "United States", "Unknown Country"]
    # chart = Map("世界地图 - 带标记点", **style.init_style)
    # chart.add("", attr, value, maptype="world", is_visualmap=True,
    #           visual_text_color='#000')
    # page.add(chart)
    #
    # chart = Map("世界地图 - 不带标记点", **style.init_style)
    # chart.add("", attr, value, maptype="world", is_visualmap=True,
    #           is_map_symbol_show=False, visual_text_color='#000')
    # page.add(chart)

    return page
Esempio n. 23
0
 def render_page(self, sex_dict, province_dict, word_list):
     """
     渲染页面多图
     """
     page = Page()
     pie = self.get_sex_pie(sex_dict)
     map = self.get_province_map(province_dict)
     wordcloud = self.get_wordcloud(word_list)
     page.add(pie)
     page.add(map)
     page.add(wordcloud)
     page.render()
Esempio n. 24
0
def page(player_id: int = None):
    # init_list = json_load('matches')
    if not player_id:
        init_list = get_player_matches_json(129689355)
    else:
        init_list = get_player_matches_json(player_id)
    # print(len(init_list))
    init_dict = {}
    data = []
    for row in init_list:
        start_time = datetime.fromtimestamp(
            row['start_time']).strftime("%Y-%m-%d")
        if start_time not in init_dict:
            init_dict[start_time] = 1
        else:
            init_dict[start_time] += 1
    for key in init_dict:
        val = init_dict[key]
        key = datetime.strptime(key, "%Y-%m-%d")
        tmp = []
        tmp.extend((key, val))
        data.append(tmp)

    page = Page()
    year = int(datetime.today().strftime("%Y"))
    for i in range(year, 2016, -1):
        heatmap = HeatMap(height=250, width=1100)
        heatmap.add("",
                    data,
                    is_calendar_heatmap=True,
                    visual_text_color='#000',
                    visual_range_text=['', ''],
                    visual_range=[0, 15],
                    calendar_cell_size=['auto', 20],
                    is_visualmap=True,
                    calendar_date_range=str(i),
                    visual_orient="horizontal",
                    visual_pos="center",
                    visual_top="90%",
                    is_piecewise=True)
        page.add(heatmap)
    return page
Esempio n. 25
0
def geo_map(data, title):
    page = Page()
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=800,
                  height=400,
                  background_color='#c4ccd3')
    kwargs = dict(maptype='china',
                  is_visualmap=True,
                  type="effectScatter",
                  is_legend_show=False,
                  geo_emphasis_color='c4ccd3',
                  visual_text_color='#2f4554')
    # 创建地图模型
    chart = Geo(title, "", **style.init_style)
    attr, value = chart.cast(data)
    # 添加数据
    chart.add("", attr, value, **kwargs)
    page.add_chart(chart)
    return page
Esempio n. 26
0
async def run_benchmark(option):
    urls = option['urls']
    # convert to string in order to used in dict
    conns = [str(conn) for conn in option['connections']]

    for conn in conns:
        benchmarks[conn] = {}
        cpu_usage[conn] = {}
        for url in urls:
            benchmarks[conn][url] = []
            cpu_usage[conn][url] = []
            benchmark_task = asyncio.ensure_future(run_wrk(url, conn, option))
            monitor_task = asyncio.ensure_future(
                monitor(url, conn, option['duration']))
            # TODO: 这里需要修改为如果主任务异常退出,则monitor任务也停止
            done, pending = await asyncio.wait(
                [benchmark_task, monitor_task],
                return_when=asyncio.ALL_COMPLETED,
            )
    for task in pending:
        task.cancel()

    print('Result: {} \n{}'.format(benchmarks, cpu_usage))
    page = Page()

    tps_bar = Bar("测试结果", "")
    cpu_line = Line("CPU占用率")

    v = {}
    for conn in conns:
        v[conn] = []
        for url in urls:
            v[conn].append(benchmarks[conn][url])

    for conn in conns:
        tps_bar.add(conn + '连接', urls, v[conn])
        for url in urls:
            cpu_line.add(url + ' ' + conn + '连接',
                         [i for i in range(option['duration'])],
                         cpu_usage[conn][url],
                         yaxis_max=100,
                         yaxis_formatter=" %")

    page.add(tps_bar)
    page.add(cpu_line)
    page.render()

    print('Result on: http://{}:{}'.format(get_ip(), PORT))
    server = HTTPServer(('0.0.0.0', PORT), MyServer)
    server.serve_forever()
    server.server_close()
Esempio n. 27
0
    def get_echarts_instance(self, *args, **kwargs):
        device_data = models.Device.objects.values('device_type').annotate(count=Count('device_type'))
        device_types, counters = fetch(device_data, 'device_type', 'count')
        pie = Pie("设备分类", page_title='设备分类', width='100%')
        pie.add("设备分类", device_types, counters, is_label_show=True)

        battery_lifes = models.Device.objects.values('name', 'battery_life')
        names, lifes = fetch(battery_lifes, 'name', 'battery_life')
        bar = Bar('设备电量', page_title='设备电量', width='100%')
        bar.add("设备电量", names, lifes)
        page = Page.from_charts(pie, bar)
        return page
Esempio n. 28
0
def creat_lan_charts(data_list):
    page = Page()
    style = Style(title_color="#fff",
                  title_pos="center",
                  width=1200,
                  height=600,
                  background_color='#404a59')

    chart = Geo("全国主要城市空气质量", "data from pm2.5", **style.init_style)
    attr, value = chart.cast(data_list)
    chart.add("",
              attr,
              value,
              type="heatmap",
              is_visualmap=True,
              visual_range=[0, 200],
              visual_text_color='#fff',
              is_legend_show=False)
    page.add(chart)

    return page
Esempio n. 29
0
def plot_line_graph():
    page = Page('back_testing')

    line = Line("K 线图-dataZoom 垂直布局", width=1300, height=400, title_pos="left")
    line.add(
        "日K",
        ["2017/7/{}".format(i + 1) for i in range(31)],
        [random.randint(1, 2000) for _ in range(31)],
        tooltip_trigger="axis",
        tooltip_axispointer_type='cross',
        mark_line=["max", 'min'],
        legend_top="3%",
        mark_point=['average', 'max', 'min'],
        is_smooth=True,
        line_color='#5296de',
        line_width=2.5,
        # yaxis_type="log",
    )

    line.add("日收益", ["2017/7/{}".format(i + 1) for i in range(31)],
             [random.randint(1, 2000) for _ in range(31)],
             tooltip_trigger="axis",
             mark_point=['average', 'max', 'min'],
             mark_line=["max", 'min'],
             is_datazoom_show=True,
             legend_top="3%",
             is_smooth=True,
             line_color='#082039',
             line_width=2.5,
             **style.init_style
             # yaxis_type="log",
             )

    page.add(line)
    # line.show_config()

    kline = Kline("K 线图-dataZoom 水平布局",
                  width=1300,
                  height=400,
                  title_pos="left")
    kline.add("日K", ["2017/7/{}".format(i + 1) for i in range(31)],
              data,
              mark_point=["max"],
              is_datazoom_show=True,
              **style.init_style)

    page.add(kline)
    # kline.show_config()

    page.render(FILE_DIR + 'line_graph.html')
Esempio n. 30
0
def create_two_bars():
    page = Page()

    # bar
    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", attr, v1, is_stack=True)
    bar.add("商家B", attr, v2, is_stack=True)
    page.add(bar)

    # scatter3D
    import random
    data = [[
        random.randint(0, 100),
        random.randint(0, 100),
        random.randint(0, 100)
    ] for _ in range(80)]
    range_color = [
        '#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
        '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026'
    ]
    scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600)
    scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color)
    page.add(scatter3D)
    return page
Esempio n. 31
0
def main():
    res_list = parse_procrank(sys.argv[1])
    df = pd.DataFrame(res_list).fillna(0)
    ts = df['ts']
    df.drop(columns='ts', inplace=True)
    local_list = []
    max_list = []
    for column in df.columns:
        local_max = max(df[column])
        max_list.append(local_max)
        local_map = {
            'comm': column,
            'memory': df[column].tolist(),
            'max': local_max
        }
        local_list.append(local_map)
    local_list = sorted(local_list, key=operator.itemgetter('max'))
    page = Page()
    index = 0
    line = None
    for _map in local_list:
        if index % 3 == 0:
            line = Line(width=1600)
            page.add(line)
        line.add(_map['comm'],
                 ts,
                 _map['memory'],
                 is_smooth=True,
                 xaxis_rotate=45,
                 xaxis_interval=5,
                 mark_line=['max', 'average'])
        index += 1
    page.render('procrank.html')
Esempio n. 32
0
def create_charts():
    page = Page()

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

    attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
    value = [20, 40, 60, 80, 100, 120]
    chart = Funnel("漏斗图示例", **style.init_style)
    chart.add("商品",
              attr,
              value,
              is_label_show=True,
              label_pos="inside",
              label_text_color="#fff")
    page.add(chart)

    chart = Funnel("漏斗图示例", title_pos='center', **style.init_style)
    chart.add("商品",
              attr,
              value,
              is_label_show=True,
              label_pos="outside",
              legend_orient='vertical',
              legend_pos='left')
    page.add(chart)

    return page
Esempio n. 33
0
def big_class_radar():
    page = Page()
    schema = [("产品", 20), ("市场与销售", 20), ("技术", 20), ("职能", 20), ("设计", 20),
              ("运营", 20), ("金融", 20)]
    print("正在计算...")
    data = sel_bigClass_avg_salary()
    print(data)
    salary_list = []
    count_list = []
    for i in data:
        salary_list.append(i[1])
        count_list.append(i[2])
    v1 = [salary_list]
    v2 = [count_list]
    #平均薪资雷达图
    radar = Radar(background_color='#F4F3EF', )
    radar.config(schema)
    radar.add("平均薪资", v1, is_splitline=True, is_axisline_show=True)
    page.add(radar)
    #职位数量雷达图
    schema2 = [("产品", 50000), ("市场与销售", 50000), ("技术", 50000), ("职能", 50000),
               ("设计", 50000), ("运营", 50000), ("金融", 50000)]
    radar2 = Radar(background_color='#F4F3EF', )
    radar2.config(schema2)
    radar2.add("职位数量",
               v2,
               is_splitline=True,
               is_axisline_show=True,
               label_color=["#4e79a7"])
    page.add(radar2)
    return page
Esempio n. 34
0
def create_three():
    # bar
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图数据堆叠示例")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    bar.add("商家B", CLOTHES, v2, is_stack=True)

    # 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)

    return Page.from_charts(bar, scatter3d)
def score_draw(csv_file):
    page = Page(csv_file+":评论等级分析")
    score, date, val, score_list = [], [], [], []
    result = {}
    path = os.path.abspath(os.curdir)
    csv_file = path + "\\" + csv_file + ".csv"
    csv_file = csv_file.replace('\\', '\\\\')
    d = pd.read_csv(csv_file, engine='python', encoding='utf-8')[['score', 'date']].dropna()  # 读取CSV转为dataframe格式,并丢弃评论为空的记录
    for indexs in d.index:  # 一种遍历df行的方法(下面还有第二种,iterrows)
        score_list.append(tuple(d.loc[indexs].values[:])) # 目前只找到转换为tuple然后统计相同元素个数的方法
    #print("有效评分总数量为:",len(score_list), " 条")
    for i in set(list(score_list)):
        result[i] = score_list.count(i)  # dict类型 ('很差', '2018-04-28'): 55
    info = []
    for key in result:
        score= key[0]
        date = key[1]
        val = result[key]
        info.append([score, date, val])
    info_new = DataFrame(info)  # 将字典转换成为数据框
    info_new.columns = ['score', 'date', 'votes']
    info_new.sort_values('date', inplace=True)    # 按日期升序排列df,便于找最早date和最晚data,方便后面插值
    #print("first df", info_new)
    # 以下代码用于插入空缺的数据,每个日期的评分类型应该有5中,依次遍历判断是否存在,若不存在则往新的df中插入新数值
    mark = 0
    creat_df = pd.DataFrame(columns = ['score', 'date', 'votes']) # 创建空的dataframe
    for i in list(info_new['date']):
        location = info_new[(info_new.date==i)&(info_new.score=="力荐")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["力荐", i, 0]
            mark += 1
        location = info_new[(info_new.date==i)&(info_new.score=="推荐")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["推荐", i, 0]
            mark += 1
        location = info_new[(info_new.date==i)&(info_new.score=="还行")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["还行", i, 0]
            mark += 1
        location = info_new[(info_new.date==i)&(info_new.score=="较差")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["较差", i, 0]
            mark += 1
        location = info_new[(info_new.date==i)&(info_new.score=="很差")].index.tolist()
        if location == []:
            creat_df.loc[mark] = ["很差", i, 0]
            mark += 1
    info_new = info_new.append(creat_df.drop_duplicates(), ignore_index=True)
    score_list = []
    info_new.sort_values('date', inplace=True)    # 按日期升序排列df,便于找最早date和最晚data,方便后面插值
    #print(info_new)
    for index, row in info_new.iterrows():   # 第二种遍历df的方法
        score_list.append([row['date'], row['votes'], row['score']])
    tr = ThemeRiver()
    tr.add(['力荐', '推荐', '还行', '较差', '很差'], score_list, is_label_show=True, is_more_utils=True)
    page.add_chart(tr)

    attr, v1, v2, v3, v4, v5 = [], [], [], [], [], []
    attr = list(sorted(set(info_new['date'])))
    bar = Bar()
    for i in attr:
        v1.append(int(info_new[(info_new['date']==i)&(info_new['score']=="力荐")]['votes']))
        v2.append(int(info_new[(info_new['date']==i)&(info_new['score']=="推荐")]['votes']))
        v3.append(int(info_new[(info_new['date']==i)&(info_new['score']=="还行")]['votes']))
        v4.append(int(info_new[(info_new['date']==i)&(info_new['score']=="较差")]['votes']))
        v5.append(int(info_new[(info_new['date']==i)&(info_new['score']=="很差")]['votes']))
    bar.add("力荐", attr, v1, is_stack=True)
    bar.add("推荐", attr, v2, is_stack=True)
    bar.add("还行", attr, v3, is_stack=True)
    bar.add("较差", attr, v4, is_stack=True)
    bar.add("很差", attr, v5, is_stack=True, is_convert=True, mark_line=["average"], is_more_utils=True)
    page.add_chart(bar)

    line = Line()
    line.add("力荐", attr, v1, is_stack=True)
    line.add("推荐", attr, v2, is_stack=True)
    line.add("还行", attr, v3, is_stack=True)
    line.add("较差", attr, v4, is_stack=True)
    line.add("很差", attr, v5, is_stack=True, is_convert=False, mark_line=["average"], is_more_utils=True)
    page.add_chart(line)

    page.render(csv_file[:-4] + "_日投票量分析汇总.html")
Esempio n. 36
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()
Esempio n. 37
0
def test_page_grid_timeline_overlap():
    # Grid
    v1 = [5, 20, 36, 10, 75, 90]
    v2 = [10, 25, 8, 60, 20, 80]
    bar = Bar("柱状图示例", height=720, width=1200, title_pos="65%")
    bar.add("商家A", CLOTHES, v1, is_stack=True)
    bar.add("商家B", CLOTHES, v2, is_stack=True, legend_pos="80%")
    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"],
        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%",
    )

    grid = Grid()
    grid.add(bar, grid_bottom="60%", grid_left="60%")
    grid.add(line, grid_bottom="60%", grid_right="60%")
    grid.add(scatter, grid_top="60%", grid_left="60%")
    grid.add(es, grid_top="60%", grid_right="60%")

    # Timeline
    bar_1 = Bar("2012 年销量", "数据纯属虚构")
    bar_1.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_1.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_1.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_1.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_2 = Bar("2013 年销量", "数据纯属虚构")
    bar_2.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_2.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_2.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_2.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_3 = Bar("2014 年销量", "数据纯属虚构")
    bar_3.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_3.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_3.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_3.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_4 = Bar("2015 年销量", "数据纯属虚构")
    bar_4.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_4.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_4.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_4.add("冬季", CLOTHES, [randint(10, 100) for _ in range(6)])

    bar_5 = Bar("2016 年销量", "数据纯属虚构", height=720, width=1200)
    bar_5.add("春季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_5.add("夏季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_5.add("秋季", CLOTHES, [randint(10, 100) for _ in range(6)])
    bar_5.add(
        "冬季",
        CLOTHES,
        [randint(10, 100) for _ in range(6)],
        is_legend_show=True,
    )

    timeline = Timeline(is_auto_play=True, timeline_bottom=0)
    timeline.add(bar_1, "2012 年")
    timeline.add(bar_2, "2013 年")
    timeline.add(bar_3, "2014 年")
    timeline.add(bar_4, "2015 年")
    timeline.add(bar_5, "2016 年")

    # Overlap
    attr = ["{}月".format(i) for i in range(1, 13)]
    v1 = [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
    v2 = [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
    v3 = [2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2]

    bar = Bar(height=720, width=1200)
    bar.add("蒸发量", attr, v1)
    bar.add("降水量", attr, v2, yaxis_formatter=" ml", yaxis_max=250)
    line = Line()
    line.add("平均温度", attr, v3, yaxis_formatter=" °C")

    overlap = Overlap()
    overlap.add(bar)
    overlap.add(line, yaxis_index=1, is_add_yaxis=True)

    page = Page()
    page.add(grid)
    page.add(timeline)
    page.add(overlap)
    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")
Esempio n. 39
0
import datetime

url = "http://www.86pm25.com/paiming.htm"
head = {
    'Referer': 'http://www.86pm25.com/city/Dazhou.html',
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'
}
html = requests.get(url, headers=head)
html.encoding = 'utf-8'
soup = BeautifulSoup(html.text, "lxml")
data1 = soup.find(id="goodtable").find_all(name='a')
data2 = str(soup.find(id='goodtable').find_all(name='td'))
data = re.findall(r'<td>(\d{1,3}.)</td>', data2)
with open("城市.txt", 'r') as f:
    CityList = f.read()
city = []
for i in range(0, 367):
    if str(data1[i].string) in CityList:
        citytuple = (data1[i].string, int(data[i]))
        city.append(citytuple)
geo = Geo("全国主要城市空气质量实时监控", "实时:" + str(datetime.datetime.now()), title_color="#fff",
          title_pos="center", width='100%',
          height=790, background_color='#404a59')
attr, value = geo.cast(city)
geo.add("", attr, value, visual_range=[0, 150], maptype='china', visual_text_color="#fff",
        symbol_size=13, is_visualmap=True)
page = Page()
page.add(geo)
page.render("全国主要城市空气质量实时监控.html")
webbrowser.open("全国主要城市空气质量实时监控.html", new=0, autoraise=True)
Esempio n. 40
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()
Esempio n. 41
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()