Exemplo n.º 1
0
	def __init__(self,load_mode='demo'):
		super(Server, self).__init__()
		self.threads = []
		self.open_port()

		#
		# user keys
		#
		mcfg = json.load(open(conf.conf_dir + conf.conf_main))
		self.my_name = mcfg['username']
		try:
			self.private,self.public = encrypt.import_keys(conf.key_dir+mcfg['private_key'],conf.key_dir+mcfg['public_key'])
		except Exception as e:
			self.log('cannot find keys: (%s, %s) %s'%(conf.key_dir+mcfg['private_key'],conf.key_dir+mcfg['public_key'],e))
			sys.exit()


		#
		# runtime tables:
		# current active connections
		#
		self.__client_socket  = {} 
		self.__socket_clinet  = {}
		
		#
		# databes of existing users and their keys
		#
		self.blockchain = Blockchain()

		self.network_state = 0
		if load_mode == 'full-load':
			self.history = History()
	def __init__(self, valid_neuron_ids, max_response, max_signal, neurons, memory_timepoints):
		super(CharacterSequenceTransducer, self).__init__(valid_neuron_ids=valid_neuron_ids,
															max_response=max_response,
															max_signal=max_signal,
															neurons=neurons)

		self._index_to_char = {	26 : ' ',
								27 : '\n',
								28 : '\t',
								29 : ',',
								30 : '\'',
								31 : '"',
								32 : '.',
								33 : '!',
								34 : '?',
								35 : '~'
		}
		for x in range(26):
			self._index_to_char[x] = str(unichr(x + 97))

		self._char_to_index = self.reverse_map(self._index_to_char)
		self._default_index = 35
		self._default_char = '~'
		self._vector_length_needed = self._default_index + 1
		self._history = History(num_timepoints=memory_timepoints, vector_length=self._vector_length, classes=self._char_to_index.keys())
Exemplo n.º 3
0
def examine(lines, pic_kind):
    resolve = [-36, -5, 97, 44, -24]
    length, same, deltaes,days,opens,actuals,expecteds = 0, 0, [],[],[],[],[]
    for line in lines:
        record = History.get_from_historyline(line)
	record = History.norm(record)
	expected = get_expected(resolve, record)
	actual = record.closed_today 
	delta = expected - actual
	deltaes.append(delta)
	days.append(record.day)
	opens.append(record.open_price)
	actuals.append(actual)
	expecteds.append(expected)
	print 'open: %s,actual: %s, expected: %s, delta: %s' % (record.open_price, actual, expected, delta)

	if (expected - record.open_price) * (actual - record.open_price) > 0:
	    same += 1
	length += 1
    print 'direction_same: %d, length: %d, direction_same/length: %s' % (same, length, float(same)/length)
    x = [ i + 1 for i in range(len(opens))]
    if pic_kind == 'delta':
        pydrawer.draw(x, deltaes, 'bo')
    if pic_kind == 'lines':
        pydrawer.draw(x, opens,'k', x, actuals,'r-', x, expecteds,'bo')
Exemplo n.º 4
0
    def revert_actions(self, arg):
        """
        Calculate the actions necessary to revert to a given state, the
        argument may be one of:
          * complete set of eggs, i.e. a set of egg file names
          * revision number (negative numbers allowed)
          * datetime in ISO format, i.e. YYYY-mm-dd HH:MM:SS
          * simple strings like '1 day ago', see parse_dt module
        """
        if self.hook:
            raise NotImplementedError
        h = History(self.prefixes[0])
        h.update()
        if isinstance(arg, set):
            state = arg
        else:
            state = self._get_state(h, arg)

        curr = h.get_state()
        if state == curr:
            return []

        res = []
        for egg in curr - state:
            res.append(("remove", egg))

        for egg in state - curr:
            if not isfile(join(self.local_dir, egg)):
                self._connect()
                if self.remote.exists(egg):
                    res.append(("fetch_0", egg))
                else:
                    raise EnpkgError("cannot revert -- missing %r" % egg)
            res.append(("install", egg))
        return res
Exemplo n.º 5
0
    def __init__(self, extender, namespace=None):
        self.extender = extender
        self.callbacks = extender.callbacks
        self.helpers = extender.helpers

        self._locals = dict(Burp=extender, items=[])
        self._buffer = []
        self.history = History(self)

        if namespace is not None:
            self._locals.update(namespace)

        self.interp = JythonInterpreter(self, self._locals)

        self.textpane = JTextPane(keyTyped=self.keyTyped,
                                  keyPressed=self.keyPressed)

        self.textpane.setFont(Font('Monospaced', Font.PLAIN, 11))
        self.callbacks.customizeUiComponent(self.textpane)

        self.initKeyMap()

        self.document.remove(0, self.document.getLength())
        self.write('Burp Extender Jython Shell', prefix='')
        self.write(self.PS1)

        self.textpane.requestFocus()
        self.callbacks.getStdout().write('Interactive interpreter ready...\n')
Exemplo n.º 6
0
    def __init__(self, cli_display=False):

        self._pwhite = None
        self._pblack = None

        self._w_king_moved = False
        self._b_king_moved = False

        self._w_en_passant = False
        self._b_en_passant = False

        self._w_ressign = False
        self._b_ressign = False

        self._promotion_sq = None

        self.history = History()

        self._board = [[None for i in range(8)] for i in range(8)]
        self._init_pieces()
        self._current_color = Color.WHITE

        self._cli_display = cli_display
        if self._cli_display:
            self._display()
Exemplo n.º 7
0
    def transfer(self, accountFrom, accountTo, amount):

        if accountFrom.get_bank_id() != accountTo.get_bank_id():
            print("Przelew miedzy bankowy")
            if accountFrom.get_account_balance() < amount:
                return False
            result = self.kir.make_transfer(accountTo.get_bank_id(), amount,
                                            accountTo.getId())
            if result == False:
                return result

            accountFrom.withdraw(amount, True)
            accountTo.deposit(amount, True)
            h_from = History(
                "Outgoing transfer to " + str(accountTo.getId()) +
                ", value: " + str(amount), accountFrom.getId())
            h_to = History(
                "Incoming transfer from " + str(accountFrom.getId()) +
                ", value: " + str(amount), accountTo.getId())
            accountFrom.getHistory().append(h_from)
            accountTo.getHistory().append(h_to)
            return True

        elif accountFrom.withdraw(amount, True):
            accountTo.deposit(amount, True)
            h_from = History(
                "Outgoing transfer to " + str(accountTo.getId()) +
                ", value: " + str(amount), accountFrom.getId())
            h_to = History(
                "Incoming transfer from " + str(accountFrom.getId()) +
                ", value: " + str(amount), accountTo.getId())
            accountFrom.getHistory().append(h_from)
            accountTo.getHistory().append(h_to)
            return True
        return False
Exemplo n.º 8
0
def main():
    env = RunEnv(visualize=False)
    env.reset(difficulty = 0)
    agent = RDPG(env)

    returns = []
    rewards = []

    for episode in xrange(EPISODES):
        state = env.reset(difficulty = 0)
        reward_episode = []
        print ("episode:",episode)
        #Initializing empty history
        history = History(state)
        # Train
        for step in xrange(env.spec.timestep_limit):
            action = agent.noise_action(history)
            next_state,reward,done,_ = env.step(action)
            # appending to history
            history.append(next_state,action,reward)
            reward_episode.append(reward)
            if done:
                break
        # storing the history into replay buffer and if the number of histories sequence is above the threshod, start training
        agent.perceive(history)
Exemplo n.º 9
0
 def schedule(self, msgs_to_process=None, timers_to_process=None):
     """Schedule given number of pending messages"""
     if msgs_to_process is None:
         msgs_to_process = 32768
     if timers_to_process is None:
         timers_to_process = 32768
     while self.queue:
         msg = self.queue.popleft()
         try:
             c = zerorpc.Client(timeout=1)
             c.connect('tcp://' + msg.to_node)
         except zerorpc.TimeoutExpired:
             _logger.info("Drop %s->%s: %s as destination down", msg.from_node, msg.to_node, msg)
             History.add("drop", msg)
             self.dynamo.retry_request(msg)
         if isinstance(msg, ResponseMessage):
                     # figure out the original request this is a response to
             try:
                 reqmsg = msg.response_to.original_msg
             except Exception:
                 reqmsg = msg.response_to
         History.add("deliver", msg)
         m = pickle.dumps(msg)
         try:
             c.rcvmsg(m)
             c.close()
         except:
             print 'time out'
             print msg.to_node
             self.dynamo.retry_request(msg)
Exemplo n.º 10
0
def main():
    env = heli()
    #env.reset()
    agent = RDPG(env)

    returns = []
    rewards = []

    for episode in xrange(EPISODES):
        state = env.reset()
        reward_episode = []
        print("episode:", episode)
        #Initializing empty history
        history = History(state)
        # Train
        for step in xrange(1000):
            action = agent.noise_action(history)
            next_state, reward, done, _ = env.step(action[0][0], action[0][0],
                                                   s)
            # appending to history
            history.append(next_state, action, reward)
            reward_episode.append(reward)
            if done:
                break
        # storing the history into replay buffer and if the number of histories sequence is above the threshod, start training
        agent.perceive(history)
Exemplo n.º 11
0
class Shell:

  def __init__(self):
    self.builtins = Builtins(self)
    self.completion = Completion(self)
    self.history = History()
    self.javascript = Javascript()
    self.log = Log()
    self.prompt = Prompt()

  def execute(self, command):
    self.log.append(str(self.prompt) + command)
    self.history.append(command)

    if command:
      # execute builtins command
      try:
        self.builtins.execute(command.strip())
      except self.builtins.UnknownCommandError as e:
        self.log.append('websh: command not found: {0}'.format(e.command))
      except Exception as e:
        print 'Error in builtins: {0}'.format(e)

    return json.dumps({'javascript': str(self.javascript),
                       'log': str(self.log),
                       'prompt': str(self.prompt)})

  def template(self):
    # read template file
    file = open('data/template.html', 'r')
    template = string.Template(file.read())
    file.close()

    return template.substitute(log = str(self.log),
                               prompt = str(self.prompt))
