示例#1
0
def calendar_label_setting() -> Calendar:
    begin = datetime.date(2017, 1, 1)
    end = datetime.date(2017, 12, 31)
    data = [[
        str(begin + datetime.timedelta(days=i)),
        random.randint(1000, 25000)
    ] for i in range((end - begin).days + 1)]

    c = (Calendar().add(
        "",
        data,
        calendar_opts=opts.CalendarOpts(
            range_="2017",
            daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
            monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
        ),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title="Calendar-2017年微信步数情况(中文 Label)"),
        visualmap_opts=opts.VisualMapOpts(
            max_=20000,
            min_=500,
            orient="horizontal",
            is_piecewise=True,
            pos_top="230px",
            pos_left="100px",
        ),
    ))
    return c
def calendar_in_Chinese():
    calendar = Calendar(
        init_opts=opts.InitOpts(theme='light', width='1000px', height='600px'))
    calendar.add(
        '确证人数',
        yaxis_data=data,
        label_opts=opts.LabelOpts(is_show=True),
        calendar_opts=opts.CalendarOpts(
            # 日期范围
            range_=['2020-01-21', '2020-04-30'],
            # 日历单元格尺寸
            cell_size=50,
            # 年月日标签样式设置
            # 星期和月份设置为中文显示,默认是英文
            yearlabel_opts=opts.CalendarYearLabelOpts(margin=50),
            daylabel_opts=opts.CalendarDayLabelOpts(name_map='cn'),
            monthlabel_opts=opts.CalendarMonthLabelOpts(name_map='cn')))
    # 设置视觉组件
    calendar.set_global_opts(visualmap_opts=opts.VisualMapOpts(
        max_=1000000,
        is_piecewise=True,
        pieces=[{
            "min": 1000000
        }, {
            "min": 10000,
            "max": 1000000
        }, {
            "min": 100,
            "max": 10000
        }, {
            "max": 100
        }],
        range_color=["#CCD3D9", "#E6B6C2", "#D4587A", "#DC364C"]))
    return calendar
示例#3
0
    def get(self):
        begin = datetime.date(2020, 1, 1)
        end = datetime.date(2020, 12, 31)

        uu_id = self.get_argument('uuid', None)

        accesslist = self.session.query(
            func.date_format(ShorturlOverview.short_url_createTime,
                             '%Y-%m-%d').label('date'),
            func.count(ShorturlOverview.short_url_id)).filter(
                ShorturlOverview.short_url == ShortUrlInfo.short_code).filter(
                    ShortUrlInfo.uuid == uu_id).group_by('date').order_by(
                        'date').all()
        data = []
        for d in accesslist:
            clist_item = []
            clist_item.append(d[0])
            clist_item.append(d[1])
            data.append(clist_item)

        calendar = Calendar()
        calendar.add(
            '',
            data,
            calendar_opts=opt.CalendarOpts(
                range_='2020',
                daylabel_opts=opt.CalendarDayLabelOpts(name_map='en'),
                monthlabel_opts=opt.CalendarMonthLabelOpts(name_map='en'),
            ),
        )

        calendar.set_global_opts(
            title_opts=opt.TitleOpts(
                title='Calendar - The number of clicks per day in 2020'),
            visualmap_opts=opt.VisualMapOpts(
                max_=200,
                min_=1,
                orient="horizontal",
                is_piecewise=True,
                pos_top="230px",
                pos_left="100px",
            ),
        )

        calendar.render(path=settings['template_path'] + '/calendar.html',
                        encoding='utf-8')
        self.render('calendar.html')
    def calendar_base(self) -> Calendar:
        start = datetime.datetime.now()

        begin = get_date(365)
        end = datetime.date.today() - timedelta(days=465)
        data = []
        cur_day = end
        count = 0
        for event in self.event_list:
            if event.create_time < cur_day:
                data.insert(0, (cur_day, count))
                count = 0
                cur_day -= timedelta(days=1)

            if cur_day < begin:
                break

            if event.create_time == cur_day:
                count += 1

        c = (
            Calendar()
            .add("",
                 data,
                 calendar_opts=opts.CalendarOpts(
                     range_=[begin, end],
                     daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
                     monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
                     pos_right="20px"
                 ),
                 )
            .set_global_opts(
                visualmap_opts=opts.VisualMapOpts(
                    max_=501,
                    min_=1,
                    orient="horizontal",
                    is_piecewise=True,
                    pos_left="40px"
                ),
            )
            .dump_options_with_quotes()
        )

        end = datetime.datetime.now()
        print("Calendar: " + str(end - start))
        return c
示例#5
0
def get_calender_data(request):
    def get_date(days):
        day = (date.today() - timedelta(days=555) - timedelta(days=days))
        return day

    property = Property.objects.get(name=request.GET.get("calender-choice"))
    event_list = Event.objects.filter(property=property)

    start = datetime.datetime.now()

    begin = get_date(365)
    end = datetime.date.today() - timedelta(days=465)
    data = []
    cur_day = end
    count = 0
    for event in event_list:
        if event.create_time < cur_day:
            data.insert(0, (cur_day, count))
            count = 0
            cur_day -= timedelta(days=1)

        if cur_day < begin:
            break

        if event.create_time == cur_day:
            count += 1

    c = (Calendar().add(
        "",
        data,
        calendar_opts=opts.CalendarOpts(
            range_=[begin, end],
            daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
            monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
            pos_right="20px"),
    ).set_global_opts(visualmap_opts=opts.VisualMapOpts(
        max_=501,
        min_=1,
        orient="horizontal",
        is_piecewise=True,
        pos_left="40px"), ).dump_options_with_quotes())

    end = datetime.datetime.now()
    print("Calendar: " + str(end - start))
    return HttpResponse(c, content_type='application/json')
