Beispiel #1
0
def event_temp(request):
    print("query event")
    print(chainIdx)
    chain_keys = list(chains.keys())
    chain = chains[chain_keys[int(chainIdx)]]  #[{event1},{event2},{event3}]
    context = {}
    timelineIndex = 0
    if 'timelineIndex' in request.GET and request.GET[
            'timelineIndex']:  #获得tl的index
        context["timelineIndex"] = request.GET['timelineIndex']
        timelineIndex = int(context["timelineIndex"])
    if 'scrollTop' in request.GET and request.GET['scrollTop']:
        context["scrollTop"] = request.GET['scrollTop']
    line_data, poses, words, frame_ids, table_data = process_chain(chain)
    page = Page()
    print("timelineIdx:{}".format(timelineIndex))
    eventmap = get_eventbmap(poses[timelineIndex])
    eventmap.chart_id = "map_event"
    eventline = get_eventline(line_data)
    eventline.chart_id = "line_event"
    wordcloudline = get_wordcloud_line(words[timelineIndex], frame_ids)
    wordcloudline.chart_id = "wordcloud_line"
    eventtable = get_eventtable(table_data[timelineIndex])
    eventtable.chart_id = "table_event"
    page.add(eventmap)
    page.add(eventline)
    page.add(wordcloudline)
    page.add(eventtable)
    page.render(path="event.html", template_name="simple_page_event.html")
    #记得在以下函数中增加了模板函数
    Page.save_resize_html("event.html",
                          cfg_file="./demo/chart_config_event.json",
                          dest="./demo/templates/my_event_charts.html")
    #page.render("bmap.html",template="simple_page_event.html")
    return render(request, "my_event_charts.html", context)  #可以向模板中填充数据来显示矩形框
Beispiel #2
0
def Chart_2():
    page = Page(layout=Page.DraggablePageLayout)
    # page.add(WorldMap(), WorldZhexian(),WorldBar())
    #
    # page.render("test_2.html")
    Page.save_resize_html("test_2.html",
                          cfg_file="chart_config_2.json",
                          dest="my_test_2.html")

    return page
Beispiel #3
0
def Chart_3():
    page = Page(layout=Page.DraggablePageLayout)
    # page.add(UsaZhexian(), YdZhexian(),YdlZhexian())
    #
    # page.render("test_3.html")
    Page.save_resize_html("test_3.html",
                          cfg_file="chart_config_3.json",
                          dest="my_test_3.html")

    return page
Beispiel #4
0
def page_draggable_layout():
    page = Page(layout=Page.DraggablePageLayout)
    page.add(
        bar_reverse(),
        gauge(),
        liquid(),
        rose(),
        wordcloud(),
        bar(),
    )
    page.render("page.html")
    Page.save_resize_html("page.html", cfg_file="chart_config.json", dest="my_charts.html")
Beispiel #5
0
def test_page_resize():
    page = Page()
    content = page.save_resize_html(
        cfg_dict=[{"cid": "xxx", "width": 100, "height": 100, "top": 100, "left": 100}]
    )
    assert_not_in(".resizable()", content)
    assert_not_in(".draggable()", content)
Beispiel #6
0
def save_resize_html():
    """组合图"""
    page = Page(layout=Page.DraggablePageLayout)
    page.add(
        industry_run(),
        hot_city_run(),
        education_run(),
        get_charts_run(),
        welfared_word_run()
    )
    # page.render('./html/resize_render.html')
    # str : 默认为save_resize_html : 生成的原html文件,该/html/resize_render.html为组合好的文件
    # cfg_file : 第二步下载的配置文件
    # dest : 新html文件路径resize_render.html, 可修改文件
    # str : 为原文件  cfg_file: json格式的文件 dest为新生成的文件
    page.save_resize_html('./html/resize_render.html', cfg_file='./json/chart_config.json', dest='./html/Bi_render.html')

    return page
