<commit_before>from django.db import models
from django.contrib.auth.models import Group
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist


class MetricFilter(models.Model):
    id = models.AutoField(primary_key=True)
    filter = models.CharField(max_length=256)
    description = models.CharField(max_length=200)
    type_filter = models.IntegerField(choices=[(0, 'include'), (1, 'exclude')])
    __str__ = lambda self: "Filter: [%s]" % self.filter

    class Meta:
        db_table = "metric_filter"


class UserMetricFilter(models.Model):
    user = models.ForeignKey(User)
    metric_filter = models.ManyToManyField(MetricFilter)
    __str__ = lambda self: "User: [%s]" % self.user

    class Meta:
        db_table = "user_metric_filter"

    @staticmethod
    def getFilters(id):
        try:
            userFilter = UserMetricFilter.objects.get(user = id)
        except ObjectDoesNotExist:
            userFilter = None
        if userFilter is not None:
            return userFilter.metric_filter


class GroupMetricFilter(models.Model):
    group = models.ForeignKey(Group)
    metric_filter = models.ManyToManyField(MetricFilter)
    __str__ = lambda self: "Group: [%s]" % self.group

    class Meta:
        db_table = "group_metric_filter"

    @staticmethod
    def getFiltersByUser(user):
        for userGroup in user.groups.all():
            try:
                groupsFilter = GroupMetricFilter.objects.filter(group = userGroup.id)
            except ObjectDoesNotExist:
                groupsFilter = None
        if groupsFilter is not None:
            for groupFilter in GroupMetricFilter.objects.filter(group = userGroup.id):
                yield groupFilter.metric_filter<commit_msg>Fix indentation contains tabs<commit_after>from django.db import models
from django.contrib.auth.models import Group
from django.contrib.auth.models import User
from django.core.exceptions import ObjectDoesNotExist


class MetricFilter(models.Model):
  id = models.AutoField(primary_key=True)
  filter = models.CharField(max_length=256)
  description = models.CharField(max_length=200)
  type_filter = models.IntegerField(choices=[(0, 'include'), (1, 'exclude')])
  __str__ = lambda self: "Filter: [%s]" % self.filter

  class Meta:
    db_table = "metric_filter"

class UserMetricFilter(models.Model):
  user = models.ForeignKey(User)
  metric_filter = models.ManyToManyField(MetricFilter)
  __str__ = lambda self: "User: [%s]" % self.user

  class Meta:
    db_table = "user_metric_filter"

  @staticmethod
  def getFilters(id):
    try:
      userFilter = UserMetricFilter.objects.get(user = id)
    except ObjectDoesNotExist:
      userFilter = None
    if userFilter is not None:
      return userFilter.metric_filter

class GroupMetricFilter(models.Model):
  group = models.ForeignKey(Group)
  metric_filter = models.ManyToManyField(MetricFilter)
  __str__ = lambda self: "Group: [%s]" % self.group

  class Meta:
    db_table = "group_metric_filter"

  @staticmethod
  def getFiltersByUser(user):
    for userGroup in user.groups.all():
      try:
        groupsFilter = GroupMetricFilter.objects.filter(group = userGroup.id)
      except ObjectDoesNotExist:
        groupsFilter = None
      if groupsFilter is not None:
        for groupFilter in GroupMetricFilter.objects.filter(group = userGroup.id):
          yield groupFilter.metric_filter
{'fraction_non_alphanumeric': 0.09256004686584651, 'fraction_numerical': 0.0046865846514352666, 'mean_word_length': 3.4816272965879267, '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': '5886770', 'n_tokens_mistral': 1025, 'n_tokens_neox': 994, 'n_words': 234}