<commit_before>
import re

from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

from sorl.thumbnail import get_thumbnail


def round_number(value, decimal_places=2, down=False):

    assert decimal_places > 0
    factor = 1.0 ** decimal_places
    sign = -1 if value < 0 else 1
    return int(value * factor + sign * (0 if down else 0.5)) / factor


def format_number(value):

    append_comma = lambda match_object: "%s," % match_object.group(0)

    value = "%.2f" % float(value)
    value = re.sub("(\d)(?=(\d{3})+\.)", append_comma, value)

    return value


def format_price(price, round_price=False):
    price = float(price)
    return format_number(round_number(price) if round_price else price)


def get_show_on_site_link(url):
    return mark_safe(
        '<a href="%s" target="_blank">%s</a>' % (url, _('Show on site')))


def get_preview(field, width=100):

    if not field:
        return '-----'
    try:
        url = get_thumbnail(field.file, str(width)).url
    except IOError:
        return _('Image not found')

    return mark_safe('<img src="%s" style="width: %spx;" title="%s" />' % (
        url, width, field.path))
<commit_msg>Create `get_file_upload_path` method.<commit_after>
import re

from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

from sorl.thumbnail import get_thumbnail


def round_number(value, decimal_places=2, down=False):

    assert decimal_places > 0
    factor = 1.0 ** decimal_places
    sign = -1 if value < 0 else 1
    return int(value * factor + sign * (0 if down else 0.5)) / factor


def format_number(value):

    append_comma = lambda match_object: "%s," % match_object.group(0)

    value = "%.2f" % float(value)
    value = re.sub("(\d)(?=(\d{3})+\.)", append_comma, value)

    return value


def format_price(price, round_price=False):
    price = float(price)
    return format_number(round_number(price) if round_price else price)


def get_show_on_site_link(url):
    return mark_safe(
        '<a href="%s" target="_blank">%s</a>' % (url, _('Show on site')))


def get_preview(field, width=100):

    if not field:
        return '-----'
    try:
        url = get_thumbnail(field.file, str(width)).url
    except IOError:
        return _('Image not found')

    return mark_safe('<img src="%s" style="width: %spx;" title="%s" />' % (
        url, width, field.path))


def get_file_upload_path(folder, filename):
    tz_now = timezone.localtime(timezone.now()).strftime('%Y_%m_%d_%H_%M')
    return '%s/%s.%s' % (folder, tz_now, filename.split('.')[-1])

{'fraction_non_alphanumeric': 0.14516735614892817, 'fraction_numerical': 0.01241068070703272, 'mean_word_length': 3.547008547008547, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6361917', 'n_tokens_mistral': 948, 'n_tokens_neox': 901, 'n_words': 230}