示例#6
0
def Calmap(name, data, maxnum, minnum):
    c = (Cal().add(
        "",
        data,
        calendar_opts=opts.CalendarOpts(
            range_="2020",
            daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
            monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
        ),
    ).set_global_opts(
        title_opts=opts.TitleOpts(title=name + '疫情日历图'),
        visualmap_opts=opts.VisualMapOpts(
            max_=maxnum,
            min_=minnum,
            orient="horizontal",
            is_piecewise=True,
            pos_top="230px",
            pos_left="100px",
        ),
    ).render(name + '疫情日历图.html'))
def calendar_custom_cell():
    calendar = Calendar(
        init_opts=opts.InitOpts(theme='light', width='1000px', height='600px'))
    calendar.add(
        '确证人数',
        yaxis_data=data,
        label_opts=opts.LabelOpts(is_show=True),
        calendar_opts=opts.CalendarOpts(
            # 日历位置
            pos_top='10%',
            pos_left='10%',
            # 日期范围
            range_=['2020-01-21', '2020-04-30'],
            # 日历单元格尺寸
            cell_size=50,
            # 年月日标签样式设置
            yearlabel_opts=opts.CalendarYearLabelOpts(
                margin=40,
                label_font_size=20,
                label_color='rgba(130,134,112,0.8)'),
            daylabel_opts=opts.CalendarDayLabelOpts(label_color='#778633',
                                                    label_font_weight='bold'),
            monthlabel_opts=opts.CalendarMonthLabelOpts(
                label_color='#778633', label_font_weight='bold')))
    # 设置视觉组件
    calendar.set_global_opts(visualmap_opts=opts.VisualMapOpts(
        max_=1000000,
        is_piecewise=True,
        pieces=[{
            "min": 1000000
        }, {
            "min": 10000,
            "max": 1000000
        }, {
            "min": 100,
            "max": 10000
        }, {
            "max": 100
        }],
        range_color=["#CCD3D9", "#E6B6C2", "#D4587A", "#DC364C"]))
    return calendar
示例#8
0
def test_calendar_setting(fake_writer):
    begin = datetime.date(2017, 1, 1)
    end = datetime.date(2017, 12, 31)
    data = [
        [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
        for i in range((end - begin).days + 1)
    ]

    c = (
        Calendar()
        .add(
            "",
            data,
            calendar_opts=opts.CalendarOpts(
                range_="2017",
                cell_size=15,
                daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
                monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
            ),
        )
        .set_global_opts(
            visualmap_opts=opts.VisualMapOpts(
                max_=20000,
                min_=500,
                orient="horizontal",
                is_piecewise=True,
                pos_top="230px",
                pos_left="100px",
            )
        )
    )
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("cellSize", content)
    assert_in("dayLabel", content)
    assert_in("monthLabel", content)
begin = datetime.date(2017, 1, 1)
end = datetime.date(2017, 12, 31)
data = [
    [str(begin + datetime.timedelta(days=i)), random.randint(1000, 25000)]
    for i in range((end - begin).days + 1)
]

c = (
    Calendar()
    .add(
        "",
        data,
        calendar_opts=opts.CalendarOpts(
            range_="2017",
            daylabel_opts=opts.CalendarDayLabelOpts(name_map="cn"),
            monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
        ),
    )
    .set_global_opts(
        title_opts=opts.TitleOpts(title="Calendar-2017年微信步数情况(中文 Label)"),
        visualmap_opts=opts.VisualMapOpts(
            max_=20000,
            min_=500,
            orient="horizontal",
            is_piecewise=True,
            pos_top="230px",
            pos_left="100px",
        ),
    )
    .render("calendar_label_setting.html")
示例#10
0
def picet(dtat):
    c = (
        Calendar(init_opts=opts.InitOpts(
            bg_color='rgb(255,255,255)',  #背景色,可以使用rgba(255,255,255,0.2)
            width='1200px',
            height='300px',
            page_title='2019年XXX污染物浓度',
            theme=ThemeType.MACARONS)).add(
                "",
                dtat,
                calendar_opts=opts.CalendarOpts(
                    range_="2019",  #确定范围
                    #range_="2015-02",
                    #range_=['2015-01-01', '2015-12-31'],
                    daylabel_opts=opts.CalendarDayLabelOpts(
                        name_map="cn"),  #中文显示,必须使用pyecharts1.7.1版本
                    monthlabel_opts=opts.CalendarMonthLabelOpts(name_map="cn"),
                ),
            ).set_global_opts(
                title_opts=opts.TitleOpts(title="2019年XXX污染物浓度", pos_left=550),
                toolbox_opts=opts.ToolboxOpts(is_show=True),
                visualmap_opts=opts.VisualMapOpts(
                    max_=10,
                    min_=0,
                    orient="horizontal",
                    is_piecewise=True,
                    split_number=5,
                    pos_top="220px",
                    pos_left="450px",
                    pieces=[  #更改区间及区间显示颜色
                        {
                            'min': 0,
                            'max': 50,
                            'label': '优',
                            'color': '#00E400'
                        },
                        {
                            'min': 51,
                            'max': 100,
                            'label': '良',
                            'color': '#FFFF00'
                        },
                        {
                            'min': 101,
                            'max': 150,
                            'label': '轻度污染',
                            'color': '#FF7E00'
                        },
                        {
                            'min': 151,
                            'max': 200,
                            'label': '中度污染',
                            'color': '#FF0000'
                        },
                        {
                            'min': 201,
                            'max': 300,
                            'label': '重度污染',
                            'color': '#99004C'
                        },
                        {
                            'min': 300,
                            'label': '严重污染',
                            'color': '#7E0023'
                        },
                    ]),
            ))
    c.render()