Exemplo n.º 12
0
class Addon(AddonCore):
    """"""
    def __init__(self, parent, *args, **kwargs):
        """"""
        AddonCore.__init__(self)
        self.name = _("History")
        self.event_id = events.connect(cons.EVENT_DL_COMPLETE, self.trigger)
        self.parent = parent
        self.config = conf
        self.history = History()
        self.history_tab = HistoryContainer(self.history, self.parent)
    
    def get_menu_item(self):
        pass
        #WIDGET, TITLE, CALLBACK, SENSITIVE = range(4)
        #return (gtk.MenuItem(), _("History"), self.on_history) #can toggle
    
    def get_tab(self):
        return self.history_tab
    
    #def on_history(self, widget):
        #HistoryDlg(self.history, self.parent)
    
    def trigger(self, download_item, *args, **kwargs):
        """"""
        link = download_item.link if download_item.can_copy_link else None
        self.history.set_values(download_item.name, link, download_item.size, download_item.size_complete, download_item.path)
        #remove from the list.
        model = self.parent.downloads_list_gui.treeView.get_model()
        row = self.parent.downloads_list_gui.rows_buffer[download_item.id]
        model.remove(row.iter)
        del self.parent.downloads_list_gui.rows_buffer[download_item.id]
        del api.complete_downloads[download_item.id]
Exemplo n.º 13
0
 def test_simple_put(self):
     for _ in range(6):
         dynamo1.DynamoNode()
     a = dynamo1.DynamoClientNode('a')
     a.put('K1', None, 1)
     Framework.schedule()
     print History.ladder()
Exemplo n.º 14
0
    def init(self):
        log('initializing player class')
        self.dlgProgress = xbmcgui.DialogProgress()
        self.dlgProgress.create('Openlast', 'Initializing addon...')
        self.dlgProgress.update(0)

        self.tracks = self.loadAllTracks()

        artistCount = len(self.tracks.keys())
        trackCount = len(self.tracks.values())
        self.history = History(
            artistCount if artistCount < MAX_ARTIST_COUNT else
            MAX_ARTIST_COUNT, trackCount * 2 / 3)
        random.seed()

        lastfmUser = ''
        try:
            lastfmAddon = xbmcaddon.Addon('service.scrobbler.lastfm')
            lastfmUser = lastfmAddon.getSetting('lastfmuser')
        except RuntimeError:
            pass
        if 0 < len(lastfmUser):
            self.loadRecentTracks(lastfmUser)

        if self.dlgProgress.iscanceled() or self.tracks is None:
            self.dlgProgress.close()
            self.dlgProgress = None
            return False

        return True
Exemplo n.º 15
0
 def test_simple_put(self):
     for _ in range(6):
         dynamo1.DynamoNode()
     a = dynamo1.DynamoClientNode('a')
     a.put('K1', None, 1)
     Framework.schedule()
     print History.ladder()
Exemplo n.º 16
0
    def test_partition(self):
        dynamomessages._show_metadata = True
        all_nodes = self.partition()

        # Display, tweaking ordering of nodes so partition is in the middle
        print History.ladder(force_include=all_nodes, spacing=16, key=lambda x: ' ' if x.name == 'b' else x.name)
        dynamomessages._show_metadata = False
Exemplo n.º 17
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.storage = FileSystemStorage(serializer=JsonSerializer())
     self.history = History(self)
     self.ui = Ui_Main()
     self.scene = GraphScene(self)
     self.setupUi()
Exemplo n.º 18
0
 def calc(self):
     """Функция подсчета выражения, вывода и сохранения результата"""
     try:
         """Считает текущее введенное математическое выражение"""
         expr = self.window.entry_line.text()
         if self.num_sys_now != 10:
             expr = number_system.convert_num_sys_math_expr(
                 self.window.entry_line.text(), int(self.num_sys_now),
                 int(10))
         print("expr =", expr)
         tmp = calculate(expr)
         """Вывод результата в поле результата"""
         result = tmp.result
         if self.num_sys_now != 10:
             result = number_system.convert_num_sys_math_expr(
                 str(tmp.result), int(10), int(self.num_sys_now))
         self.window.result_field.setText(str(result))
         """Сохранение результата"""
         History.save(self.window.entry_line.text() + ' = ' +
                      str(tmp.result) + '\n')
         try:
             """В случае, если окно истории открыто - обновить его"""
             self.w_history.display()
         except:
             pass
     except:
         """В случае неудачи вывести в поле результата Fail"""
         self.window.result_field.setText("Fail")
