<commit_before>from wsw_stats.utils import get_backend


def put_metric(slug, object=None, count=1, **kwargs):
    backend = get_backend()
    backend.put_metric(slug, object=object, count=count, **kwargs)<commit_msg>Update api<commit_after>from .models import Metric, MetricItem


def put_metric(slug, object=None, count=1, **kwargs):
    from django.conf import settings
    from django.contrib.sites.models import Site

    try:
        metric = Metric.objects.get(slug=slug)
    except Metric.DoesNotExist:
        metric = Metric.objects.create(slug=slug, name=slug)

    site = Site.objects.get(pk=settings.SITE_ID)

    MetricItem.objects.create(
        metric=metric,
        content_object=object,
        site=site,
        count=count
    )
{'fraction_non_alphanumeric': 0.1077127659574468, 'fraction_numerical': 0.0026595744680851063, 'mean_word_length': 3.6770186335403725, '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': '4781939', 'n_tokens_mistral': 240, 'n_tokens_neox': 239, 'n_words': 48}