Beispiel #1
0
 def __init__(self, write_key="invalid_key", base_url=None, verbose=True, **kwargs ):
     """ Create the ability to write """
     super().__init__(base_url=base_url or api_url(),**kwargs)
     string_write_key = write_key if isinstance(write_key,str) else write_key.decode()
     assert self.key_difficulty(string_write_key), "Invalid write_key. Mine one at muid.org. "
     self.write_key = string_write_key
     self.verbose   = verbose
Beispiel #2
0
 def __init__(self, write_key="invalid_key", base_url=None, verbose=True, **kwargs):
     """ Create the ability to write """
     super().__init__(base_url=base_url or api_url(), **kwargs)
     string_write_key = write_key if isinstance(write_key, str) else write_key.decode()
     assert self.key_difficulty(string_write_key), "Invalid write_key. Mine one at muid.org. "
     self.write_key = string_write_key  # Optional: location of your repo you wish to advertise
     self.verbose = verbose
     self.code = self.shash(write_key)  # Unique identifier that can be shared
     self.animal = self.animal_from_key(write_key)  # ... and corresponding spirit animal
Beispiel #3
0
 def __init__(self, base_url=None, **kwargs):
     """ Establish connection and adopt configuration parameters from site """
     super().__init__(base_url=base_url or api_url(), **kwargs)
    def __init__(self,
                 write_key=None,
                 base_url=None,
                 verbose=False,
                 quietude=50,
                 stop_loss=10,
                 min_budget=0.,
                 max_budget=10,
                 min_lags=25,
                 max_lags=1000000,
                 sponsor_min=12,
                 use_environ=False,
                 difficulty=10,
                 max_active=20,
                 **ignored):
        """
            param: write_key  str    Valid write_key    See www.microprediction.org or www.muid.com for more details
            param: base_url   str    e.g  'http://api.microprediction.org'  or 'http://devapi.microprediction.org' for the brave. Defaults to what is at http://config.microprediction.org
            param: verbose    bool   Verbosity parameter passed to MicroWriter
            param: quietude   int    If set to 10, will only barf messages 1/10th of the time
            param: stop_loss  float  How much to lose before giving up on a stream
            param: min_budget int
            param: max_budget int    These set the low/high limits for table stakes. See _default_candidate_streams() method
            param: min_lags   int
            param: max_lags   int    These set the short/long limits for the number of lags in a time series. Does your algo need or want a lot of data?
            param: sponsor_min int   Minimum write_key difficulty of the stream sponsor. E.g. set to 13 to only look at streams where people bothered to generate a 13-MUID.
            param: use_environ bool  Set True if you want crawler to look in environ for write_key, and store write_key there if it mines one
            param: difficulty  int   Used to create key if none supplied, but otherwise ignored
            param: **ignored         For future compatibility

        """

        # Parameter management
        super().__init__(base_url=base_url or api_url(),
                         write_key=new_key_if_none(write_key,
                                                   use_environ=use_environ,
                                                   difficulty=difficulty),
                         verbose=verbose)
        assert self.key_difficulty(
            self.write_key
        ) >= 7, "Invalid write_key for crawler. Use new_key(difficulty=11) to create one. "
        assert not self.base_url[
            -1] == '/', 'Base url should not have trailing /'
        if stop_loss <= 0:
            print(
                'WARNING: Did you mean to set a negative stop loss? If you are running the crawler for the first time this might result in almost immediate withdrawal. ',
                flush=True)
        self.quietude = int(
            quietude)  # e.g. if set to 10, will only print 1/10th of the time
        self.sponsor_min = sponsor_min  # Only choose streams with sponsors at least this long
        self.stop_loss = stop_loss  # How much to lose before giving up on a stream
        self.original_stop_loss = stop_loss
        self.min_budget = min_budget  # Play with highly competitive algorithms?
        self.max_budget = max_budget  #
        self.min_lags = min_lags  # Insist on some historical data
        self.max_lags = max_lags
        self.max_active = max_active

        # Caching somewhat expensive operations to avoid taxing the system unnecessarily
        # (There might be a tiny charge implemented for these operations at some point in the future)
        self.performance = self.get_performance() or self.get_performance()
        self.active = self.get_active() or self.get_active(
        )  # List of active horizons
        self.prizes = self.get_prizes()  # These don't change too often
        self.sponsors = self.get_sponsors()  # Ditto
        self.budgets = self.get_budgets()  # Ditto
        self.stream_candidates = self.candidate_streams(
        )  # Order important. Should follow other caching

        # State - times
        self.start_time = None  # Don't start this clock until run() is called
        self.end_time = None  # ditto
        self.seconds_until_next = 10
        self.last_performance_check = time.time()
        self.last_new_horizon = time.time()
        self.last_withdrawal_reset = time.time()

        # State - other
        self.pending_cancellations = list(
        )  # List of horizons we have sent cancellation requests
        self.given_up = list(
        )  # A list of horizons where we have or will cancel entries
        self.prediction_schedule = dict(
        )  # A manifest of upcoming data arrivals, keyed by horizon
        self.message_log = list()  # A log of detailed messages
