Skip to content
This repository was archived by the owner on Jul 22, 2022. It is now read-only.
This repository was archived by the owner on Jul 22, 2022. It is now read-only.

Trending tags runner #16

@makyo

Description

@makyo

Should be able to look at tags over the past n days and see what's on the rise, ordered by count of latest descending, probably with a lower threshold. Maybe something like:

today = datetime.date.today()
important_tags = Post.objects.filter(created_at__date=today)\
    .values('tags__tag')\
    .annotate(count=Count('tags__tag'))\
    .filter(count__gt=threshold)
tags = dict([(t['tags__tag'], collections.defaultdict(lambda: 0)) for t in important_tags])
for day in range(0, self.n_days):
    date = today - datetime.timedelta(days=day)
    posts_for_day = Post.objects.filter(tags__tag__in=tags.values())\
        .filter(created_at__date__gt=date - datetime.timedelta(days=day + 1))\
        .filter(created_at__date__lt=date)
    for post in posts_for_day:
        for tag in post.tags:
            if tag.tag in tags:
                tags[tag.tag][str(date)] += 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions