コード例 #1
0
def month_loan_income():
    '''生成本月放款收入图表'''

    # X轴label
    attr = dates

    # 图表数据
    v1 = list(np.random.randint(2000, 6000, len(dates)) / 10)

    # 生成图表实例
    chart = Line("本月放款收入趋势(单位:万)", background_color=BACKGROUND_COLOR, width="100%")

    # 使用暗色主题
    chart.use_theme('dark')

    # 载入默认设置并差异化更新
    chart_kwargs = DEFAULT_KWARGS
    chart_kwargs.update({
        "xaxis_interval":0,
        "mark_line": ["average"],
        "is_smooth": True,
        "is_fill": True,
        "area_opacity": 0.3,
        "yaxis_min": "dataMin",
        "xaxis_rotate":90,
    })

    # 添加数据
    chart.add("放款收入", attr, v1, **chart_kwargs)

    return chart
コード例 #2
0
def monthly_sign():
    '''生成每月签约率图表'''

    # X轴label
    attr = months

    # 图表数据
    v1 = list(np.random.randint(700, 800, len(months)) / 10)

    # 生成图表实例
    chart = Line("每月签约率趋势", background_color=BACKGROUND_COLOR, width="100%")

    # 使用暗色主题
    chart.use_theme('dark')

    # 载入默认设置并差异化更新
    chart_kwargs = DEFAULT_KWARGS
    chart_kwargs.update({
        "xaxis_interval":0,
        "mark_line": ["average"],
        "is_smooth": True,
        "is_fill": True,
        "area_opacity": 0.3,
        "yaxis_min": "dataMin",
        "yaxis_formatter": "%",
        "label_formatter": "{c}%",
        "xaxis_rotate":90,
    })

    # 添加数据
    chart.add("签约率", attr, v1, **chart_kwargs)

    return chart
コード例 #3
0
def month_apply_bill():
    '''生成本月申请件数图表'''

    # X轴label
    attr = dates

    # 图表数据
    v1 = list(np.random.randint(20, 100, len(dates)))

    # 生成图表实例
    chart = Line("本月申请件数趋势", background_color=BACKGROUND_COLOR, width="100%")

    # 使用暗色主题
    chart.use_theme('dark')

    # 载入默认设置并差异化更新
    chart_kwargs = DEFAULT_KWARGS
    chart_kwargs.update({
        "xaxis_interval":0,
        "mark_line": ["average"],
        "is_smooth": True,
        "is_fill": True,
        "area_opacity": 0.3,
        "xaxis_rotate":90,
    })

    # 添加数据
    chart.add("申请件数", attr, v1, **chart_kwargs)

    return chart
コード例 #4
0
def monthly_loan_amount():
    '''生成每月放款金额图表'''

    # X轴label
    attr = months

    # 图表数据
    v1 = list(np.random.randint(60000, 300000, len(months)) / 10)

    # 生成图表实例
    chart = Line("每月放款金额趋势", background_color=BACKGROUND_COLOR, width="100%")

    # 使用暗色主题
    chart.use_theme('dark')

    # 载入默认设置并差异化更新
    chart_kwargs = DEFAULT_KWARGS
    chart_kwargs.update({
        "xaxis_interval":0,
        "mark_line": ["average"],
        "is_smooth": True,
        "is_fill": True,
        "area_opacity": 0.3,
        "xaxis_rotate":90,
    })

    # 添加数据
    chart.add("放款金额", attr, v1, **chart_kwargs)

    return chart