Beispiel #7
0
def generate_page_layout(date, data):
    '''
    先生成一个layout
    '''
    # 挑选一个小时的数据先生成layout
    sankey_data = data['poi_pair'][20]
    orderNums_24 = data['order_num']
    distanceNum = data['distance'][20]
    waitTimeNum = data['wait_time'][20]
    normalTimeNum = data['normal_time'][20]

    time_str = hour_24_list[20]
    page = get_chart_of(date, time_str, sankey_data, orderNums_24, distanceNum,
                        waitTimeNum, normalTimeNum)
    page.render('sankey_layout.html')
    Page.save_resize_html("sankey_page_.html",
                          cfg_file="chart_config.json",
                          dest="page_new_charts.html")
Beispiel #8
0
def draw_time_line(date, data):
    sankey_data = data['poi_pair']
    orderNums_24 = data['order_num']
    distanceNum_list = data['distance']
    waitTimeNum_list = data['wait_time']
    normalTimeNum_list = data['normal_time']

    # 可视化
    for i in range(24):
        sankey_data_i = sankey_data[i]
        distanceNum_i = distanceNum_list[i]
        waitTimeNum_i = waitTimeNum_list[i]
        normalTimeNum_i = normalTimeNum_list[i]

        hour_i = hour_24_list[i]
        hour_i_chart = get_chart_of(date, hour_i, sankey_data_i, orderNums_24,
                                    distanceNum_i, waitTimeNum_i,
                                    normalTimeNum_i)

        hour = hour_i.split(":")[0]
        hour_i_chart.render('sankey_' + hour + '.html')
        Page.save_resize_html('sankey_' + hour + '.html',
                              cfg_file="chart_config.json",
                              dest=date + '_sankey_' + hour + '.html')
Beispiel #9
0
a = (Map().add("累计确诊", [list(z) for z in zip(data2_list, data3_list)],
               "china").set_global_opts(
                   title_opts=opts.TitleOpts(),
                   visualmap_opts=opts.VisualMapOpts(max_=200),
               ))

b = (Map().add("死亡", [list(z) for z in zip(data2_list, data4_list)],
               "china").set_global_opts(
                   title_opts=opts.TitleOpts(),
                   visualmap_opts=opts.VisualMapOpts(max_=200),
               ))

c = (Map().add("治愈", [list(z) for z in zip(data2_list, data5_list)],
               "china").set_global_opts(
                   title_opts=opts.TitleOpts(),
                   visualmap_opts=opts.VisualMapOpts(max_=200),
               ))

page = Page(layout=Page.DraggablePageLayout)
page.add(
    a,
    b,
    c,
)
# 先生成render.html文件
# page.render()
#完成上一步之后把 page.render()这行注释掉
# 然后循行这下面
Page.save_resize_html("render.html",
                      cfg_file="chart_config.json",
                      dest="my_test.html")
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = 'QiuZiXian'  http://blog.csdn.net/qqzhuimengren/   [email protected]
# @time          :2020/9/7  19:21
# @abstract    :

from pyecharts.charts import Page
Page.save_resize_html("render.html", cfg_file='./chart_config.json', dest="new_charts.html")





# import pyecharts
#
# print(pyecharts.__version__)
Beispiel #11
0

#get_today_no_infect_gauge().render("today_no_infect_gauge.html")

