示例#1
0
    def __init__(self, source_id, syntax, body, event_id=None,
                 application_id=None, aggregator_id=[], event_type=None,
                 timestamp=None, extra_headers=None):
        """Creates a new event.

        'body' must be the textual representation of the event, or an
        object providing that textual representation through 'str()'.

        When the created event has to be an instance of a specific
        subclass (e.g. an 'RDFEvent'), the static 'create()' method
        should be used instead.

        """
        self.event_id = event_id or ztreamy.random_id()
        self.source_id = source_id
        self.syntax = syntax
        self.body = body
        if aggregator_id is None:
            aggregator_id = []
        else:
            if type(aggregator_id) is not list:
                self.aggregator_id = [str(aggregator_id)]
            else:
                self.aggregator_id = [str(e) for e in aggregator_id]
        self.event_type = event_type
        self.timestamp = timestamp or ztreamy.get_timestamp()
        self.application_id = application_id
        if extra_headers is not None:
            self.extra_headers = extra_headers
        else:
            self.extra_headers = {}
示例#2
0
def randomize_timestamps(events, interval_duration):
    current_time = ztreamy.rfc3339_as_time(events[0].timestamp)
    time_max = current_time + interval_duration - 1
    exp_rate = 1.3 * len(events) / interval_duration
    for event in events:
        current_time += random.expovariate(exp_rate)
        timestamp = int(current_time)
        if timestamp > time_max:
            timestamp = time_max
        event.timestamp = ztreamy.get_timestamp(date=timestamp)
示例#3
0
def randomize_timestamps(events, interval_duration):
    current_time = ztreamy.rfc3339_as_time(events[0].timestamp)
    time_max = current_time + interval_duration - 1
    exp_rate = 1.3 * len(events) / interval_duration
    for event in events:
        current_time += random.expovariate(exp_rate)
        timestamp = int(current_time)
        if timestamp > time_max:
            timestamp = time_max
        event.timestamp = ztreamy.get_timestamp(date=timestamp)
示例#4
0
    def __init__(self,
                 source_id,
                 syntax,
                 body,
                 event_id=None,
                 application_id=None,
                 aggregator_id=[],
                 event_type=None,
                 timestamp=None,
                 extra_headers=None):
        """Creates a new event.

        'body' must be the textual representation of the event, or an
        object providing that textual representation through 'str()'.

        When the created event has to be an instance of a specific
        subclass (e.g. an 'RDFEvent'), the static 'create()' method
        should be used instead.

        """
        self.event_id = event_id or ztreamy.random_id()
        self.source_id = source_id
        self.syntax = syntax
        self.body = body
        if aggregator_id is None:
            aggregator_id = []
        else:
            if type(aggregator_id) is not list:
                self.aggregator_id = [str(aggregator_id)]
            else:
                self.aggregator_id = [str(e) for e in aggregator_id]
        self.event_type = event_type
        self.timestamp = timestamp or ztreamy.get_timestamp()
        self.application_id = application_id
        if extra_headers is not None:
            self.extra_headers = extra_headers
        else:
            self.extra_headers = {}
示例#5
0
    def __init__(self, source_id, syntax, body, event_id=None,
                 application_id=None, aggregator_id=[], event_type=None,
                 timestamp=None, extra_headers=None):
        """Creates a new event.

        'body' must be the textual representation of the event, or an
        object providing that textual representation through 'str()'.

        When the created event has to be an instance of a specific
        subclass (e.g. an 'RDFEvent'), the static 'create()' method
        should be used instead.

        """
        if source_id is None:
            raise ValueError('Required event field missing: source_id')
        elif not syntax:
            raise ValueError('Required event field missing: syntax')
        self.event_id = event_id or ztreamy.random_id()
        self.source_id = source_id
        self.syntax = syntax
        self.body = body
        if aggregator_id is None:
            aggregator_id = []
        elif type(aggregator_id) is not list:
            self.aggregator_id = [str(aggregator_id)]
        else:
            self.aggregator_id = [str(e) for e in aggregator_id]
        self.event_type = event_type
        self._timestamp = timestamp or ztreamy.get_timestamp()
        self._time = None
        self.application_id = application_id
        self.extra_headers = {}
        if extra_headers is not None:
            # Do this in order to ensure type checking
            for header, value in extra_headers.iteritems():
                self.set_extra_header(header, value)
示例#6
0
 def timestamp(self):
     return ztreamy.get_timestamp(self.time)
示例#7
0
 def timestamp(self):
     return ztreamy.get_timestamp(self.time)