<commit_before>from datetime import datetime

import pytz
from django.db import models

from .tag import Tag


class Topic(models.Model):
    name = models.CharField(max_length=500, blank=False)
    description = models.TextField(max_length=150)
    start = models.DateTimeField(blank=False)
    end = models.DateTimeField(blank=False)
    tags = models.ManyToManyField(Tag, related_name='topics')

    def is_active(self):
        return self.start <= datetime.now(pytz.utc) <= self.end

    def has_ended(self):
        now = datetime.now(pytz.utc)
        return self.start <= now and self.end <= now

    def get_best_post(self):
        posts = self.posts.all()

        if(posts.count() > 0):
            # Return post with the biggest rating
            return max(self.posts.all(), key=lambda p: p.get_rating() or 0)

        return None

    def __str__(self):
        return self.name<commit_msg>Refactor topic model slightly<commit_after>from datetime import datetime

import pytz
from django.db import models

from .tag import Tag


class Topic(models.Model):
    name = models.CharField(max_length=500, blank=False)
    description = models.TextField(max_length=150)
    start = models.DateTimeField(blank=False)
    end = models.DateTimeField(blank=False)
    tags = models.ManyToManyField(Tag, related_name='topics')

    def is_active(self):
        return self.start <= datetime.now(pytz.utc) <= self.end

    def has_ended(self):
        now = datetime.now(pytz.utc)
        return self.start <= now and self.end <= now

    def get_best_post(self):
        posts = self.posts.all()

        if posts.count() <= 0:
            return None

        return max(posts, key=lambda p: p.get_rating() or 0)

    def __str__(self):
        return self.name
{'fraction_non_alphanumeric': 0.10382513661202186, 'fraction_numerical': 0.008743169398907104, 'mean_word_length': 2.611439842209073, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6394291', 'n_tokens_mistral': 596, 'n_tokens_neox': 540, 'n_words': 135}