Beispiel #5
0
    def __init__(self,
                 write_key=None,
                 base_url=None,
                 verbose=False,
                 quietude=50,
                 stop_loss=10,
                 min_budget=0.,
                 max_budget=10,
                 min_lags=25,
                 max_lags=1000000,
                 sponsor_min=12,
                 **ignored):
        """
            param: write_key  str    Valid write_key    See www.microprediction.org or www.muid.com for more details
            param: base_url   str    e.g  'http://api.microprediction.org'  or 'http://devapi.microprediction.org' for the brave. Defaults to what is at http://config.microprediction.org
            param: verbose    bool   Verbosity parameter passed to MicroWriter
            param: quietude   int    If set to 10, will only barf messages 1/10th of the time
            param: stop_loss  float  How much to lose before giving up on a stream
            param: min_budget int
            param: max_budget int    These set the low/high limits for table stakes. See _default_candidate_streams() method
            param: min_lags   int
            param: max_lags   int    These set the short/long limits for the number of lags in a time series. Does your algo need or want a lot of data?
            param: sponsor_min int   Minimum write_key difficulty of the stream sponsor. E.g. set to 13 to only look at streams where people bothered to generate a 13-MUID.
            param: **ignored         For future compatability

        """

        # Parameter management
        super().__init__(base_url=base_url or api_url(),
                         write_key=write_key,
                         verbose=verbose)
        assert self.key_difficulty(
            write_key
        ) >= 7, "Invalid write_key for crawler. See www.muid.org to mine one. "
        assert not self.base_url[
            -1] == '/', 'Base url should not have trailing /'
        assert stop_loss > 0, "Stop loss must be positive "
        self.quietude = int(
            quietude)  # e.g. if set to 10, will only print 1/10th of the time
        self.sponsor_min = sponsor_min  # Only choose streams with sponsors at least this long
        self.stop_loss = stop_loss  # How much to lose before giving up on a stream
        self.min_budget = min_budget  # Play with highly competitive algorithms?
        self.max_budget = max_budget  # Play with highly competitive algorithms?
        self.min_lags = min_lags  # Insist on historical data
        self.max_lags = max_lags

        # Caching somewhat expensive operations to avoid taxing the system unnecessarily
        # There might be a tiny charge implemented for these operations at some point in the future
        self.performance = self.get_performance()
        self.active = self.get_active()  # List of active horizons
        self.stream_candidates = self.candidate_streams()

        # State - times since ...
        self.seconds_until_next = 10
        self.last_performance_check = time.time()
        self.last_new_horizon = time.time()
        self.next_prediction_time = dict()  # Indexed by horizon

        # State - other
        self.withdrawn = list(
        )  # List of horizons we have withdrawn from, or will never enter
        self.next_prediction_time = dict(
        )  # A manifest of upcoming data arrivals
        self.message_log = list()  # A log of detailed messages