<commit_before>"""Interact with the Circonus annotation API."""

from datetime import datetime
from functools import wraps

import time


class Annotation(object):
    """Context manager and decorator for creating annotations."""

    RESOURCE_PATH = "annotation"

    @staticmethod
    def datetime_to_int(dt):
        """Convert the given datetime object into an integer."""
        return int(time.mktime(dt.timetuple()))

    def __init__(self, client, title, category, description="", rel_metrics=None):
        self.client = client
        self.title = title
        self.category = category
        self.description = description
        self.rel_metrics = [] if rel_metrics is None else rel_metrics
        self.start = None
        self.stop = None
        self.response = None

    def __call__(self, f):
        """Decorator for creating an annotation around a function or method."""
        @wraps(f)
        def wrapper(*args, **kwargs):
            self.start = datetime.utcnow()
            try:
                r = f(*args, **kwargs)
            finally:
                self.stop = datetime.utcnow()
                self.create()
            return r
        return wrapper<commit_msg>Ensure annotation UTC.<commit_after>"""Interact with the Circonus annotation API."""

from calendar import timegm
from datetime import datetime
from functools import wraps


class Annotation(object):
    """Context manager and decorator for creating annotations."""

    RESOURCE_PATH = "annotation"

    @staticmethod
    def datetime_to_int(dt):
        """Convert the given datetime object into an integer."""
        return int(timegm(dt.timetuple()))

    def __init__(self, client, title, category, description="", rel_metrics=None):
        self.client = client
        self.title = title
        self.category = category
        self.description = description
        self.rel_metrics = [] if rel_metrics is None else rel_metrics
        self.start = None
        self.stop = None
        self.response = None

    def __call__(self, f):
        """Decorator for creating an annotation around a function or method."""
        @wraps(f)
        def wrapper(*args, **kwargs):
            self.start = datetime.utcnow()
            try:
                r = f(*args, **kwargs)
            finally:
                self.stop = datetime.utcnow()
                self.create()
            return r
        return wrapper
{'fraction_non_alphanumeric': 0.09492364836978952, 'fraction_numerical': 0.0, 'mean_word_length': 2.2580645161290325, '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': '2604814', 'n_tokens_mistral': 637, 'n_tokens_neox': 612, 'n_words': 201}