Example #1
0
def pie(request):
    template = loader.get_template('chart/chart.html')
    attr = ['菜品A', '菜品B', '菜品C', '菜品D', '菜品E', '菜品F']
    pie = Pie("菜品销售占比", width=1400, height=700)
    pie.add("",
            attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55],
            center=[25, 50],
            is_random=True)
    pie.add("",
            attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45],
            center=[25, 50],
            rosetype='area')
    pie.add("",
            attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55],
            center=[65, 50],
            is_random=True)
    pie.add("",
            attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45],
            center=[65, 50],
            rosetype='radius')
    context = dict(myechart=pie.render_embed(),
                   host=REMOTE_HOST,
                   script_list=pie.get_js_dependencies())
    return HttpResponse(template.render(context, request))
Example #2
0
def show_data(request):
    template = loader.get_template('meetings/show_data.html')

    attr = [u"members", "non-members"]
    value = [
        Members.objects.filter(on_activate=True).count(),
        Members.objects.filter(on_activate=False).count()
    ]
    pie = Pie(u"Members and non-members")
    pie.add("Count", attr, value)

    meeting_attendace = Counter(MeetingInfo.objects.values_list('attendance'))
    attr_attendace = OrderedDict()
    attr_attendace.update({
        Members.objects.get(id=key[0]).name: value
        for key, value in meeting_attendace.items()
    })

    wordcloud = WordCloud()
    wordcloud.add("attendace", list(attr_attendace.keys()),
                  list(attr_attendace.values()))

    bar = Bar("attendaces")
    bar.add("attendaces",
            list(attr_attendace.keys()),
            list(attr_attendace.values()),
            xaxis_interval=0,
            xaxis_rotate=-90)

    meeting_info = MeetingInfo.objects.values_list('date', 'count',
                                                   'theme').annotate(
                                                       Count('attendance'))
    meeting_info_dict = OrderedDict()
    for m in meeting_info:
        meeting_info_dict[str(m[0]) + '#' + str(m[1]) + str(m[2])] = int(m[3])
        print(str(m[0]) + '_' + str(m[1]) + str(m[2]), m[3])

    line = Line("Meeting attendance number")
    line.add("ESHTMC",
             list(meeting_info_dict.keys()),
             list(meeting_info_dict.values()),
             mark_point=["average"],
             xaxis_interval=0,
             xaxis_rotate=-45)

    context = dict(
        host=REMOTE_HOST,
        pie=pie.render_embed(),
        pie_script_list=pie.get_js_dependencies(),
        wordcloud=wordcloud.render_embed(),
        wordcloud_script_list=wordcloud.get_js_dependencies(),
        bar=bar.render_embed(),
        bar_script_list=bar.get_js_dependencies(),
        line=line.render_embed(),
        line_script_list=line.get_js_dependencies(),
    )

    return HttpResponse(template.render(context, request))
Example #3
0
def build_top10_dst_port_diagram(df, logs):
    df_top10_grouped_by_dst_port = None

    if not df.empty:
        df_top10_grouped_by_dst_port = df.groupby('dstport').agg({'msg': 'count'})\
         .sort_values(by='msg').tail(10)

    attr = list(df_top10_grouped_by_dst_port.index
                ) if df_top10_grouped_by_dst_port is not None else {}
    v = list(df_top10_grouped_by_dst_port['msg']
             ) if df_top10_grouped_by_dst_port is not None else {}
    pie = Pie()
    pie.add("DST Port", attr, v)

    logs.update(top10_dst_port_diagram=pie.render_embed())
    logs.update(echart_pie_script_list=pie.get_js_dependencies())
Example #4
0
class PlotPie:
    def __init__(self):
        self.data = ''
        self.sort = '0'
        self.pie = Pie()
        self.script_list = self.pie.get_js_dependencies()

    def plot_pie(self, dat, sort):
        self.data = dat
        self.sort = sort
        self.pie = Pie()
        for label in list(self.data.columns):
            if label != 'index':
                self.pie.add(label, self.data['index'],
                             self.data[label],
                             radius=[40, 75],
                             legend_pos='right',
                             legend_orient='vertical',
                             is_label_show=True)
        return self.pie.render_embed()