Exemplo n.º 19
0
 def __init__(self, config):
     self.history = History(config['logserver']['hostname'],
                            config['logserver']['port'],
                            config['logserver']['db'],
                            config['logserver']['collection'])
                            
     self.bot = Bot(config, self.history)
    def process(self):
        data_operations = []
        transaction_dict = {}

        for t in self.tokens:
            if len(t) < 2:
                raise Exception('invalid token {0}'.format(t))

            operation_type = self.parse_operation_type(t)
            transaction_id = self.parse_transaction_id(t)

            data_item = None

            if (operation_type is OperationType.READ
                    or operation_type is OperationType.WRITE):
                data_item = self.parse_data_item(t)

            if transaction_id not in transaction_dict:
                transaction_dict[transaction_id] = Transaction(transaction_id)

            tx = transaction_dict[transaction_id]

            data_operation = DataOperation(operation_type, tx, data_item)
            data_operations.append(data_operation)
            tx.add_data_operation(data_operation)

        hist = History(transaction_dict.values())
        hist.set_schedule(data_operations)

        return hist
Exemplo n.º 21
0
    def __init__(self, game, x, y, width, fg, bg):
        self.game = game
        self.history = History()
        self.document = pyglet.text.document.UnformattedDocument()
        self.document.set_style(0, len(self.document.text),
                                {"color": (255, 255, 255, 255)})
        self.font = self.document.get_font()
        height = self.font.ascent - self.font.descent
        self.background = pyglet.shapes.Rectangle(x,
                                                  y - 20,
                                                  width,
                                                  height + 40,
                                                  color=(0, 0, 0),
                                                  batch=bg)

        self.layout = pyglet.text.layout.IncrementalTextLayout(self.document,
                                                               width - 40,
                                                               height,
                                                               multiline=False,
                                                               batch=fg)
        self.caret = pyglet.text.caret.Caret(self.layout,
                                             color=(255, 255, 255))

        self.layout.x = x + 20
        self.layout.y = y
Exemplo n.º 22
0
class Addon(AddonCore):
    """"""
    def __init__(self, parent, *args, **kwargs):
        """"""
        AddonCore.__init__(self)
        self.name = _("History")
        self.event_id = events.connect(cons.EVENT_DL_COMPLETE, self.trigger)
        self.parent = parent
        self.config = conf
        self.history = History()
        self.history_tab = HistoryContainer(self.history, self.parent)

    def get_menu_item(self):
        pass
        #WIDGET, TITLE, CALLBACK, SENSITIVE = range(4)
        #return (gtk.MenuItem(), _("History"), self.on_history) #can toggle

    def get_tab(self):
        return self.history_tab

    #def on_history(self, widget):
    #HistoryDlg(self.history, self.parent)

    def trigger(self, download_item, *args, **kwargs):
        """"""
        link = download_item.link if download_item.can_copy_link else None
        self.history.set_values(download_item.name, link, download_item.size,
                                download_item.size_complete,
                                download_item.path)
        #remove from the list.
        model = self.parent.downloads_list_gui.treeView.get_model()
        row = self.parent.downloads_list_gui.rows_buffer[download_item.id]
        model.remove(row.iter)
        del self.parent.downloads_list_gui.rows_buffer[download_item.id]
        del api.complete_downloads[download_item.id]
Exemplo n.º 23
0
 def test_put2_fail_nodes23_2(self):
     """Show second request for same key skipping failed nodes"""
     (a, pref_list) = self.put_fail_nodes23(dynamo2)
     coordinator = pref_list[0]
     from_line = len(History.history)
     a.put('K1', None, 2, destnode=coordinator)  # Send client request to coordinator for clarity
     Framework.schedule()
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
Exemplo n.º 24
0
 def cancel_timer(cls, tmsg):
     """Cancel the given timer"""
     for (this_prio, this_tmsg) in cls.pending:
         if this_tmsg == tmsg:
             _logger.debug("Cancel timer %s for node %s reason %s", id(tmsg), tmsg.from_node, tmsg.reason)
             cls.pending.remove((this_prio, this_tmsg))
             History.add("cancel", tmsg)
             return
Exemplo n.º 25
0
 def test_put2_fail_nodes23_5(self):
     """Show Put after a failure including handoff, and the resulting Pings"""
     (a, pref_list) = self.put_fail_nodes23(dynamo4)
     coordinator = pref_list[0]
     from_line = len(History.history)
     a.put('K1', None, 2, destnode=coordinator)  # Send client request to coordinator for clarity
     Framework.schedule(timers_to_process=10)
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
Exemplo n.º 26
0
 def __init__(self):
     """Initializes a Rubik's Cube with cube, moves, fitness, and
     num_moves.
     """
     self.cube = [0] * 6
     self.history = History()
     self.fitness = 0
     self.fitness_score = 0
Exemplo n.º 27
0
def build_segment_history(segments, history):
  segment_history = History()
  for segment in segments:
    attempts = find_segment_in_history(segment, history)
    for attempt in attempts:
      for transition in attempt:
        segment_history.record(transition)
  return segment_history