while True:
    main_page = Page(layout=Page.DraggablePageLayout)
    main_page.add(
        get_total_confirm_map(),
        get_national_heal_rate_liquid(),
        get_national_death_rate_liquid(),
        get_today_confirm_gauge(),
        get_today_no_infect_gauge(),
    )
    main_page.render('main_page_temp.html')
    Page.save_resize_html('main_page_temp.html',
                          cfg_file='./config_json/main_page.json',
                          dest='./templates/main_page.html')
    now_page = Page(layout=Page.DraggablePageLayout)
    now_page.add(get_now_confirm_map(), get_now_confirm_pie())
    now_page.render('now_page_temp.html')
    Page.save_resize_html('now_page_temp.html',
                          cfg_file='./config_json/now_page.json',
                          dest='./templates/now_page.html')
    heal_page = Page(layout=Page.DraggablePageLayout)
    heal_page.add(get_national_heal_rate_liquid(), get_total_heal_rate_bar())
    heal_page.render('heal_page_temp.html')
    Page.save_resize_html('heal_page_temp.html',
                          cfg_file='./config_json/heal_page.json',
                          dest='./templates/heal_page.html')
    death_page = Page(layout=Page.DraggablePageLayout)
    death_page.add(get_national_death_rate_liquid(),
Beispiel #12
0
def page_fun():
    line = Line().add_xaxis(Faker.choose()).add_yaxis(
        series_name="xx1",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=opts.ItemStyleOpts(color=Faker.rand_color())).add_yaxis(
            series_name="xx2",
            y_axis=Faker.values(1, 100),
            itemstyle_opts=opts.ItemStyleOpts(
                color=Faker.rand_color())).set_global_opts(
                    title_opts=opts.TitleOpts(title="主标题",
                                              subtitle="副标题",
                                              pos_left="10%"),
                    legend_opts=opts.LegendOpts(pos_left="40%"),
                )
    bar = Bar().add_xaxis(Faker.choose()).add_yaxis(
        series_name="柱1",
        y_axis=Faker.values(1, 100),
        itemstyle_opts=opts.ItemStyleOpts(color=Faker.rand_color())).add_yaxis(
            series_name="柱2",
            y_axis=Faker.values(1, 100),
            itemstyle_opts=opts.ItemStyleOpts(
                color=Faker.rand_color())).set_global_opts(
                    title_opts=opts.TitleOpts(title="主标题",
                                              subtitle="副标题",
                                              pos_left="10%"),
                    legend_opts=opts.LegendOpts(pos_left="40%"),
                )
    pie = Pie().add(
        series_name="饼图名称",
        data_pair=[list(z) for z in zip(Faker.choose(), Faker.values())],
    ).set_series_opts(label_opts=opts.LabelOpts(
        formatter="{b}: {c}",
        color=Faker.rand_color(),
    )).set_global_opts(
        title_opts=opts.TitleOpts(title="主标题",
                                  subtitle="副标题",
                                  pos_left="10%",
                                  pos_top="10%"),
        legend_opts=opts.LegendOpts(pos_left="30%", pos_top="10%"),
    )
    map = Map().add(
        series_name="全国疫情数据",
        data_pair=[list(z) for z in zip(Faker.provinces, Faker.values())],
        maptype="china").set_series_opts(label_opts=opts.LabelOpts(
            color=Faker.rand_color(), )).set_global_opts(
                title_opts=opts.TitleOpts(title="主标题",
                                          subtitle="副标题",
                                          pos_left="10%",
                                          pos_top="10%"),
                legend_opts=opts.LegendOpts(pos_left="30%", pos_top="10%"),
                visualmap_opts=opts.VisualMapOpts(),
            )

    # 首先用 Page 生成可拖动的多图表页面
    # Page(layout=Page.DraggablePageLayout).add(
    #     line, bar, pie, map
    # ).render(path="D:/temp/pyecharts_page.html");
    # 打开多图表页面,拖动图表到合适的位置,保存设置为 json 文件
    # 指定原始文件、配置文件和输出文件,生成拖动后的多图表文件
    Page.save_resize_html(source="D:/temp/pyecharts_page.html",
                          cfg_file="D:/temp/chart_config.json",
                          dest="D:/temp/pyecharts_page_resize.html")
Beispiel #13
0
             yaxis_opts=opts.AxisOpts(
                 type_="value",
                 axistick_opts=opts.AxisTickOpts(is_show=True),
                 splitline_opts=opts.SplitLineOpts(is_show=True),
                 name='评分'),
             tooltip_opts=opts.TooltipOpts(is_show=False),
         ))
    c.render('人均消费与综合评分散点.html')
    return c


# # 仪表盘

# In[120]:

from pyecharts.charts import Page


def page_draggable_layout():
    page = Page(layout=Page.DraggablePageLayout)
    page.add(geo(), pie(), bar(), pie_circle(), bar_reserve(), worldcloud(),
             heat_corr(), scatter())
    page.render('page.html')


if __name__ == "__main__":
    # page_draggable_layout()
    Page.save_resize_html('page.html', cfg_file='page.json', dest='仪表盘.html')