Example #5
0
def s_compyr():
    try:
        usertype = session['type']
        if usertype == "staff":
            cursor = conn.cursor()
            query = 'SELECT sum(price) FROM purchases, ticket, flight WHERE purchases.ticket_id = ticket.ticket_id AND ticket.airline_name = flight.airline_name AND ticket.flight_num = flight.flight_num AND booking_agent_id is null AND (purchase_date BETWEEN DATE_SUB(CURRENT_DATE(),INTERVAL 1 YEAR) AND CURRENT_DATE())'
            cursor.execute(query)
            direct = cursor.fetchone()
            cursor.close()
            cursor = conn.cursor()
            query = 'SELECT sum(price) FROM purchases, ticket, flight WHERE purchases.ticket_id = ticket.ticket_id AND ticket.airline_name = flight.airline_name AND ticket.flight_num = flight.flight_num AND booking_agent_id is not null AND (purchase_date BETWEEN DATE_SUB(CURRENT_DATE(),INTERVAL 1 YEAR) AND CURRENT_DATE())'
            cursor.execute(query)
            indirect = cursor.fetchone()
            cursor.close()
            xpie = ['direct to customer', '3rd party']
            ypie = []
            print(direct, indirect)
            for key in direct:
                if direct[key] == None:
                    ypie.append(0)
                else:
                    ypie.append(int(direct[key]))
            for key in indirect:
                if indirect[key] == None:
                    ypie.append(0)
                else:
                    ypie.append(int(indirect[key]))
            pie = Pie('Revenue in last year')
            pie.add('', xpie, ypie, is_label_show=True)
            return render_template('s_compyr.html',
                                   myechart=pie.render_embed(),
                                   host=REMOTE_HOST,
                                   script_list=pie.get_js_dependencies())
        else:
            return render_template('error.html')
    except KeyError:
        return render_template('error.html')
Example #6
0
def chart_view03():
    # 从mongo中获取数据
    (x, y) = BidNotice.get_records_group_by_notice_type()

    # 设置bar图形的基本属性
    pie = Pie("公告类型分析图", "From: cmccb2b")
    pie.use_theme('light')
    pie.add("公告类型", x, y, is_stack=False)  # 从Mongo读取的数据存放在这里

    javascript_snippet = TRANSLATOR.translate(pie.options)  # 将bar的属性设置翻译为js脚本
    # pie.print_echarts_options()                  # 该行只为了打印配置项,方便调试时使用

    return render_template(
        "pyecharts.html",  # 自定义,位于templates/的模版文件
        chart_id=pie.chart_id,  # 默认设置,
        host=REMOTE_HOST,  # 常量定义,存放js文件的url地址
        renderer=pie.renderer,  # 默认设置,
        my_width="100%",  # 默认设置,定义图表的宽度
        my_height=600,  # 默认设置,定义图表的高度
        custom_function=javascript_snippet.
        function_snippet,  # 默认设置,保存图片的方法,似乎基于node.js
        options=javascript_snippet.option_snippet,  # 默认设置,
        script_list=pie.get_js_dependencies(),  # 默认设置,需要动态加载的js文件
    )
Example #7
0
def myechart(request, pk):
    school = get_object_or_404(Food_Struct, pk=pk)
    school2 = get_object_or_404(School, pk=pk)
    nutri_school = get_object_or_404(Nutri_of_Food, pk=pk)
    students = school2.students
    template = loader.get_template("hele/pyecharts.html")
    mypie = Pie("每人日均餐标结构(单位:%)", title_pos="center")
    value = [
        school.rice, school.ganhuo, school.cake, school.egg, school.chicken,
        school.ricenoodle, school.milk, school.beef, school.oil,
        school.vegitable, school.flavor, school.pock
    ]
    attr = [
        "大米", "干货", "糕点", "鸡蛋", "鸡鸭肉", "米粉", "奶制品", "牛肉", "食用油", "蔬菜", "调味品",
        "猪肉"
    ]
    struct_value = []
    for i in value:
        k = roundfunc(i)
        struct_value.append(k)
    total = roundfunc(school.total)
    mypie.add("", attr, value, is_label_show=True, is_legend_show=False)
    mybar = Bar("每人日均食物摄入结构(单位:g)", title_pos="center")
    nutri_value = [
        nutri_school.xuqin, nutri_school.fish, nutri_school.soilbean,
        nutri_school.egg, nutri_school.gushu, nutri_school.milk,
        nutri_school.sault, nutri_school.vigetable, nutri_school.fruit,
        nutri_school.oil
    ]
    standart_value = [50, 50, 40, 50, 350, 200, 5, 400, 250, 30]
    nutri_attr = [
        "畜禽肉", "鱼虾类", "大豆坚果", "蛋类", "谷薯类", "奶制品", "食盐", "蔬菜类", "水果类", "植物油"
    ]
    mybar.add("学生实际值",
              nutri_attr,
              nutri_value,
              is_label_show=True,
              is_legend_show=True,
              legend_top="bottom")
    mybar.add("标准摄入值",
              nutri_attr,
              standart_value,
              is_label_show=True,
              is_legend_show=True,
              legend_top="bottom")
    context = dict(
        school=school,
        town_list=District.objects.all(),
        town=school2.district,
        school_name=school.name.name,
        next_school=next_school(school2.id),
        school_student=students,
        total=total,
        nutr_total=nutri_school.total,
        pie_myecharts=mypie.render_embed(),
        bar_myecharts=mybar.render_embed(),
        host=REMOTE_HOST,
        pie_script_list=mypie.get_js_dependencies(),
        bar_script_list=mybar.get_js_dependencies(),
    )
    return HttpResponse(template.render(context, request))