Exemplo n.º 28
0
def createHistory(portfolioFile = None, forceReload = False):
    # Read all transactions from disk
    transactions = transaction.readTransactions(portfolioFile)
    startDate = transactions[0].date

    # And all investments
    investments = investment.learn_investments(transactions)

    # Build a list of all mentioned tickers
    tickerList = []
    for trans in transactions:
        if trans.ticker not in tickerList:
            tickerList.append(trans.ticker)

    # Hard code currency list.  !! Should pick these out of investments really.
    currencyList = ["USD", "Euro", "NOK"]

    # Build a history of our transactions
    history = History(transactions)

    # Load what we've got from disk
    prices = {}
    Price.loadHistoricalPricesFromDisk(prices)

    # Start reading all the HTML we're going to need now.
    urlCache, currencyInfo, tickerInfo = cacheUrls(tickerList, currencyList, investments, history, startDate, prices, forceReload)

    # Load currency histories
    for currency in currencyInfo:
        Price.getCurrencyHistory(currency[0],
                                 currency[1],
                                 date.today(),
                                 prices,
                                 urlCache)

    # Load current prices from the Web
    Price.loadCurrentPricesFromWeb(history.currentTickers(), prices, urlCache)

    # Now load historical prices from the Web
    for ticker in tickerInfo:
        Price.loadHistoricalPricesFromWeb(ticker[0], ticker[1], ticker[2], prices, urlCache)

    # Fill in any gaps
    Price.fixPriceGaps(prices)

    # Now save any new data to disk
    Price.savePricesToDisk(prices)

    # And fill in any gaps between the last noted price and today
    Price.fixLastPrices(prices, history.currentTickers())

    # Give the prices to our history
    history.notePrices(prices)

    # Done with all the HTML that we read
    #urlCache.clean_urls()

    return (history, investments)
Exemplo n.º 29
0
    def __init__(self,
                 memorycontent,
                 assertionTriggers,
                 addr2line,
                 pcInitValue=0):
        # Parameters
        self.pcoffset = 8 if getSetting("PCbehavior") == "+8" else 0
        self.PCSpecialBehavior = getSetting("PCspecialbehavior")
        self.allowSwitchModeInUserMode = getSetting("allowuserswitchmode")
        self.maxit = getSetting("runmaxit")
        self.bkptLastFetch = None
        self.deactivatedBkpts = []

        # Initialize history
        self.history = History()

        # Initialize components
        self.mem = Memory(self.history, memorycontent)
        self.regs = Registers(self.history)
        self.pcInitVal = pcInitValue

        # Initialize decoders
        self.decoders = {
            'BranchOp': BranchOp(),
            'DataOp': DataOp(),
            'MemOp': MemOp(),
            'MultipleMemOp': MultipleMemOp(),
            'HalfSignedMemOp': HalfSignedMemOp(),
            'SwapOp': SwapOp(),
            'PSROp': PSROp(),
            'MulOp': MulOp(),
            'MulLongOp': MulLongOp(),
            'SoftInterruptOp': SoftInterruptOp(),
            'NopOp': NopOp()
        }
        self.decoderCache = {}

        # Initialize assertion structures
        self.assertionCkpts = set(assertionTriggers.keys())
        self.assertionData = assertionTriggers
        self.assertionWhenReturn = set()
        self.callStack = []
        self.addr2line = addr2line

        # Initialize execution errors buffer
        self.errorsPending = MultipleErrors()

        # Initialize interrupt structures
        self.interruptActive = False
        # Interrupt trigged at each a*(t-t0) + b cycles
        self.interruptParams = {'b': 0, 'a': 0, 't0': 0, 'type': "FIQ"}
        self.lastInterruptCycle = -1

        self.stepMode = None
        self.stepCondition = 0
        # Used to stop the simulator after n iterations in run mode
        self.runIteration = 0
        self.history.clear()
Exemplo n.º 30
0
 def __init__(self, parent, *args, **kwargs):
     """"""
     AddonCore.__init__(self)
     self.name = _("History")
     self.event_id = events.connect(cons.EVENT_DL_COMPLETE, self.trigger)
     self.parent = parent
     self.config = conf
     self.history = History()
     self.history_tab = HistoryContainer(self.history, self.parent)
Exemplo n.º 31
0
class HistoryQuery(object):
    def __init__(self, router):
        self._history = History(router)

    def get(self, uid, key):
        return self._history.get(uid, key)

    def put(self, uid, key, **fields):
        self._history.put(uid, key, fields)
Exemplo n.º 32
0
    def test_partition(self):
        dynamomessages._show_metadata = True
        all_nodes = self.partition()

        # Display, tweaking ordering of nodes so partition is in the middle
        print History.ladder(force_include=all_nodes,
                             spacing=16,
                             key=lambda x: ' ' if x.name == 'b' else x.name)
        dynamomessages._show_metadata = False
Exemplo n.º 33
0
 def test_put2_fail_nodes23_3(self):
     """Show PingReq failing"""
     (a, pref_list) = self.put_fail_nodes23(dynamo4)
     coordinator = pref_list[0]
     a.put('K1', None, 2, destnode=coordinator)  # Send client request to coordinator for clarity
     Framework.schedule(timers_to_process=0)
     from_line = len(History.history)
     Framework.schedule(timers_to_process=3)
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
Exemplo n.º 34
0
 def __init__(self, parent, *args, **kwargs):
     """"""
     AddonCore.__init__(self)
     self.name = _("History")
     self.event_id = None
     self.parent = parent
     self.config = conf
     self.history = History()
     self.history_tab = HistoryTab(self.history)
