Beispiel #1
0
class Mutdraw():
    def __init__(self):
        self.attr = [
            "ASD", "SCZ", "BPD", "DD", "DEE", "EE", "ID", "OCD", "TS", "CHD",
            "control"
        ]
        self.v1 = [
            173712, 1038, 69, 8336, 288, 580, 1432, 26, 441, 1900, 51093
        ]
        self.attr2 = ["ASD", "SCZ", "BPD", "ID", "control"]
        self.v2 = [486, 66, 25, 81, 121]
        self.attr3 = ["ASD", "SCZ", "BPD", "MDD", "ADHD"]
        self.v3 = [292, 641, 84, 36, 35]
        self.pie1 = Pie("DNM",
                        width=500,
                        height=300,
                        title_pos="center",
                        title_top="bottom")
        self.pie2 = Pie("CNV",
                        width=500,
                        height=300,
                        title_pos="center",
                        title_top="bottom")
        self.pie1.add("",
                      self.attr,
                      self.v1,
                      legend_pos="left",
                      legend_text_size=8,
                      is_toolbox_show=False)
        self.pie2.add("",
                      self.attr2,
                      self.v2,
                      legend_pos="left",
                      legend_text_size=8,
                      is_toolbox_show=False)
        self.nodes = [{"name": "x"}, {"name": "y"}, {"name": "z"}]
        self.links = [{
            "source": "x",
            "target": "y"
        }, {
            "source": "x",
            "target": "z"
        }]
        self.graph = Graph("Graph", "PPI")
        self.graph.add("Pt", self.nodes, self.links)
        """

		self.grid=Grid()
		self.grid.add(self.pie1,grid_left="70%")
		self.grid.add(self.pie2,grid_right="70%")
		"""

    def drawPie(self):
        return self.pie1.render_embed()

    def drawPie2(self):
        return self.pie2.render_embed()

    def drawGraph(self):
        return self.graph.render_embed()
Beispiel #2
0
def results(request, questionnaire_id):
    questionnaire = get_object_or_404(Questionnaire, pk=questionnaire_id)
    pies_for_questions = []
    total_bar_x = []
    total_bar_y = []
    for question in questionnaire.question_set.all():
        pie_x = []
        pie_y = []
        for choice in question.choice_set.all():
            total_bar_x.append(choice.choice_text)
            total_bar_y.append(choice.votes)
            pie_x.append(choice.choice_text)
            pie_y.append(choice.votes)
        pie = Pie("各选项所占百分比")
        pie.add("", pie_x, pie_y, radius=[30, 75], is_label_show=True)
        pies_for_questions.append(pie.render_embed())

    total_bar = Bar("投票结果总览", width=1000, height=700)
    total_bar.add("各选项投票量",
                  total_bar_x,
                  total_bar_y,
                  mark_line=["average"],
                  mark_point=["max", "min"],
                  xaxis_rotate=30)

    return render(
        request, 'polls/results.html', {
            'questionnaire': questionnaire,
            'myecharts': {
                "total_bar": total_bar.render_embed(),
                "pies_for_questions": pies_for_questions
            }
        })
Beispiel #3
0
def courseStatistics():
    r'''
    课程统计页面,使用pyecharts
    :return:
    '''
    types = CourseType.query.filter().all()
    attr = []
    data = []
    for type in types:
        attr.append(type.typeName)
        data.append(
            len(
                CourseInfo.query.filter(
                    CourseInfo.typeId == type.typeId).all()))
    bar = Bar()
    bar.add("courseType", attr, data, is_random=True)

    #用户学习课程待完成
    courses = CourseInfo.query.filter().all()
    attr2 = []
    data2 = []
    for course in courses:
        attr2.append(course.courseTitle.encode('utf-8'))
        data2.append(len(course.stds.all()))
    pie = Pie()
    pie.add("", attr2, data2, is_label_show=True, is_random=True)
    return render_template("course-statistics.html",
                           myechart1=bar.render_embed(),
                           myechart2=pie.render_embed())
Beispiel #4
0
def pie(request):
    template = loader.get_template('chart/chart.html')
    attr = ['菜品A', '菜品B', '菜品C', '菜品D', '菜品E', '菜品F']
    pie = Pie("菜品销售占比", width=1400, height=700)
    pie.add("",
            attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55],
            center=[25, 50],
            is_random=True)
    pie.add("",
            attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45],
            center=[25, 50],
            rosetype='area')
    pie.add("",
            attr, [random.randint(0, 100) for _ in range(6)],
            radius=[50, 55],
            center=[65, 50],
            is_random=True)
    pie.add("",
            attr, [random.randint(20, 100) for _ in range(6)],
            radius=[0, 45],
            center=[65, 50],
            rosetype='radius')
    context = dict(myechart=pie.render_embed(),
                   host=REMOTE_HOST,
                   script_list=pie.get_js_dependencies())
    return HttpResponse(template.render(context, request))
