<commit_before>"""
Provides data handlers that can push messages to a zipline.core.DataFeed
"""
import datetime
import random
import pytz

import zipline.messaging as zm
import zipline.protocol as zp


class TradeDataSource(zm.DataSource):

    def send(self, event):
        """
        :param dict event: is a trade event with data as per
                           :py:func: `zipline.protocol.TRADE_FRAME`
        :rtype: None
        """
        event.source_id = self.get_id
        message = zp.DATASOURCE_FRAME(event)
        self.data_socket.send(message)


class RandomEquityTrades(TradeDataSource):
    """
    Generates a random stream of trades for testing.
    """

    def __init__(self, sid, source_id, count):
        zm.DataSource.__init__(self, source_id)
        self.count          = count
        self.incr           = 0
        self.sid            = sid
        self.trade_start    = datetime.datetime.now().replace(tzinfo=pytz.utc)
        self.minute         = datetime.timedelta(minutes=1)
        self.price          = random.uniform(5.0, 50.0)


    def get_type(self):
        zp.COMPONENT_TYPE.SOURCE

    def do_work(self):
        if(self.incr == self.count):
            self.signal_done()
            return

        self.price = self.price + random.uniform(-0.05, 0.05)
        volume = random.randrange(100,10000,100)

        event = zp.namedict({
            #'source_id' : self.get_id,
            "type"      : zp.DATASOURCE_TYPE.TRADE,
            "sid"       : self.sid,
            "price"     : self.price,
            "volume"    : volume,
            "dt"        : self.trade_start + (self.minute * self.incr),
        })
<commit_msg>removed the commented out line that was setting the source id. parent class ensures id is set.<commit_after>"""
Provides data handlers that can push messages to a zipline.core.DataFeed
"""
import datetime
import random
import pytz

import zipline.messaging as zm
import zipline.protocol as zp


class TradeDataSource(zm.DataSource):

    def send(self, event):
        """
        :param dict event: is a trade event with data as per
                           :py:func: `zipline.protocol.TRADE_FRAME`
        :rtype: None
        """
        event.source_id = self.get_id
        message = zp.DATASOURCE_FRAME(event)
        self.data_socket.send(message)


class RandomEquityTrades(TradeDataSource):
    """
    Generates a random stream of trades for testing.
    """

    def __init__(self, sid, source_id, count):
        zm.DataSource.__init__(self, source_id)
        self.count          = count
        self.incr           = 0
        self.sid            = sid
        self.trade_start    = datetime.datetime.now().replace(tzinfo=pytz.utc)
        self.minute         = datetime.timedelta(minutes=1)
        self.price          = random.uniform(5.0, 50.0)


    def get_type(self):
        zp.COMPONENT_TYPE.SOURCE

    def do_work(self):
        if(self.incr == self.count):
            self.signal_done()
            return

        self.price = self.price + random.uniform(-0.05, 0.05)
        volume = random.randrange(100,10000,100)

        event = zp.namedict({
            "type"      : zp.DATASOURCE_TYPE.TRADE,
            "sid"       : self.sid,
            "price"     : self.price,
            "volume"    : volume,
            "dt"        : self.trade_start + (self.minute * self.incr),
        })

{'fraction_non_alphanumeric': 0.10414827890556046, 'fraction_numerical': 0.01412180052956752, 'mean_word_length': 1.8936170212765957, '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': '5130828', 'n_tokens_mistral': 1091, 'n_tokens_neox': 1018, 'n_words': 236}