# In[ ]:
        # education_salary_chart(df)  # 各学历对应的平均工资水平(单位:千/月)
        # background_salary_chart(df)  # 各工作经验对应的平均薪资水平(单位:千/月)
        # field_chart(df)     # 企业领域统计
        # # data_show(df)       # 主要数据展示
        # #
        # setword1()
        # setword2()
        # setrose()

        # page = Page(layout=Page.DraggablePageLayout)
        # page.add(title(), data_show1(), data_show2(df), data_show3(), data_show4(df), company_type_chart(df), company_size_chart(df), background_chart(df), workarea_chart(df), education_chart(df), workarea_salary_chart(df), education_salary_chart(df), background_salary_chart(df), field_chart(df),  setword1(), setword2(), setrose())
        # page.render("test.html")
        # 格式化Page
        Page.save_resize_html(
            "test.html",
            cfg_file="chart_config.json",
            dest="report.html",
        )

    with open("report.html", "r+", encoding='utf-8') as html:
        html_bf = BeautifulSoup(html, 'lxml')
        body = html_bf.find("body")
        body["style"] = "background-color:#333333;"  # 改变背景色
        html_new = str(html_bf)
        # print(html_bf)
        html.seek(0, 0)
        # file.seek()
        # 方法标准格式是:file.seek(offset, whence)
        # offset:开始的偏移量,也就是代表需要移动偏移的字节数
        # whence:给offset参数一个定义,表示要从哪个位置开始偏移;0代表从文件开头开始算起,1代表从当前位置开始算起,2代表从文件末尾算起。whence值为空没设置时会默认为0。
        html.truncate()  # 用于截断文件
Beispiel #15
0
def test_page_cfg_type():
    page = Page()
    page.save_resize_html()
Beispiel #16
0
def event_chain_temp(request):
    global frames
    global chains
    global chainIdx
    global date_begin_old
    global date_end_old
    global timeInterval_old
    context = {}
    '''
    grid = (
        Grid()
        .add(get_line(), grid_opts=opts.GridOpts(pos_left="55%"))
        .add(get_mymap(), grid_opts=opts.GridOpts(pos_right="50%"))
    )
    '''
    request.encoding = 'utf-8'
    if (date_begin_old == ""):
        date_begin = "2015/11/10"  #初始
        date_begin = "2015/11/10 00:00:00"
    if (date_end_old == ""):
        date_end = "2015/11/12"
        date_end = "2015/11/12 00:00:00"
    timeInterval = 24
    num_frames = 5
    #如果有查询序号就执行查看event页面
    if 'chainIdx' in request.GET and request.GET['chainIdx']:
        print("bigin to url: chain")
        chainIdx = int(request.GET['chainIdx']) - 1  #下标从0开始,所以要减一
        return event(request)
    if 'date_begin' in request.GET and request.GET['date_begin']:
        context["last_date_begin"] = request.GET['date_begin']
        date_begin = request.GET['date_begin'] + " " + "00:00:00"
        date_begin = date_begin.replace("-", "/")
        print("databigin:{}".format(date_begin))
    if 'date_end' in request.GET and request.GET['date_end']:
        context["last_date_end"] = request.GET['date_end']
        date_end = request.GET['date_end'] + " " + "00:00:00"
        date_end = date_end.replace("-", "/")
        print("dataend:{}".format(date_end))
    #if(date_end="")
    num_frames = int((time2timestamp(date_end) - time2timestamp(date_begin)) /
                     (3600 * timeInterval))
    print("num_frames:{}".format(num_frames))
    #如果获得经度和维度,就可以在process.detect中删除不在这经度和维度范围内的数据 to do
    if (date_begin_old != date_begin or date_end_old != date_end
            or timeInterval_old != timeInterval):  #如果有一个更新
        frames = process.detect(date_begin, 3600 * timeInterval, num_frames)
        #line_data = frames
        #不论是全城还是局部事件都要对chain做预处理操作,并且只返回前top20的事件链
        chains = process.match(frames)
    chains, bursty_dict = preprocess_chains(
        chains, event_type)  #对chains做一些处理按bursty、glbal/local处理
    date_begin_old = date_begin
    date_end_old = date_end
    timeInterval_old = timeInterval
    #print(chain)
    line_data, themeriver_data, themeriver_lengend, pos, words = process_data(
        frames, chains, bursty_dict)
    page = Page()  #如果要让地图正常显示必须Page里配置为空
    mymap = get_bmap(pos)
    #mymap = get_mymap(message)
    mymap.chart_id = "bmap_1"  #
    wordcloud = get_wordcloud(words)
    wordcloud.chart_id = "wordcloud_1"
    myline = get_line(line_data)
    myline.chart_id = "line_1"
    mythemeriver = get_themeriver(themeriver_data, themeriver_lengend,
                                  num_frames)
    mythemeriver.chart_id = "themeriver_1"

    # 需要自行调整每个 chart 的 height/width,显示效果在不同的显示器上可能不同
    page.add(mymap)
    page.add(wordcloud)
    page.add(myline)

    page.add(mythemeriver)
    page.render(template_name="simple_page_test.html")
    Page.save_resize_html("render.html",
                          cfg_file="./demo/chart_config.json",
                          dest="./demo/templates/my_new_charts.html")
    return render(request, "my_new_charts.html")
