<commit_before>import hashlib
import logging

from django.conf import settings
from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.db import models
from django.utils import timezone
from django.utils.functional import cached_property
from phonenumber_field.modelfields import PhoneNumberField

from apostello.exceptions import NoKeywordMatchException
from apostello.tasks import (
    group_send_message_task, recipient_send_message_task
)
from apostello.utils import fetch_default_reply
from apostello.validators import (
    TWILIO_INFO_WORDS, TWILIO_START_WORDS, TWILIO_STOP_WORDS, gsm_validator,
    less_than_sms_char_limit, no_overlap_keyword, not_twilio_num,
    twilio_reserved, validate_lower
)

logger = logging.getLogger('apostello')


class RecipientGroup(models.Model):
    """Stores groups of recipients."""
    is_archived = models.BooleanField("Archived", default=False)
    name = models.CharField(
        "Name of group",
        max_length=30,
        unique=True,
        validators=[gsm_validator],
    )
    description = models.CharField("Group description", max_length=200, )

    def send_message(self, content, sent_by, eta=None):
        """Send message to group."""
        group_send_message_task.delay(content, self.name, sent_by, eta)

    def archive(self):
        """Archive the group."""
        self.is_archived = True
        self.save()

    @cached_property
    def all_recipients(self):
        return self.recipient_set.all()

    @property
    def all_recipients_names(self):
        """List of the names of recipients."""
        return [str(x) for x in self.all_recipients]

    def calculate_cost(self):
        """Calculate the cost of sending to this group."""
        return settings.SENDING_COST * self.all_recipients.count()

    @cached_property
    def get_absolute_url(self):
        """Url for this group."""
        return reverse('group', args=[str(self.pk)])

    @cached_property
    def get_api_url(self):
        """Url for group list api end point."""
        return reverse('api:group', args=[str(self.pk)])

    @cached_property
    def get_table_url(self):
        """Url for group list page."""
        return reverse('recipient_groups')

    def __str__(self):
        """Pretty representation."""
        return self.name

    class Meta:
        ordering = ['name']
<commit_msg>fix bug in calculate costs<commit_after>import hashlib
import logging

from django.conf import settings
from django.contrib.auth.models import User
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.exceptions import ValidationError
from django.core.urlresolvers import reverse
from django.db import models
from django.utils import timezone
from django.utils.functional import cached_property
from phonenumber_field.modelfields import PhoneNumberField

from apostello.exceptions import NoKeywordMatchException
from apostello.tasks import (
    group_send_message_task, recipient_send_message_task
)
from apostello.utils import fetch_default_reply
from apostello.validators import (
    TWILIO_INFO_WORDS, TWILIO_START_WORDS, TWILIO_STOP_WORDS, gsm_validator,
    less_than_sms_char_limit, no_overlap_keyword, not_twilio_num,
    twilio_reserved, validate_lower
)

logger = logging.getLogger('apostello')


class RecipientGroup(models.Model):
    """Stores groups of recipients."""
    is_archived = models.BooleanField("Archived", default=False)
    name = models.CharField(
        "Name of group",
        max_length=30,
        unique=True,
        validators=[gsm_validator],
    )
    description = models.CharField("Group description", max_length=200, )

    def send_message(self, content, sent_by, eta=None):
        """Send message to group."""
        group_send_message_task.delay(content, self.name, sent_by, eta)

    def archive(self):
        """Archive the group."""
        self.is_archived = True
        self.save()

    @cached_property
    def all_recipients(self):
        return self.recipient_set.all()

    @property
    def all_recipients_names(self):
        """List of the names of recipients."""
        return [str(x) for x in self.all_recipients]

    def calculate_cost(self):
        """Calculate the cost of sending to this group."""
        return settings.TWILIO_SENDING_COST * self.all_recipients.count()

    @cached_property
    def get_absolute_url(self):
        """Url for this group."""
        return reverse('group', args=[str(self.pk)])

    @cached_property
    def get_api_url(self):
        """Url for group list api end point."""
        return reverse('api:group', args=[str(self.pk)])

    @cached_property
    def get_table_url(self):
        """Url for group list page."""
        return reverse('recipient_groups')

    def __str__(self):
        """Pretty representation."""
        return self.name

    class Meta:
        ordering = ['name']

{'fraction_non_alphanumeric': 0.09389671361502347, 'fraction_numerical': 0.0019561815336463224, 'mean_word_length': 3.6608933454876937, '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': '1634621', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1466, 'n_words': 382}