<commit_before>from django.db import models
from django.contrib.auth.models import User
from tracking import utils
from datetime import datetime, timedelta

class VisitorManager(models.Manager):
    def active(self, timeout=None):
        if not timeout:
            timeout = utils.get_timeout()

        now = datetime.now()
        cutoff = now - timedelta(minutes=timeout)

        return self.get_query_set().filter(last_update__gte=cutoff)

class Visitor(models.Model):
    session_key = models.CharField(max_length=40)
    ip_address = models.CharField(max_length=20)
    user = models.ForeignKey(User, null=True)
    user_agent = models.CharField(max_length=255)
    referrer = models.CharField(max_length=255)
    url = models.CharField(max_length=255)
    page_views = models.PositiveIntegerField(default=0)
    session_start = models.DateTimeField()
    last_update = models.DateTimeField()

    objects = VisitorManager()

    def _time_on_site(self):
        if self.session_start:
            seconds = (self.last_update - self.session_start).seconds

            hours = seconds / 3600
            seconds -= hours * 3600
            minutes = seconds / 60
            seconds -= minutes * 60

            return u'%i:%i:%i' % (hours, minutes, seconds)
        else:
            return u'unknown'
    time_on_site = property(_time_on_site)

    class Meta:
        ordering = ['-last_update']
        unique_together = ['session_key', 'ip_address']

class UntrackedUserAgent(models.Model):
    keyword = models.CharField(max_length=100, help_text='Part or all of a user-agent string.  For example, "Googlebot" here will be found in "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" and that visitor will not be tracked.')

    def __unicode__(self):
        return self.keyword

    class Meta:
        ordering = ['keyword']
        verbose_name = 'Untracked User-Agent'
        verbose_name_plural = 'Untracked User-Agents'

class BannedIP(models.Model):
    ip_address = models.IPAddressField('IP Address', help_text='The IP address that should be banned')

    def __unicode__(self):
        return self.ip_address

    class Meta:
        ordering = ['ip_address']
        verbose_name = 'Banned IP'
        verbose_name_plural = 'Banned IPs'<commit_msg>Fixed the formatting for the time_on_site property<commit_after>from django.db import models
from django.contrib.auth.models import User
from tracking import utils
from datetime import datetime, timedelta

class VisitorManager(models.Manager):
    def active(self, timeout=None):
        if not timeout:
            timeout = utils.get_timeout()

        now = datetime.now()
        cutoff = now - timedelta(minutes=timeout)

        return self.get_query_set().filter(last_update__gte=cutoff)

class Visitor(models.Model):
    session_key = models.CharField(max_length=40)
    ip_address = models.CharField(max_length=20)
    user = models.ForeignKey(User, null=True)
    user_agent = models.CharField(max_length=255)
    referrer = models.CharField(max_length=255)
    url = models.CharField(max_length=255)
    page_views = models.PositiveIntegerField(default=0)
    session_start = models.DateTimeField()
    last_update = models.DateTimeField()

    objects = VisitorManager()

    def _time_on_site(self):
        if self.session_start:
            seconds = (self.last_update - self.session_start).seconds

            hours = seconds / 3600
            seconds -= hours * 3600
            minutes = seconds / 60
            seconds -= minutes * 60

            return u'%02i:%02i:%02i' % (hours, minutes, seconds)
        else:
            return u'unknown'
    time_on_site = property(_time_on_site)

    class Meta:
        ordering = ['-last_update']
        unique_together = ['session_key', 'ip_address']

class UntrackedUserAgent(models.Model):
    keyword = models.CharField(max_length=100, help_text='Part or all of a user-agent string.  For example, "Googlebot" here will be found in "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)" and that visitor will not be tracked.')

    def __unicode__(self):
        return self.keyword

    class Meta:
        ordering = ['keyword']
        verbose_name = 'Untracked User-Agent'
        verbose_name_plural = 'Untracked User-Agents'

class BannedIP(models.Model):
    ip_address = models.IPAddressField('IP Address', help_text='The IP address that should be banned')

    def __unicode__(self):
        return self.ip_address

    class Meta:
        ordering = ['ip_address']
        verbose_name = 'Banned IP'
        verbose_name_plural = 'Banned IPs'
{'fraction_non_alphanumeric': 0.0986856280973928, 'fraction_numerical': 0.015513897866839044, 'mean_word_length': 3.0541484716157203, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '466053', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1355, 'n_words': 331}