Beispiel #17
0
def analyse_data():
    client = pymongo.MongoClient("mongodb://localhost:27017/")
    db = client['testcomment']
    col = db[collection_name]
    result = col.find({}, {'_id': 0, '评论日期': 1, "评论": 1, "追加评论": 1})
    comment_list = []
    date_list = []
    date_dic = {}
    for date in result:  # 把日期和评论字数放入列表中
        date_list.append(date['评论日期'])
        comment_list.append(len(date['评论']))
        if len(date['追加评论']) != 0:
            comment_list.append(len(date['追加评论']))
    for date in date_list:  # 统计日销量
        if date in date_dic:
            date_dic[date] += 1
        else:
            date_dic[date] = 1
    # date_list = list(date_dic)
    data_dic = {}
    arr = np.array(list(date_dic))  # 给日期排序
    date_list = arr[np.argsort(
        [datetime.strptime(i, '%m.%d') for i in list(date_dic)])].tolist()
    for i in date_list:
        data_dic[i] = date_dic[i]
    # s = pd.Series(data_dic)  # series表示一维数组
    # comment_list.sort()
    word_num_dic = {
        '0-10': 0,
        '11-20': 0,
        '21-30': 0,
        '31-40': 0,
        '41-50': 0,
        '51-60': 0,
        '61-70': 0,
        '71-80': 0,
        '91-100': 0,
        '101-110': 0,
        '111-120': 0,
        '121-130': 0,
        '131-140': 0,
        '141-150': 0,
        '151-160': 0,
        '161-170': 0,
        '171-180': 0,
        '181-190': 0,
        '191-200': 0,
        '201-300': 0
    }
    for i in word_num_dic:  # 统计字数
        for j in comment_list:
            if j >= int(i.split('-')[0]) and j <= int(i.split('-')[-1]):
                word_num_dic[i] += 1
    # print(ndic)
    bar1 = (  # 生成柱状图
        Bar().add_xaxis(list(data_dic.keys())).add_yaxis(
            '商品', list(data_dic.values())).set_global_opts(  # 设置全局参数
                title_opts=opts.TitleOpts(title='商品日销量'),
                yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(
                    is_show=True)),  # 添加纵坐标标线
                datazoom_opts=[
                    opts.DataZoomOpts(range_start=10,
                                      range_end=80,
                                      is_zoom_lock=False)
                ]  # 添加滑动条
            ))
    bar1.chart_id = '6f180e81787a48539de004c1eb847c1e'
    bar2 = (  # 生成柱状图
        Bar({
            'theme': ThemeType.MACARONS
        }).add_xaxis(list(word_num_dic.keys())).add_yaxis(
            '商品', list(word_num_dic.values())).set_global_opts(  # 设置全局参数
                title_opts=opts.TitleOpts(title='字数统计'),
                yaxis_opts=opts.AxisOpts(splitline_opts=opts.SplitLineOpts(
                    is_show=True)),
                datazoom_opts=[
                    opts.DataZoomOpts(range_start=10,
                                      range_end=80,
                                      is_zoom_lock=False)
                ]))
    bar2.chart_id = '9a412341322b4d92bba49e3fd932a7f0'
    pie1 = (  # 生成柱状图
        Pie().add(series_name='用户身份',
                  data_pair=[('超级会员', vip_num), ('普通用户', comment_num - vip_num)
                             ]).set_global_opts(  # 设置全局参数
                                 title_opts=opts.TitleOpts(title='超级会员比例'), ))
    pie1.chart_id = '7ed5d413532646909f127fd36f584081'
    pie2 = (  # 生成柱状图
        Pie(init_opts=opts.InitOpts(theme=ThemeType.WESTEROS)).add(
            series_name='有无图片',
            data_pair=[('有图评价', img_num), ('无图评价', comment_num - img_num)
                       ]).set_global_opts(  # 设置全局参数
                           title_opts=opts.TitleOpts(title='有图评价比例'), ))
    pie2.chart_id = 'aa3f038854e144dbaa6e9892d4ca31fc'
    pie3 = (  # 生成柱状图
        Pie(init_opts=opts.InitOpts(theme=ThemeType.INFOGRAPHIC)).add(
            series_name='是否追加',
            data_pair=[('追加评价', append_num), ('普通评价', comment_num - append_num)
                       ]).set_global_opts(  # 设置全局参数
                           title_opts=opts.TitleOpts(title='追加评价比例'), ))
    pie3.chart_id = '235863de6fe74a2aa9273e30ed4a7f66'
    page = Page(page_title='评论分析报告')
    page.add(bar1, bar2, pie1, pie2, pie3)
    page.render()
    Page.save_resize_html(cfg_file=r'chart_config.json')
    with open('resize_render.html', 'r+', encoding='utf-8') as f:
        f.seek(573)
        html = f.read()
        f.seek(573)
        f.write('   <h1>评价分析结果:</h1>\n    <p>' + content + '</p>\n ')
        f.write(html)
    print(
        r'已完成分析   请打开E:\Python\learnPython\testspider\FinalProject\resize_render.html查看分析结果'
    )
