results.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:visitor 作者: narupo 项目源码 文件源码
def getdistonmonth():
    config = if_not_exists_to_create_config()
    nvisitors = Visitor.objects.count()

    from calendar import Calendar
    c = Calendar()

    # This month
    now = timezone.now()
    padmonth = padtime(now.month)

    weeks = c.monthdatescalendar(year=now.year, month=now.month)
    for week in weeks:
        for i, day in enumerate(week):
            iday = day.day
            q = 'SELECT * FROM visitor_visitor WHERE visit_date LIKE "{0}-{1}-{2}%%"'.format(now.year, padmonth, padtime(iday))
            total = len(list(Visitor.objects.raw(q)))
            per = toper(nvisitors, total)
            image = None

            if len(settings.MEDIA_URL) and len(settings.MEDIA_ROOT):
                fname = 'c{0}.png'.format(padtime(iday))
                url = os.path.join(settings.MEDIA_URL, config.media_directory, fname)
                savepath = os.path.join(settings.MEDIA_ROOT, config.media_directory, fname)
                savecalrect(savepath, nvisitors, total)

                image = {
                    # TODO: Remove /media
                    'url': url,
                }

            week[i] = {
                'day': iday,
                'total': total,
                'per': per,
                'image': image,
            }

    return weeks
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号