Exemplo n.º 35
0
 def forward_message(cls, msg, new_to_node):
     """Forward a message"""
     _logger.info("Enqueue(fwd) %s->%s: %s", msg.to_node, new_to_node, msg)
     fwd_msg = copy.copy(msg)
     fwd_msg.intermediate_node = fwd_msg.to_node
     fwd_msg.original_msg = msg
     fwd_msg.to_node = new_to_node
     cls.queue.append(fwd_msg)
     History.add("forward", fwd_msg)
Exemplo n.º 36
0
 def forward_message(cls, msg, new_to_node):
     """Forward a message"""
     _logger.info("Enqueue(fwd) %s->%s: %s", msg.to_node, new_to_node, msg)
     fwd_msg = copy.copy(msg)
     fwd_msg.intermediate_node = fwd_msg.to_node
     fwd_msg.original_msg = msg
     fwd_msg.to_node = new_to_node
     cls.queue.append(fwd_msg)
     History.add("forward", fwd_msg)
Exemplo n.º 37
0
 def test_get_put_put(self):
     """Show get-then-put-then-put operation"""
     dynamomessages._show_metadata = True
     (a, pref_list) = self.get_put_get_put()
     coordinator = pref_list[0]
     from_line = len(History.history)
     self.get_put_put(a, coordinator)
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
     dynamomessages._show_metadata = False
Exemplo n.º 38
0
 def cancel_timer(cls, tmsg):
     """Cancel the given timer"""
     for (this_prio, this_tmsg) in cls.pending:
         if this_tmsg == tmsg:
             _logger.debug("Cancel timer %s for node %s reason %s",
                           id(tmsg), tmsg.from_node, tmsg.reason)
             cls.pending.remove((this_prio, this_tmsg))
             History.add("cancel", tmsg)
             return
Exemplo n.º 39
0
    def partition_repair(self):
        # Repair the partition
        History.add("announce", "Repair network partition")
        Framework.cuts = []
        Framework.schedule(timers_to_process=12)

        # Get from node a
        a = Node.node['a']
        a.get('K1')
        Framework.schedule(timers_to_process=0)
Exemplo n.º 40
0
 def test_simple_get(self):
     for _ in range(6):
         dynamo1.DynamoNode()
     a = dynamo1.DynamoClientNode('a')
     a.put('K1', None, 1)
     Framework.schedule()
     from_line = len(History.history)
     a.get('K1')
     Framework.schedule()
     print History.ladder(start_line=from_line)
Exemplo n.º 41
0
 def put_fail_initial_node(self, cls):
     for _ in range(6):
         cls.DynamoNode()
     a = cls.DynamoClientNode('a')
     destnode = random.choice(cls.DynamoNode.nodelist)
     a.put('K1', None, 1, destnode=destnode)
     # Fail at the forwarding node before it gets a chance to forward
     destnode.fail()
     Framework.schedule()
     print History.ladder()
Exemplo n.º 42
0
    def __init__(self, user):
        self.user = user
        self.history = History()
        self.statusMap = StatusMap()
        self.sender = MessageSender(self.BROKER_LIST, user)
        self.receiver = MessageReceiver(self.BROKER_LIST, user, self.history)
        self.userManager = UserStatusManager(self.BROKER_LIST, user,
                                             self.statusMap)

        self.userManager.goOnline()
Exemplo n.º 43
0
Arquivo: env.py Projeto: wxw0/rl
 def __init__(self, config):
     self.cf = config
     self.game = self.cf.game
     self.history = History(self.cf)
     self.env = gym.make(self.game + self.cf.env_versions)
     self.action_n = self.env.action_space.n
     self._obs = np.zeros((2, ) + self.env.observation_space.shape,
                          dtype=np.uint8)
     self.real_done = True
     print('env: ', self.game, self.action_n)
Exemplo n.º 44
0
 def put_fail_initial_node(self, cls):
     for _ in range(6):
         cls.DynamoNode()
     a = cls.DynamoClientNode('a')
     destnode = random.choice(cls.DynamoNode.nodelist)
     a.put('K1', None, 1, destnode=destnode)
     # Fail at the forwarding node before it gets a chance to forward
     destnode.fail()
     Framework.schedule()
     print History.ladder()
Exemplo n.º 45
0
 def test_double_put(self):
     for _ in range(6):
         dynamo1.DynamoNode()
     a = dynamo1.DynamoClientNode('a')
     b = dynamo1.DynamoClientNode('b')
     a.put('K1', None, 1)
     Framework.schedule(1)
     b.put('K2', None, 17)
     Framework.schedule()
     print History.ladder(spacing=14)
