<commit_before># -*- coding: utf-8 -*-
#
# © 2012 <NAME>
# Author: <NAME> <<EMAIL>>
#
import datetime
class Packet(object):
    """
    Packet class represents the data that came in down the stream. It breaks the
    data into timestamp, event string and version.
    """
    def __new__(cls, encoded_data, *args, **kwargs):
        implementation = super(Packet, cls).__new__(cls, *args, **kwargs)
        implementation.timestamp = encoded_data.split("!")[0]
        implementation.event = encoded_data.split("!")[1]
        implementation.version = encoded_data.split("!")[2]

        return implementation

    def __init__(self, configuration):
        """
        Construct a packet object with the provided key
        configuration. Configuration is an iterable of tuples, the first element
        of the tuple is either, seconds, minutes, hours, days, weeks, months, or
        years and the second element of the tuple is an integer representing the
        number of keys to keep for this granularity
        """
        self.configuration = configuration

    def constructKeys(self):
        """
        Returns all the keys for the packet based on the configuration
        """
        event_date = datetime.datetime.fromtimestamp(self.timestamp)
        now = datetime.datetime.now()
        keys = []
        for (granularity, count_of_keys) in self.configuration:
            todays_value = Packet.determineTimeAgo(event_date, granularity)
            key_value = Packet.determineTimeAgo(event_date, granularity)
            if todays_value - key_value < count_of_keys:
                keys.append("%s:%s:%s" % (key_value, self.event, self.version,))
        return keys

    @classmethod
    def determineTimeAgo(cls, event_date, granularity):
        """<commit_msg>move configuration to the constructKeys method<commit_after># -*- coding: utf-8 -*-
#
# © 2012 <NAME>
# Author: <NAME> <<EMAIL>>
#
import datetime
class Packet(object):
    """
    Packet class represents the data that came in down the stream. It breaks the
    data into timestamp, event string and version.
    """
    def __new__(cls, encoded_data, *args, **kwargs):
        implementation = super(Packet, cls).__new__(cls, *args, **kwargs)
        implementation.timestamp = float(encoded_data.split("!")[0])
        implementation.event = encoded_data.split("!")[1]
        implementation.version = encoded_data.split("!")[2]

        return implementation

    def constructKeys(self, configuration):
        """
        Returns all the keys for the packet based on the configuration
        """
        event_date = datetime.datetime.fromtimestamp(self.timestamp)
        now = datetime.datetime.now()
        keys = []
        for (granularity, count_of_keys) in configuration:
            todays_value = Packet.determineTimeAgo(now, granularity)
            key_value = Packet.determineTimeAgo(event_date, granularity)
            if todays_value - key_value < count_of_keys:
                keys.append("%s:%s:%s" % (key_value, self.event, self.version,))
        return keys

    @classmethod
    def determineTimeAgo(cls, event_date, granularity):
        """
{'fraction_non_alphanumeric': 0.1067469116249604, 'fraction_numerical': 0.005068102629078239, 'mean_word_length': 2.8325242718446604, 'pattern_counts': {'":': 0, '<': 13, '<?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': '6571190', 'n_tokens_mistral': 877, 'n_tokens_neox': 840, 'n_words': 254}