コード例 #5
0
 def get_mem_data():
     base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     performance_data = os.path.join(base_dir, 'data')
     image_path = performance_data + "\\result.png"
     html_path = "%s\\memory_report.html" % (performance_data)
     hfile = ('%s\\memory_data.txt' % (performance_data))
     fp = open(hfile, "r")
     # fp = open(r'D:\moxiu\youyang\data\xin.txt', 'r')
     meminfo_data = fp.readlines()
     case_name_list = []
     for i in range(len(meminfo_data)):
         j = meminfo_data[i].replace('\n', '').split(',')
         case_name_list.append(j[0:1][0])
     heap_size_list = []
     for i in range(len(meminfo_data)):
         j = meminfo_data[i].replace('\n', '').split(',')
         heap_size_list.append(float(j[1:2][0]))
     heap_alloc_list = []
     for i in range(len(meminfo_data)):
         j = meminfo_data[i].replace('\n', '').split(',')
         heap_alloc_list.append(float(j[2:3][0]))
     heap_free_list = []
     for i in range(len(meminfo_data)):
         j = meminfo_data[i].replace('\n', '').split(',')
         heap_free_list.append(float(j[3:4][0]))
     bar = Line("有样__内存数据图形报表", "图表纵轴为数据大小,横轴为case名称,直线为平均值")
     bar.add("heap_size",
             case_name_list,
             heap_size_list,
             label_color=['#B22222'],
             mark_line=["average"],
             mark_point=["max", "min"],
             xaxis_interval=0,
             xaxis_rotate=90)
     bar.add("heap_alloc",
             case_name_list,
             heap_alloc_list,
             label_color=['#008080'],
             mark_line=["average"],
             mark_point=["max", "min"],
             xaxis_interval=0,
             xaxis_rotate=90)
     bar.add("heap_free",
             case_name_list,
             heap_free_list,
             label_color=['#483D8B'],
             mark_line=["average"],
             mark_point=["max", "min"],
             xaxis_interval=0,
             xaxis_rotate=90)
     bar.use_theme("vintage")
     base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     performance_data = os.path.join(base_dir, 'data')
     bar.render('%s\\memory_report.html' % (performance_data))
     make_a_snapshot(html_path, image_path)
     im = Image.open(image_path)
     out = im.resize((800, 400), Image.ANTIALIAS)
     out.save(image_path)
コード例 #6
0
def drawLine(title, data, savepath='./results'):
	if not os.path.exists(savepath):
		os.mkdir(savepath)
	line = Line(title, title_pos='center')
	line.use_theme('purple-passion')
	attrs = [i for i, j in data.items()]
	values = [j for i, j in data.items()]
	line.add('', attrs, values, xaxis_rotate=30, yaxis_rotate=30, mark_point=['max', 'min'])
	line.render(os.path.join(savepath, '%s.html' % title))
コード例 #7
0
ファイル: main.py プロジェクト: P79N6A/python_learning
def caculate_mi_list(dir_path):
    files = common.get_filelist(dir_path)
    res = _caculate_mi_list(files[3], files[0:10])
    data_a, data_b = Bar.cast(res)
    print data_a
    print data_b
    bar = Line("甜甜的实验", "二哥出品")
    bar.use_theme('vintage')
    bar.add("数据", data_a, data_b)
    bar.render()
    return