Exemplo n.º 46
0
 def test_double_put(self):
     for _ in range(6):
         dynamo1.DynamoNode()
     a = dynamo1.DynamoClientNode('a')
     b = dynamo1.DynamoClientNode('b')
     a.put('K1', None, 1)
     Framework.schedule(1)
     b.put('K2', None, 17)
     Framework.schedule()
     print History.ladder(spacing=14)
Exemplo n.º 47
0
def main(config_path):
    # Setup configuration and history
    config_obj = Config(config_path)
    url_history = History(
    ) if "history" not in config_obj["config"] else History(
        config_obj["config"]["history"])

    # Execute each poll setting
    for poll in config_obj["polls"]:
        execute_poll(poll, url_history)
Exemplo n.º 48
0
 def test_simple_get(self):
     for _ in range(6):
         dynamo1.DynamoNode()
     a = dynamo1.DynamoClientNode('a')
     a.put('K1', None, 1)
     Framework.schedule()
     from_line = len(History.history)
     a.get('K1')
     Framework.schedule()
     print History.ladder(start_line=from_line)
Exemplo n.º 49
0
    def partition_repair(self):
        # Repair the partition
        History.add("announce", "Repair network partition")
        Framework.cuts = []
        Framework.schedule(timers_to_process=12)

        # Get from node a
        a = Node.node['a']
        a.get('K1')
        Framework.schedule(timers_to_process=0)
Exemplo n.º 50
0
 def test_put2_fail_nodes23_6(self):
     """Show hinted handoff after recovery"""
     (a, pref_list) = self.put_fail_nodes23(dynamo4)
     coordinator = pref_list[0]
     a.put('K1', None, 2, destnode=coordinator)  # Send client request to coordinator for clarity
     Framework.schedule(timers_to_process=10)
     from_line = len(History.history)
     pref_list[1].recover()
     pref_list[2].recover()
     Framework.schedule(timers_to_process=15)
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
Exemplo n.º 51
0
 def send_message(cls, msg, expect_reply=True):
     """Send a message"""
     _logger.info("Enqueue %s->%s: %s", msg.from_node, msg.to_node, msg)
     cls.queue.append(msg)
     History.add("send", msg)
     # Automatically run timers for request messages if the sender can cope
     # with retry timer pops
     if (expect_reply and
         not isinstance(msg, ResponseMessage) and
         'rsp_timer_pop' in msg.from_node.__class__.__dict__ and
         callable(msg.from_node.__class__.__dict__['rsp_timer_pop'])):
         cls.pending_timers[msg] = TimerManager.start_timer(msg.from_node, reason=msg, callback=Framework.rsp_timer_pop)
Exemplo n.º 52
0
 def put_fail_node2(self, cls):
     for _ in range(6):
         cls.DynamoNode()
     a = cls.DynamoClientNode('a')
     a.put('K1', None, 1)
     # Fail the second node in the preference list
     pref_list = cls.DynamoNode.chash.find_nodes('K1', 3)[0]
     Framework.schedule(1)
     pref_list[1].fail()
     Framework.schedule()
     a.get('K1')
     Framework.schedule()
     print History.ladder()
Exemplo n.º 53
0
 def test_put2_fail_nodes23_4a(self):
     """Show PingReq recovering but an inconsistent Get being returned"""
     (a, pref_list) = self.put_fail_nodes23(dynamo3)
     coordinator = pref_list[0]
     a.put('K1', None, 2, destnode=coordinator)  # Send client request to coordinator for clarity
     Framework.schedule(timers_to_process=10)
     from_line = len(History.history)
     pref_list[1].recover()
     pref_list[2].recover()
     Framework.schedule(timers_to_process=10)
     a.get('K1', destnode=coordinator)
     Framework.schedule(timers_to_process=0)
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
Exemplo n.º 54
0
 def test_put2_fail_nodes23_4b(self):
     """Show PingReq recovering, and a subsequent Put returning to the original preference list"""
     (a, pref_list) = self.put_fail_nodes23(dynamo3)
     coordinator = pref_list[0]
     a.put('K1', None, 2, destnode=coordinator)  # Send client request to coordinator for clarity
     Framework.schedule(timers_to_process=10)
     from_line = len(History.history)
     pref_list[1].recover()
     pref_list[2].recover()
     Framework.schedule(timers_to_process=15)
     a.put('K1', None, 3, destnode=coordinator)
     Framework.schedule(timers_to_process=5)
     print History.ladder(force_include=pref_list, start_line=from_line, spacing=16)
Exemplo n.º 55
0
 def pop_timer(cls):
     """Pop the first pending timer"""
     while True:
         (_, tmsg) = cls.pending.pop(0)
         if tmsg.from_node.failed:
             continue
         _logger.debug("Pop timer %s for node %s reason %s", id(tmsg), tmsg.from_node, tmsg.reason)
         History.add("pop", tmsg)
         if tmsg.callback is None:
             # Default to calling Node.timer_pop()
             tmsg.from_node.timer_pop(tmsg.reason)
         else:
             tmsg.callback(tmsg.reason)
         return