Beispiel #5
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))
Beispiel #6
0
def pie_html(title, key, val):
    pie = Pie(title, title_pos="center", width="100%", height=300)
    pie.add("",
            key,
            val,
            is_random=True,
            radius=[30, 75],
            rosetype="area",
            is_legend_show=False,
            is_label_show=True)
    return pie.render_embed()
Beispiel #7
0
 def _education_show(self):
     pie = Pie("学历统计", title_pos='center', width=1200, height=500)
     attr, value = pie.cast(self.g.education_data)
     pie.add("",
             attr,
             value,
             adius=[40, 80],
             title_pos='center',
             is_label_show=True,
             legend_orient='vertical',
             legend_pos='left')
     return pie.render_embed()
Beispiel #8
0
def echart_auto():
    style = Style()
    attr = ["订购中", "上牌中", "仓储中", "维修中"]
    v = [0, 0, 0, 0]
    v[0] = models.CarHold.objects.filter(car_status=1).count()
    v[1] = models.CarHold.objects.filter(car_status=2).count()
    v[2] = models.CarHold.objects.filter(car_status=3).count()
    v[3] = models.CarHold.objects.filter(car_status=9).count()

    chart = Pie("", **style.init_style)
    chart.add("", attr, v, is_label_show=True)
    return chart.render_embed()
Beispiel #9
0
def echart_cust():
    style = Style()
    attr = ["意向客户", "提交审批", "审批通过", "审批拒绝", "用户退单"]
    v = [0, 0, 0, 0, 0]
    v[0] = models.Cust.objects.filter(cust_status=1).count()
    v[1] = models.Cust.objects.filter(cust_status=2).count()
    v[2] = models.Cust.objects.filter(cust_status=3).count()
    v[3] = models.Cust.objects.filter(cust_status=4).count()
    v[4] = models.Cust.objects.filter(cust_status=5).count()

    chart = Pie("", **style.init_style)
    chart.add("", attr, v, is_label_show=True)
    return chart.render_embed()
Beispiel #10
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())
Beispiel #11
0
def pie(spi, name):
    """
    :param spi: 接受为元组((),())
    :param name:
    :return:
    """
    attr = []
    v1 = []
    for i in spi:
        attr.append(i[0])
        v1.append(i[1])

    pie_pie = Pie(name, title_pos='center')
    pie_pie.add("", attr, v1, radius=[40, 75], label_text_color=None,
                is_label_show=True, legend_orient='vertical', legend_pos='left')
    return pie_pie.render_embed()
Beispiel #12
0
def querySexGroup():
    print("用户需要查询性别比例")

    qdatas = querydbSexData()
    headInfos = request.headers["User-Agent"]

    print(headInfos)

    flag = checkMobile(headInfos)

    if flag:
        print("来自移动端的请求")

        print(qdatas)

        listdatas = []
        for linedatas in qdatas:
            sexdata = {}
            sexdata["name"] = linedatas[0]
            sexdata["value"] = linedatas[1]
            listdatas.append(sexdata)

        print(listdatas)
        return jsonify(listdatas)
    else:
        print("来自浏览器的请求")

        sex = []
        sexdatas = []

        for item in qdatas:
            sex.append(item[0])
            sexdatas.append(item[1])

        pie = Pie("天汇智码学生比例")
        print(sex)
        print(sexdatas)

        pie.add("性别", sex, sexdatas)

        # 生成图表对象
        piesexImg = pie.render_embed()
        return render_template("stu_pie.html", sexpie=piesexImg)
Beispiel #13
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()
Beispiel #14
0
def vote_chart(request):
    # print("here")
    vote_c = Mongo_conn("test_Berg", "vote")
    result = vote_c.aggregate([{
        "$group": {
            '_id': "$Choice",
            'sum': {
                "$sum": 1
            }
        }
    }])
    attr = []
    val = []
    for d in result:
        attr.append(d['_id'])
        val.append(d['sum'])
    pie = Pie("Result for vote")
    pie.add("", attr, val, is_label_show=True, rosetype="radius")
    chart = pie.render_embed()
    # print(chart)
    return HttpResponse(json.dumps({"chart": chart}))