コード例 #8
0
def single_line_maker(start, end):
    # 子函数:获取数据
    # 己函数:把数据放到 Line 中

    def lining_single():
        records = get_info(start, end)

        stamps = []
        cpu_percents = []
        cpu_temps = []
        free_rams = []
        free_disks = []
        for i in range(start + 60, end, 60):
            stamps.append(time.strftime('%H:%M', time.gmtime(i + 28800)))
            if i // 60 in records:
                cpu_percents.append(records[i // 60].cpu_percent)
                cpu_temps.append(records[i // 60].cpu_temp)
                free_rams.append(records[i // 60].free_ram)
                free_disks.append(records[i // 60].free_disk)
            else:
                cpu_percents.append('')
                cpu_temps.append('')
                free_rams.append('')
                free_disks.append('')

        return stamps, cpu_percents, cpu_temps, free_rams, free_disks

    line_cpu = Line(width=width, height=height, title='CPU 监控')
    line_space = Line(width=width, height=height, title='DISK 监控')
    if time.localtime().tm_hour >= 21 or time.localtime().tm_hour <= 6:
        line_cpu.use_theme('dark')
        line_space.use_theme('dark')
    stamps, cpu_percents, cpu_temps, free_rams, free_disks = lining_single()
    line_cpu.add('使用率',
                 stamps,
                 cpu_percents,
                 mark_line=["average"],
                 line_width=2)
    line_cpu.add('温度', stamps, cpu_temps, mark_point=["max"], line_width=2)
    line_space.add('剩余内存',
                   stamps,
                   free_rams,
                   mark_line=["average"],
                   line_width=2)
    line_space.add('剩余磁盘', stamps, free_disks, line_width=2)

    js_list = list(
        set(line_cpu.get_js_dependencies() + line_space.get_js_dependencies()))

    return line_cpu, line_space, js_list
コード例 #9
0
def picture(table, time, data):
    # print(time)
    attr = time
    line = Line(str(table + "发展趋势"), background_color='white')
    # print("theme shape %s"%(data.shape[0]))
    for i in range(0, data.shape[0]):
        line.add("第%s主题" % (i),
                 attr,
                 data[i].tolist(),
                 is_random=True,
                 is_label_show=True,
                 is_smooth=False)
        # print(data[i].tolist())
    line.use_theme("vintage")
    path = table + ".html"
    line.render(path)
コード例 #10
0
def CPUintoChart(cpufile, name):
    row = []
    row_cpu = 1
    for line in cpufile:
        if row_cpu%2 == 1:
            line = line.split(' ')
            cpudata = [line[i] for i in (2, 4, 7)]
            row.append(cpudata)
        row_cpu += 1
    data = []
    for i in row:
        if i[1][0].isdigit() is False:
            pass
        else:
            data.append(i)
    package = []
    user = []
    kernel = []
    for j, k, l in data:
        package.append(j[0:-1])
        user.append(k[0:-1])
        kernel.append(l[0:-1])
    package.insert(0, 'package')
    user.insert(0, 'user')
    kernel.insert(0, 'kernel')
    print(package)
    print(user)
    print(kernel)
    id = []
    for i in range(len(package) - 1):
        id.append(i)
    bar = Line(f"{name}__CPU数据图形报表", "图表纵轴为数据大小,横轴为时间节点,直线为平均值")
    bar.add("package", id, package[1:], label_color=['#800080'], mark_line=["average"],
            mark_point=["max", "min"], xaxis_interval=0, xaxis_rotate=90)
    bar.add("user", id, user[1:], label_color=['#0000FF'], mark_line=["average"],
            mark_point=["max", "min"], xaxis_interval=0, xaxis_rotate=90)
    bar.add("kernel", id, kernel[1:], label_color=['#2E8B57'], mark_line=["average"],
            mark_point=["max", "min"], xaxis_interval=0, xaxis_rotate=90)
    bar.use_theme("vintage")
    t = time.time()
    bar.render('%s\\cpu%s.html' % (setting.data, int(t)))
コード例 #11
0
def dashboard_loan_amount():
    '''添加放款金额轮播图表'''

    # 生成图表实例
    timeline = Timeline(is_auto_play=True, timeline_bottom=0, width="100%")

    # 使用暗色主题
    timeline.use_theme('dark')

    # 生成每个月份的图表
    for month in months:
        
        # X轴label
        n_day_in_month = pd.Period(month+"-01").days_in_month
        attr = list(range(1,n_day_in_month+1))

        # 图表数据
        v1 = list(np.random.randint(2000, 10000, n_day_in_month) / 10)

        # 生成图表实例
        chart = Line("%s月放款金额走势图" %month,"当月放款总金额为%.2f万" %np.sum(v1), background_color=BACKGROUND_COLOR, width="100%")

        # 使用暗色主题
        chart.use_theme('dark')

        # 载入默认设置并差异化更新
        chart_kwargs = DEFAULT_KWARGS
        chart_kwargs.update({
            "xaxis_interval":0,
            "mark_line": ["average"],
            "is_smooth": True,
            "is_fill": True,
            "area_opacity": 0.3,
        })

        # 添加数据
        chart.add("放款金额", attr, v1, **chart_kwargs)

        timeline.add(chart,month)
    
    return timeline
コード例 #12
0
ファイル: chart.py プロジェクト: mgbin088/GWeb
def history_chart():
    BOTTOM = 1
    TOP = 200
    XAXIS_COUNT = 10
    XAXIS_INTERVAL = ((TOP - BOTTOM) // XAXIS_COUNT) - 1
    chart = Line(title="Python History Ratings",
                 subtitle="Source: www.tiobe.com",
                 title_color="DarkSlateGray",
                 background_color="Azure",
                 width=1000,
                 height=500,
                 page_title="Python Ratings History")

    chart.use_theme('walden')

    df = pd.read_csv(path.join(DATA_PATH, "pythonratehistory.csv"), sep=",")
    TOP = len(df.Python)
    values = list(df.Python[BOTTOM:TOP])
    title = list(df.Date[BOTTOM:TOP])
    chart.add(
        name="Rating",
        x_axis=title,
        y_axis=values,
        yaxis_name="Rating (%)",
        xaxis_name="Date",
        # xaxis_interval=XAXIS_INTERVAL,
        # is_label_show=True,
        # label_formatter="{a}%",
        is_legend_show=False,
        is_smooth=True,
        is_symbol_show=False,
        line_width=4,
        mark_point=['max'],
        mark_point_symbolsize=60,
        mark_line=["max", "min"],
        is_datazoom_show=True,
        is_visualmap=True,
        visual_range=[0, 8])
    return chart
コード例 #13
0
def MemintoChart(memfile, name):
    native = subprocess.getoutput(' grep "Native Heap " %s |awk \'{print $3}\' ' % memfile).split('\n')
    native.insert(0, 'Native')
    print(native)
    dalvik = subprocess.getoutput(' grep "Dalvik Heap " %s |awk \'{print $3}\' '% memfile).split('\n')
    dalvik.insert(0, 'Dalvik')
    print (dalvik)
    total = subprocess.getoutput('grep "TOTAL:" %s |awk \'{print $2}\' ' % memfile).split('\n')
    total.insert(0, 'Total')
    id = []
    for i in range(len(native)-1):
        id.append(i)
    bar = Line(f"{name}__内存数据图形报表", "图表纵轴为数据大小,横轴为时间节点,直线为平均值")
    bar.add("native", id, native[1:], label_color=['#800080'], mark_line=["average"],
            mark_point=["max", "min"], xaxis_interval=0, xaxis_rotate=90)
    bar.add("dalvik", id, dalvik[1:], label_color=['#0000FF'], mark_line=["average"],
            mark_point=["max", "min"], xaxis_interval=0, xaxis_rotate=90)
    # bar.add("total", id, total[1:], label_color=['#2E8B57'], mark_line=["average"],
    #         mark_point=["max", "min"], xaxis_interval=0, xaxis_rotate=90)
    bar.use_theme("vintage")
    t = time.time()
    bar.render('%s\\memory%s.html' % (setting.data, int(t)))
コード例 #14
0
    ['一星', '二星', '三星', '四星', '五星'],
    scores.values,
    is_random=True,
    is_legend_show=False,  #不显示图例
    is_label_show=True  #显示标签(各个属性的数据信息)
)
pie1.render('评分.html')

#评论数
datas['dates'] = datas['date'].apply(
    lambda x: pd.Timestamp(x).date())  #注意,此处为dates,区别原date
datas['hour'] = datas['date'].apply(lambda x: pd.Timestamp(x).time().hour)
num_of_date = datas.author.groupby(datas.dates).count()  #每天有多少作者评论
#评论数时间分布
chart = Line("评论数时间分布")
chart.use_theme('dark')
chart.add(
    '评论时间分布',
    num_of_date.index,
    num_of_date.values,
    is_fill=True,  #填充曲线所绘制面积
    line_opacity=0.2,  #折线透明度
    area_opacity=0.4,  #区域透明度
    symbol=None,
)
chart.render('评论时间分布.html')
#时间分布
num_of_hour = datas.author.groupby(datas.hour).count()  #各个小时段有多少作者评论
chart = Line("评论日内时间分布")
chart.use_theme('dark')
chart.add('评论日内时间分布',
コード例 #15
0
#     is_random=True,
#     #    radius=[30, 75],
#     is_legend_show=False,
#     is_label_show=True
# )
# pie1.render('scores.html')

###########################################################################
# 评论时间分布
data['dates'] = data.date.apply(lambda x: pd.Timestamp(x).date())
data['time'] = data.date.apply(lambda x: pd.Timestamp(x).time().hour)
# print(data.author)
num_date = data.author.groupby(data['dates']).count()

chart = Line("评论数时间分布")
chart.use_theme('dark')
chart.add('评论时间',
          num_date.index,
          num_date.values,
          is_fill=True,
          line_opacity=0.2,
          area_opacity=0.4,
          symbol=None)

chart.render('comment_time_stamp.html')

# 好评字数分析
datalikes = ['num', 'likes']
datalikes = data.loc[data.likes > 5]
datalikes['num'] = datalikes.content.apply(lambda x: len(x))
chart = Scatter("likes")
コード例 #16
0
for i in tokens:
    d[i] = d.get(i,0) + 1

count_list = sorted(d.items(), key=lambda x:x[0], reverse=False)
del count_list[-2]
keyword_list = [k[0] for k in count_list]
k2 = []
for i in keyword_list:
    k2.append(i[0])
#k_list = sorted(k, key=lambda x:x[0], reverse=False)
value_list = [k[1] for k in count_list]
v2 = value_list


line = Line(background_color='#404a59')
line.use_theme('dark')
# is_datazoom_show=True,
line.add('2018',k1,v1,mark_point=['average'], is_smooth=True)
line.add('2019',k2,v2,mark_point=['average'], is_smooth=True)
#line.add('',attr,v1)
#line.render(r"D:\BI大屏\工作经验折线.html")
page.add_chart(line,name="line") 

#=============================================================================

# 漏斗图
from pyecharts import Funnel 
import os as os 
from bs4 import BeautifulSoup  
#=============================================================================
コード例 #17
0
def draw_chan(stock, stock_df):  #
    stock_df_original = stock_df[['open', 'close', 'low', 'high']]
    stock_df_bi = stock_df[(stock_df['tb'] == TopBotType.top) |
                           (stock_df['tb'] == TopBotType.bot)][['chan_price']]
    stock_df_xd = stock_df[(stock_df['xd_tb'] == TopBotType.top) |
                           (stock_df['xd_tb'] == TopBotType.bot)][[
                               'chan_price'
                           ]]

    crp = CentralRegionProcess(stock_df, isdebug=False)
    crp.define_central_region()
    stock_zs_x, stock_zs_y = crp.convert_to_graph_data()

    overlap = Overlap(width=1500, height=600)
    overlap.use_theme("dark")

    kline = Kline("����")
    kline.use_theme("dark")
    kline.add(stock, [str(d) for d in stock_df_original.index],
              stock_df_original.values,
              is_datazoom_show=True,
              datazoom_range=[80, 100],
              xaxis_interval=10,
              xaxis_rotate=30,
              background_color='black')
    overlap.add(kline)

    line_1 = Line()
    line_1.use_theme("dark")
    line_1.add("�ֱ�", [str(d) for d in stock_df_bi.index],
               stock_df_bi.values,
               line_color='yellow',
               is_datazoom_show=True,
               xaxis_interval=10,
               xaxis_rotate=30)
    overlap.add(line_1)

    if stock_df_xd is not None:
        line_2 = Line()
        line_2.use_theme("dark")
        line_2.add("�ֶ�", [str(d) for d in stock_df_xd.index],
                   stock_df_xd.values,
                   line_color='blue',
                   mark_point_symbol="arrow",
                   is_datazoom_show=True,
                   xaxis_interval=10,
                   xaxis_rotate=30)
        overlap.add(line_2)


#     print(stock_zs_x)
#     print(stock_zs_y)

    for i in range(0, len(stock_zs_x), 2):
        line_a = Line()
        line_a.use_theme("dark")
        line_a.add("����", [str(d) for d in stock_zs_x[i:i + 2]],
                   stock_zs_y[i:i + 2],
                   line_color='red',
                   line_width=3,
                   is_step=True,
                   is_label_show=True,
                   is_datazoom_show=True,
                   xaxis_interval=10,
                   xaxis_rotate=30)
        overlap.add(line_a)

    overlap.render('stock_chan.html')
コード例 #18
0
scores = datas.rating.groupby(datas['rating']).count()
# print(scores.index.values)
pie = Pie('《工作细胞》用户评分')
pie.add(
    '',
    ['1星', '2星', '3星', '4星', '5星'],# scores.index.values,
    scores.values,
    center=[50,60],
    is_label_show=True,
)
pie.render('评分.html')

datas['dates'] = datas.ctime.apply(lambda x:pd.Timestamp(datetime.fromtimestamp(x)).date())
num_date = datas.mid.groupby(datas['dates']).count()
line1 = Line('评论数时间分布')
line1.use_theme('dark')
line1.add(
    '',
    num_date.index.values,
    num_date.values,
    is_fill=True,
)
line1.render('评论数时间分布.html')

datas['times'] = datas.ctime.apply(lambda x:pd.Timestamp(datetime.fromtimestamp(x)).time().hour)
num_time = datas.mid.groupby(datas['times']).count()
line2 = Line('评论数日内分布')
line2.use_theme('dark')
line2.add(
    '',
    num_time.index.values,
コード例 #19
0
def group_line_maker(start, end, group_by):
    # 子函数:获取数据
    # 己函数:把数据放到 Line 中

    def lining_grouped():
        records = get_info(start, end)

        stamps = []
        top_list = [[], [], [],
                    []]  # cpu_percents, cpu_temps, free_rams, free_disks
        average_list = [[], [], [],
                        []]  # cpu_percents, cpu_temps, free_rams, free_disks
        bottom_list = [[], [], [],
                       []]  # cpu_percents, cpu_temps, free_rams, free_disks

        tops = [-1000, -1000, -1000, -1000]
        averages = [[], [], [], []]
        bottoms = [1000, 1000, 1000, 1000]

        for i in range(start + 60, end, 60):
            flag = get_stamp(i, group_by)
            if not stamps:
                stamps.append(flag)
                if i // 60 in records:
                    new_info = [
                        records[i // 60].cpu_percent,
                        records[i // 60].cpu_temp, records[i // 60].free_ram,
                        records[i // 60].free_disk
                    ]
                    for ind in range(4):
                        tops[ind] = max(tops[ind], new_info[ind])
                        averages[ind].append(new_info[ind])
                        bottoms[ind] = min(bottoms[ind], new_info[ind])
                else:
                    tops = ['', '', '', '']
                    averages = ['', '', '', '']
                    bottoms = ['', '', '', '']
            elif flag != stamps[-1]:
                stamps.append(flag)
                for ind in range(4):
                    top_list[ind].append(
                        tops[ind] if tops[ind] != -1000 else 0)
                    ind_tmp = sum(averages[ind]) / len(
                        averages[ind]) if averages[ind] else 0
                    average_list[ind].append(round(ind_tmp, 1))
                    bottom_list[ind].append(
                        bottoms[ind] if bottoms[ind] != 1000 else 0)
                tops = [-1000, -1000, -1000, -1000]
                averages = [[], [], [], []]
                bottoms = [1000, 1000, 1000, 1000]
            elif i // 60 in records:
                new_info = [
                    records[i // 60].cpu_percent, records[i // 60].cpu_temp,
                    records[i // 60].free_ram, records[i // 60].free_disk
                ]
                for ind in range(4):
                    tops[ind] = max(tops[ind], new_info[ind])
                    averages[ind].append(new_info[ind])
                    bottoms[ind] = min(bottoms[ind], new_info[ind])

        return stamps[1:], top_list, average_list, bottom_list

    line_cpu = Line(width=width, height=height, title='CPU 监控')
    line_space = Line(width=width, height=height, title='DISK 监控')
    if time.localtime().tm_hour >= 21 or time.localtime().tm_hour <= 6:
        line_cpu.use_theme('dark')
        line_space.use_theme('dark')
    stamps, [cpu_percents_top, cpu_temps_top, _, _], [
        cpu_percents_average, cpu_temps_average, free_rams_average, _
    ], [_, _, free_rams_bottom, free_disks_bottom] = lining_grouped()
    line_cpu.add('使用率峰值',
                 stamps,
                 cpu_percents_top,
                 is_smooth=True,
                 line_width=2)
    line_cpu.add('平均使用率',
                 stamps,
                 cpu_percents_average,
                 is_smooth=True,
                 line_width=2)
    line_cpu.add('温度峰值',
                 stamps,
                 cpu_temps_top,
                 is_smooth=True,
                 mark_line=['max'],
                 line_width=2)
    line_cpu.add('平均温度',
                 stamps,
                 cpu_temps_average,
                 is_smooth=True,
                 line_width=2,
                 legend_top='bottom')
    line_space.add('剩余内存谷值',
                   stamps,
                   free_rams_bottom,
                   is_smooth=True,
                   line_width=2)
    line_space.add('剩余内存均值',
                   stamps,
                   free_rams_average,
                   is_smooth=True,
                   line_width=2)
    line_space.add('剩余磁盘',
                   stamps,
                   free_disks_bottom,
                   is_smooth=True,
                   line_width=2,
                   legend_top='bottom')

    js_list = list(
        set(line_cpu.get_js_dependencies() + line_space.get_js_dependencies()))

    return line_cpu, line_space, js_list
コード例 #20
0
import pyecharts
import numpy as np
import pandas as pd
from pyecharts import Line

if __name__ == '__main__':
    data = np.genfromtxt("1.txt", delimiter="\t")
    shijian = data[:, 0]
    renkou = data[:, 1]
    qiyegeshu = data[:, 2]
    lirun = data[:, -2]
    print(shijian)
    print(renkou)
    print(qiyegeshu)
    line = Line("人口变化趋势与企业活力")
    line.use_theme('roma')
    l = range(9)
    line.add("人口(万人)", l, renkou, is_smooth=True, line_width=3)
    line.add("规模以上工业企业单位数(个)",
             l,
             qiyegeshu,
             is_smooth=True,
             line_color="blue",
             line_width=3)
    line.add("规模以上工业企业利润总额",
             l,
             lirun,
             is_smooth=True,
             line_color="green",
             line_width=3)
    line.add("规模以上工业企业利润总额", shijian, lirun, is_smooth=True)
コード例 #21
0
page.add(pie)
"""评论时间分布"""

# 保留当天时间
datas['dates'] = datas.date.apply(lambda x: pd.Timestamp(x).date())

sum = datas.score.groupby(datas['dates']).sum()
count = datas.score.groupby(datas['dates']).count()

index_per_day = list(sum.index)
values_per_day = list(sum / count)
values_per_day = [int(x) for x in values_per_day]

chart = Line("评分时间分布")
chart.use_theme("dark")

chart.add(
    "评分",
    index_per_day,
    values_per_day,
)

page.add(chart)
"""每日评论数目"""

chart2 = Line("评论数时间分布")
chart2.use_theme("dark")
chart2.add("评论数",
           index_per_day,
           list(count.values),
コード例 #22
0
# 每日平均评分

# 筛选出不为0的行
datas = datas[[int(i) > 0 for i in datas.star]]
datas.star = datas.star.astype(int)

datas["timeT"] = datas.time.apply(lambda x: pd.Timestamp(x).date())

sum = datas.star.groupby(datas['timeT']).sum()
count = datas.star.groupby(datas['timeT']).count()
per_day = sum / count
per_day_list = [int(i) for i in per_day.values]
date_list = sum.index.tolist()

line = Line("每日平均评分")
line.use_theme("dark")
line.add(
    "评分",
    date_list,
    per_day_list,
)

page.add(line)

"每日评论数目"
line2 = Line('每日评论数目')
line2.add(
    "数目",
    date_list,
    sum.values.tolist(),
    area_opacity=0.4,
コード例 #23
0
ファイル: view_bravo.py プロジェクト: huangbinhustei/Raspb
def view_info(range=False):
    if not range:
        start = time.time() - 1800
        gap = 60 - 5
        stampType = '%H:%M'
    elif range == 'day':
        start = time.time() - 86400
        gap = 3600 - 60
        stampType = '%d %H'
    elif range == 'week':
        start = time.time() - 86400 * 7
        gap = 86400 / 4 - 60
        stampType = '%d %H'
    elif range == 'month':
        start = time.time() - 86400 * 30
        gap = 86400 - 60
        stampType = '%m-%d'
    else:
        print('Range Error')
        start = time.time() - 1800
        gap = 60
        stampType = '%H:%M'
    flag, rdb = connect()
    assert flag

    line_cpu = Line(width=width, height=height, title='CPU 监控')
    line_space = Line(width=width, height=height, title='DISK 监控')
    stamps = []
    cpuP_b = []
    cpuT_b = []
    cpuT_z = []
    ram_b = []
    ram_z = []
    disk_b = []
    disk_z = []

    tmp = [], [], [], [], [], [], []

    intKeys = [int(key) for key in rdb.keys() if int(key) > start]
    gapper = start

    if not intKeys:
        return ('<h2>sth wrong')

    if gap == 60 - 5:
        for key in sorted(intKeys):
            stamps.append(time.strftime(stampType, time.gmtime(key + 28800)))
            tmpD = rdb.hgetall(str(key))
            cpuP_b.append(tmpD['cpu_percent'])
            cpuT_b.append(tmpD['cpu_temp'])
            cpuT_z.append(tmpD['zero_cpu_temp'])
            ram_b.append(tmpD['free_ram'])
            ram_z.append(tmpD['zero_free_ram'])
            disk_b.append(tmpD['free_disk'])
            disk_z.append(tmpD['zero_free_disk'])
    else:
        for key in sorted(intKeys):
            if key - gapper >= gap:
                gapper = key
                if tmp[0]:
                    stamps.append(
                        time.strftime(stampType, time.gmtime(key + 28800)))
                    cpuP_b.append(round(sum(tmp[0]) / len(tmp[0]), 0))
                    cpuT_b.append(round(sum(tmp[1]) / len(tmp[0]), 0))
                    cpuT_z.append(round(sum(tmp[2]) / len(tmp[0]), 0))
                    ram_b.append(round(sum(tmp[3]) / len(tmp[0]), 0))
                    ram_z.append(round(sum(tmp[4]) / len(tmp[0]), 0))
                    disk_b.append(round(sum(tmp[5]) / len(tmp[0]), 0))
                    disk_z.append(round(sum(tmp[6]) / len(tmp[0]), 0))
                    tmp = [], [], [], [], [], [], []
            else:
                tmpD = rdb.hgetall(str(key))
                tmp[0].append(float(tmpD['cpu_percent']))
                tmp[1].append(float(tmpD['cpu_temp']))
                tmp[2].append(float(tmpD['zero_cpu_temp']))
                tmp[3].append(float(tmpD['free_ram']))
                tmp[4].append(float(tmpD['zero_free_ram']))
                tmp[5].append(float(tmpD['free_disk']))
                tmp[6].append(float(tmpD['zero_free_disk']))
        if tmp[0]:
            stamps.append(time.strftime(stampType, time.gmtime(key + 28800)))
            cpuP_b.append(sum(tmp[0]) / len(tmp[0]))
            cpuT_b.append(sum(tmp[1]) / len(tmp[0]))
            cpuT_z.append(sum(tmp[2]) / len(tmp[0]))
            ram_b.append(sum(tmp[3]) / len(tmp[0]))
            ram_z.append(sum(tmp[4]) / len(tmp[0]))
            disk_b.append(sum(tmp[5]) / len(tmp[0]))
            disk_z.append(sum(tmp[6]) / len(tmp[0]))
            tmp = [], [], [], [], [], [], []

    line_cpu.add('使用率', stamps, cpuP_b, line_width=2, is_smooth=True)
    line_cpu.add('温度_3B', stamps, cpuT_b, line_width=2, is_smooth=True)
    line_cpu.add('温度_Z', stamps, cpuT_z, line_width=2, is_smooth=True)

    line_space.add('内存_3B', stamps, ram_b, line_width=2, is_smooth=True)
    line_space.add('内存_Z', stamps, ram_z, line_width=2, is_smooth=True)

    if time.localtime().tm_hour >= 21 or time.localtime().tm_hour <= 6:
        line_cpu.use_theme('dark')
        line_space.use_theme('dark')
    js_list = list(
        set(line_cpu.get_js_dependencies() + line_space.get_js_dependencies()))
    return render_template(
        "pyecharts.html",
        cpu=line_cpu.render_embed(),
        space=line_space.render_embed(),
        host='https://pyecharts.github.io/assets/js',
        script_list=js_list,
    )