<commit_before>import hashlib
import datetime

from django.db import models
from django.contrib.auth.models import User

# Extend the user model
CHECKIN_ONLY =1
REPORTS_ONLY = 2
ALL = 3
USER_TYPE_REPORTS = [REPORTS_ONLY, ALL]

USER_TYPES = (
    (CHECKIN_ONLY, 'Checkin only'),
    (REPORTS_ONLY, 'Reports only'),
    (ALL, 'All')
)
class ApplePiUser(models.Model):
    user = models.OneToOneField(User)
    parent = models.ForeignKey('self', null=True)
    role = models.PositiveSmallIntegerField(choices=USER_TYPES)
    checkins_count = models.PositiveIntegerField(default=0)

    def generate_token(self):
        m = hashlib.md5()
        m.update(self.user.username)
        m.update(str(datetime.datetime.now()))

        token = m.hexdigest()

        ut = UserTokens()
        ut.user = self.user
        ut.value = token
        ut.save()

        return token

    def can_report(self):
        return self.role in USER_TYPE_REPORTS

    def __unicode__(self):
        return u'%s (parent: %s, role: %s)' % (self.user, self.parent, self.role)

class UserTokens(models.Model):
    user = models.ForeignKey(User)
    value = models.CharField(max_length=32)

# Define place types (school, parc, etc) - defined for each instance in
# the app's settings
PLACE_TYPE_CHOICES = (
    ('1', 'School'),
    ('2', 'Parc'),
    ('3', 'Gym')
)
class Place(models.Model):
    place_type = models.PositiveSmallIntegerField(choices=PLACE_TYPE_CHOICES)
    place_name = models.CharField(max_length=100)
    # Add support for geo fields (spatialite and all)

# Define the checkin model
class Checkin(models.Model):
    user = models.ForeignKey(User)
    place = models.ForeignKey(Place)
    starttime = models.DateTimeField(auto_now_add=True)
    endtime = models.DateTimeField(null=True)
    # add maybe mood or other stuff here
<commit_msg>A user is still logged in<commit_after>import hashlib
import datetime

from django.db import models
from django.contrib.auth.models import User

# Extend the user model
CHECKIN_ONLY =1
REPORTS_ONLY = 2
ALL = 3
USER_TYPE_REPORTS = [REPORTS_ONLY, ALL]

USER_TYPES = (
    (CHECKIN_ONLY, 'Checkin only'),
    (REPORTS_ONLY, 'Reports only'),
    (ALL, 'All')
)
class ApplePiUser(models.Model):
    user = models.OneToOneField(User)
    parent = models.ForeignKey('self', null=True)
    role = models.PositiveSmallIntegerField(choices=USER_TYPES)
    checkins_count = models.PositiveIntegerField(default=0)

    def generate_token(self):
        m = hashlib.md5()
        m.update(self.user.username)
        m.update(str(datetime.datetime.now()))

        token = m.hexdigest()

        ut = UserTokens()
        ut.user = self.user
        ut.value = token
        ut.save()

        return token

    def can_report(self):
        return self.role in USER_TYPE_REPORTS

    def __unicode__(self):
        return u'%s (parent: %s, role: %s)' % (self.user, self.parent, self.role)

class UserTokens(models.Model):
    user = models.ForeignKey(User)
    value = models.CharField(max_length=32)

# Define place types (school, parc, etc) - defined for each instance in
# the app's settings
PLACE_TYPE_CHOICES = (
    ('1', 'School'),
    ('2', 'Parc'),
    ('3', 'Gym')
)
class Place(models.Model):
    place_type = models.PositiveSmallIntegerField(choices=PLACE_TYPE_CHOICES)
    place_name = models.CharField(max_length=100)
    # Add support for geo fields (spatialite and all)

    def __unicode__(self):
        return u'%s' % self.place_name

# Define the checkin model
class Checkin(models.Model):
    user = models.ForeignKey(User)
    place = models.ForeignKey(Place)
    starttime = models.DateTimeField(auto_now_add=True)
    endtime = models.DateTimeField(null=True)
    # add maybe mood or other stuff here

    def stillthere(self):
        return not self.endtime # todo: add time limit when the session is considered done
{'fraction_non_alphanumeric': 0.11231884057971014, 'fraction_numerical': 0.006728778467908903, 'mean_word_length': 3.4785631517960605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7131503', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1250, 'n_words': 307}