Beispiel #15
0
 def pie_two_html(self, chart_id, title, sub_title1, sub_title2, key1,
                  value1, key2, value2):
     """网络信息双饼图"""
     pie = Pie(title="{}-{}".format(self.dt, title),
               title_pos='center',
               width='100%',
               height=300,
               title_text_size=14,
               title_color='white')
     # 指定id
     pie.chart_id = chart_id
     # 添加数据
     pie.add(
         name=sub_title1,
         attr=key1,
         value=value1,
         center=[25, 50],
         is_random=True,
         radius=[30, 75],
         rosetype="radius",
         is_legend_show=True,
         is_label_show=True,
         label_text_size=15,
         legend_text_size=14,
     )
     pie.add(name=sub_title2,
             attr=key2,
             value=value2,
             center=[65, 50],
             is_random=True,
             radius=[30, 75],
             rosetype="radius",
             is_legend_show=True,
             is_label_show=True,
             legend_pos="right",
             legend_orient="vertical",
             label_text_size=15)
     return pie.render_embed()
Beispiel #16
0
def pie(spi, name):
    """
    :param spi: 接受为可叠代对象,如:元组((),())
    :param name:
    :return:
    """
    attr = []
    v1 = []
    for i in spi:
        attr.append(i[0])
        v1.append(i[1])

    pie_pie = Pie("", title_pos='center', width=1200, height=600)
    pie_pie.add(name,
                attr,
                v1,
                radius=[25, 75],
                label_text_color=None,
                is_label_show=True,
                legend_orient='vertical',
                legend_pos='left',
                rosetype="area")
    return pie_pie.render_embed()
Beispiel #17
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')
Beispiel #18
0
def pie(title, attr, values):
    """
    输出Pie图
    :param title: 标题
    :param attr: 属性
    :param values: 数据
    :return: 图形
    """

    pie = Pie(title, title_pos='center', width=300)
    for _value in values:
        pie.add(title, attr, _value,
                center=[50, 50],
                is_random=False,
                radius=[20, 45],
                rosetype='rose',
                is_legend_show=False,
                is_label_show=True,
                background_color='#b0bab9',
                label_text_size=12)

    pie.options['toolbox']['show'] = False

    return pie.render_embed()
def bar_echart(request, *args, **kwargs):
    template = loader.get_template(
        './node_modules/gentelella/production/display_metric_detail.html')
    snap = request.GET.get('snapdate')
    #snap_date = datetime.strptime(snap, '%y/%m/%d').strftime('%Y-%m-%d')
    if snap:

        load_profile_per_hour = list(
            models.loadmetric_hour.objects.values(
                "time", "redo_second", "logical_second", "physical_second",
                "execs_second", "trans_second").filter(snap_date=snap).all())
        space_usage = list(
            models.spaceusage.objects.values(
                "tablespace_name", "percent").filter(collect_time=snap).all())
        print(space_usage)

        # load_profile_obj = apps.get_model('ora_dual', 'loadmetric_hour')
        # load_profile_field = load_profile_obj._meta.fields
        # title = []
        # for ind in range(len(load_profile_field)):
        #     title.append(load_profile_field[ind].name)
        attr = []

        for key, value in load_profile_per_hour[0].items():
            attr.append(key)

        val_usage = []
        val_name = []
        for idx in range(len(space_usage)):
            val_name.append(space_usage[idx]['tablespace_name'])
            val_usage.append(space_usage[idx]['percent'])

        usage_pie = Pie("饼图-空间使用率", title_pos='center')
        usage_pie.add(
            "",
            val_name,
            val_usage,
            radius=[40, 75],
            label_text_color=None,
            is_label_show=True,
            legend_orient="vertical",
            legend_pos="left",
        )
        # pie.render()
        timeline = Timeline(is_auto_play=True, timeline_bottom=0)

        for idx in range(len(load_profile_per_hour)):
            val = []
            for key, value in load_profile_per_hour[idx].items():
                val.append(value)

            bar = Bar("数据库指标", val[0])
            bar.add("值/秒", attr[1:], val[1:])
            timeline.add(bar, val[0])

        context = dict(
            snap_date=snap,
            title=attr,
            usage_pie=usage_pie.render_embed(),
            space_usage=space_usage,
            metric_data=load_profile_per_hour,
            myechart=timeline.render_embed(),
            # host=DEFAULT_HOST,#这句改为下面这句
            host=REMOTE_HOST,  # <-----修改为这个
            script_list=timeline.get_js_dependencies())
        return HttpResponse(template.render(context, request))
Beispiel #20
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))