Ejemplo n.º 1
0
 def __init__(self,
              names,
              func,
              interval,
              write_key="invalid_key",
              base_url=None,
              verbose=True,
              func_args=None,
              with_copulas=False,
              **kwargs):
     """  Create multiple streams by polling every 20 minutes, say
             param:
             names        [ str ]    stream name ending in .json
             func:        function    returns data from some live source, ideally [ float ] but you can override determine_next_values method
             interval:    int         minutes between polls
             func_args    dict        optional dict of arguments to be passed to func
             with_copulas bool        Whether to create derived copula streams, or just individual unrelated streams
         """
     super().__init__(base_url=base_url or api_url(),
                      write_key=write_key,
                      verbose=verbose,
                      func=func,
                      func_args=func_args,
                      interval=interval,
                      names=names,
                      with_copulas=with_copulas,
                      **kwargs)
     self.prev_values = None
     self.feed_state = MultiChangePoll.COLD
     self.current_values = None
Ejemplo n.º 2
0
 def __init__(self,
              name,
              func,
              interval,
              write_key="invalid_key",
              base_url=None,
              verbose=True,
              func_args=None,
              mine=False,
              **kwargs):
     """  Create a stream by polling every 20 minutes, say
         param: name  str   stream name ending in .json
         func:        function    returns float  (data feed function)
         interval:    int     minutes between polls
         func_args    dict    optional dict of arguments to be passed to func
         mine:        bool    Supply mine=True if you want to automatically mine MUIDs to help keep the stream alive
     """
     assert self.is_valid_name(name), 'name not valid'
     super().__init__(base_url=base_url or api_url(),
                      write_key=write_key,
                      verbose=verbose)
     self.name = name
     self.interval = interval
     self.func = func
     self.func_args = func_args
     self.recent = list()
     self.mining_time = 0
     self.mining_success = 0
     self.test_value = self.call_func()  # Fail fast
     self.mine = mine
     print('Created poller. Example value ' + str(self.test_value))
Ejemplo n.º 3
0
    def __init__(self,
                 names,
                 func,
                 interval,
                 write_key="invalid_key",
                 base_url=None,
                 verbose=True,
                 func_args=None,
                 with_copulas=False,
                 **kwargs):
        """  Create a stream by polling every 20 minutes, say
                param: names  [ str ]    stream name ending in .json
                func:        function    returns raw data from some live source, ideally [ float ] but you can override determine_next_values method
                interval:    int         minutes between polls
                func_args    dict        optional dict of arguments to be passed to func

            """
        assert all([self.is_valid_name(name)
                    for name in names]), 'name not valid'
        super().__init__(base_url=base_url or api_url(),
                         write_key=write_key,
                         verbose=verbose,
                         func=func,
                         func_args=func_args,
                         interval=interval,
                         name='never_used.json')
        self.names = names
        self.with_copulas = with_copulas