Beispiel #18
0
                                      textstyle_opts=opts.TextStyleOpts(
                                          color="#FFFFFF"))).set_series_opts(
                                              label_opts=opts.LabelOpts(
                                                  formatter="{b}:{c}")))

    return c


# 2018年报名数、招生数、录取数漏斗图
def setfunnel():
    data = [['报名人数/万', 238], ['招生人数', 85.7966], ['录取人数', 76.2]]

    c = (Funnel(init_opts=opts.InitOpts(width="300x", height="600px")).add(
        series_name="",
        data_pair=data,
        gap=2,
        tooltip_opts=opts.TooltipOpts(trigger="item",
                                      formatter="{a} <br/>{b} : {c}%"),
        label_opts=opts.LabelOpts(is_show=True, position="inside"),
        itemstyle_opts=opts.ItemStyleOpts(border_color="#fff", border_width=1),
    ).set_global_opts(title_opts=opts.TitleOpts(title="2018年报名数、招生数、录取数漏斗图")))
    return c


page = Page(page_title="数智考研", layout=Page.DraggablePageLayout)
page.add(setmap(), setrose(), setbar(), setpai(), setfunnel())
# page.render("test.html")
Page.save_resize_html("test.html",
                      cfg_file="chart_config1.json",
                      dest="数智考研大屏可视化系统.html")
Beispiel #19
0
    '15-24 years', '25-34 years', '35-54 years', '55-74 years', '75+ years'
]
date_value = date.iloc[[i for i in range(len(date))], [0, 1, 2, 3, 6]]
date_value = np.array(date_value).tolist()

for i in date_value:
    if i[0] in country20 and i[3] != '5-14 years' and i[2] == 'male':
        suicides.append(i)
    if i[2] == "male":
        male.append(i)
    if i[2] == "female":
        female.append(i)
suicides.sort(key=lambda x: (x[0], x[1], x[3]))
whileyear = []
for i in year:
    year_suicides = []
    for j in suicides:
        if i == j[1]:
            year_suicides.append(j[4])
    whileyear.append(year_suicides)
shujizonghe = dict(zip(year, whileyear))
npshuju = np.array(whileyear)

#第二次运行时块注释以下内容
""" if __name__=="__main__":
    page_layout() """

#第二次运行程序是取消以下注释
Page.save_resize_html("page.html",
                      cfg_file="chart_config.json",
                      dest="page_1.html")