Exemplo n.º 56
0
def course_page(dept, course_id):
    try: #format id, else tell user that id is invalid
        formatted_id = id_from_url(course_id)
    except ValueError:
        return '\''+course_id+'\' is not a valid course id.'

    try:
        res = dbsession.query(Course)
        course = res.filter(Course.id == formatted_id).one()
    except:
        return 'Course \'' + course_id + '\' does not exist.'

    #get alt descs for course
    res = dbsession.query(AltDesc)
    alt_desc_list = list(res.filter(AltDesc.course_id == formatted_id))

    #get alt descs for courses that are the same (like CS220 and MATH220)
    #and concatenate them together
    for same_course in listify(course.same_as):
        additional_alt_descs = dbsession.query(AltDesc).filter(AltDesc.course_id == same_course)
        alt_desc_list += list(additional_alt_descs)

    #remove unapproved alt descs
    alt_desc_list = filter(lambda alt_desc: alt_desc.approved, alt_desc_list)

    sections = dbsession.query(Section).\
                         filter( Section.course_id == formatted_id )
    term_offerings = OrderedDict()
    for term in terms:
        term_offerings[term] = sections.filter(Section.term==term)
        term_offerings[term] = list(term_offerings[term])

    course = search(dbsession, course_id = course.id)
    course = course[course.keys()[0]]

    form = AltDescForm()

    #Appends course title to history
    history = History()
    history.add(course)
    #Sets history cookie
    resp = make_response( render_template("course.html",
                                          course=course,
                                          form=form,
                                          alt_descs=alt_desc_list,
                                          terms=term_offerings,
                                          history=history) )
    resp.set_cookie('history', str(history), max_age=365*24*60*60) #cookie lasts a year
    return resp
Exemplo n.º 57
0
    def test_partition_restore(self):
        dynamomessages._show_metadata = True
        all_nodes = self.partition()
        self.partition_repair()
        from_line = len(History.history)

        # Put a new value, which coalesces
        a = Node.node['a']
        getrsp = a.last_msg
        a.put('K1', getrsp.metadata, 101)
        Framework.schedule(timers_to_process=0)

        # Display, tweaking ordering of nodes so partition is in the middle
        print History.ladder(force_include=all_nodes, start_line=from_line, spacing=16, key=lambda x: ' ' if x.name == 'b' else x.name)
        dynamomessages._show_metadata = False
Exemplo n.º 58
0
	def __init__(self, logfile='history.log'):
		# Initialize the scheduler
		SchedulerPolicy.__init__(self) # super()
		
		self.t = 0
		# Nodes
		self.nodes = {}
		# History
		self.logfile = logfile
		self.history = History(filename=self.logfile)
		# Job submission
		self.lastJobId = 1
		# Simulation
		self.maxTime = None
		# Id for jobs
		if sys.platform == 'win32':
			self.trackerId = datetime.now().strftime('%Y%m%d%H%M')
		else:
			self.trackerId = datetime.now().strftime('%4Y%2m%2d%2H%2M')
		# Specify if the nodes are sent to sleep when there's no load
		self.nodeManagement = True
		
		# Outputs
		self.energy = None
		
		# Step length
		self.STEP = 1
Exemplo n.º 59
0
def anneal_reducer(lines):
    # 开盘价, 昨结算, 最高价, 最低价
    domain = [(-100, 100), (-100, 100), (-100, 100), (-100, 100), (-2000, 2000)]
    records = set()
    for line in lines:
        history_record = History.get_from_historyline(line)
	history_record = History.norm(history_record)
	records.add(history_record)

    while(True):
        best_cost, best_resolve = optimizations.annealing(domain, get_best_solution(records))
	ave_cost = best_cost / len(records)
	if ave_cost < 3000:
            print 'best_cost: %s, best_resolve: %s, best_ave_cost: %f' % (best_cost, best_resolve, ave_cost)
	    if ave_cost < 1000:
	        break
Exemplo n.º 60
0
    def __init__(self):
        
        #-----location part
        if parameters.location_mode:
            self.mesh_size = 1./parameters.LD0range/2
            f = lambda size: [[{} for x in xrange(int(size)+1)] for y in xrange(int(size)+1)]
            self.mesh = f(self.mesh_size)
            map_path = parameters.map_phenotype_image(parameters.maps)
            self.load_terrain(map_path+".info.tmp", map_path+".tmp")
        #------------------

        from plant import Plant
        from phenotype import Phenotype

        self.plants = {}
        self.allplantslist = []
        self.generation = 0
        self.__class__.default = self
        self.__class__.environments += 1
        debug.g("niche %d" % parameters.niche_size)
        for i in xrange(parameters.niche_size):
            if parameters.location_mode:
                Plant.new(parameters.get_start_point(parameters.maps))
            else:
                Plant.new((0,0))
        debug.g("*** %d" % len(self.plants))
        self.optimal_global_phenotype = Phenotype()
        self.base_phenotype = Phenotype()
        self.survivors = parameters.niche_size
        self.randomkiller = selectors.KillerRandom()
        (self.killer, self.reproducer) = selectors.getSelectors()
        self.phenotype_link = Phenotype
        self.history = History(self)
        self.history.update()