Пример #1
0
    def _flow_stats_reply_handler(self, ev):
        """
        receive flow_stat reply, then insert into database.
        entry is considered unique for cookie-datapath pair
        :param ev:
        """
        body = ev.msg.body

            # self.logger.info('datapath         '
            #                  'in-port  eth-dst           '
            #                  'out-port packets  bytes')
        for stat in sorted([flow for flow in body if flow.priority == 1],
                           key=lambda flow: (flow.match['in_port'],
                                             flow.match['eth_dst'])):
            # self.logger.info('%016x %8x %17s %8x %8d %8d %8d',
            #                  ev.msg.datapath.id,
            #                  stat.match['in_port'], stat.match['eth_dst'],
            #                  stat.instructions[0].actions[0].port,
            #                  stat.packet_count, stat.byte_count, stat.cookie)

            #check if the entry is already exists, if not create new entry
            if db.fidcheck(stat.cookie, ev.msg.datapath.id):
                current_th = (stat.byte_count - db.read_stat(stat.cookie, ev.msg.datapath.id))/monperiod
                #print "stat.byte_count "+ str(stat.byte_count)
                print str(stat.cookie) + " " + str(ev.msg.datapath.id) + " "     + str(current_th/1000) + "kbps"
                db.update_stat(stat.cookie, ev.msg.datapath.id, stat.byte_count, stat.packet_count)
                #insert throughput (kbps) based on current and previous bytes
                db.insert_throughput(stat.cookie, ev.msg.datapath.id, current_th/1000)
            else:
                db.insert_stat(stat.cookie, ev.msg.datapath.id, stat.byte_count, stat.packet_count)
                db.insert_throughput(stat.cookie, ev.msg.datapath.id, None)
Пример #2
0
    def ticker_callback(cls, message):
        logging.info('New Ticker | High %s - Low %s' % (message.daily_high, message.daily_low))

        update_trade_for_ticker(message, cls.last_ticker_transaction_ids)
        update_stat(0, - len(cls.last_ticker_transaction_ids))

        with lock:
            cls.last_ticker_transaction_ids = []
Пример #3
0
    def ticker_callback(cls, message):
        logging.info('New Ticker | High %s - Low %s' %
                     (message.daily_high, message.daily_low))

        update_trade_for_ticker(message, cls.last_ticker_transaction_ids)
        update_stat(0, -len(cls.last_ticker_transaction_ids))

        with lock:
            cls.last_ticker_transaction_ids = []
Пример #4
0
 async def dmg(self, ctx, arg1, arg2):
     trainer = str(ctx.message.author.id)
     print('About to do damage')
     pokemon, error1 = db.get_battle_pokemon(trainer, arg1)
     if error1 != '':
         await ctx.message.channel.send(
             'Something went wrong with verifying pokemon is in battle: {}'.
             format(error1))
         return False
     if len(pokemon) == 0:
         await ctx.message.channel.send(
             '{} is not in battle to damage'.format(pokemon[1]))
         return False
     pokemon = pokemon[0]
     curr_hp = pokemon[3]
     new_hp = int(curr_hp) - int(arg2)
     result, error2 = db.update_stat(trainer, arg1, 'HP', new_hp, True)
     if error2 != '':
         await ctx.message.channel.send(
             'Something went wrong with setting damage: {}'.format(error2))
         return False
     msg1 = '{} now has {} hp.'.format(arg1, new_hp)
     if new_hp < 1:
         msg1 += 'They have been defeated'
     await ctx.message.channel.send(msg1)
Пример #5
0
    def trades_callback(cls, message):
        logging.info('New Trade | %s: %s @ %s' %
                     (message['id'], message['amount'], message['price']))

        insert_trade(tid=message['id'],
                     price=message['price'],
                     amount=message['amount'],
                     asks=cls.latest_orders['asks'][:10],
                     bids=cls.latest_orders['bids'][:10])

        update_stat(1, 1)

        with lock:
            cls.last_ticker_transaction_ids.append(message['id'])

        if len(cls.last_ticker_transaction_ids) > cls.ticker_trigger:
            Ticker().fetch()
Пример #6
0
    def trades_callback(cls, message):
        logging.info('New Trade | %s: %s @ %s' % (message['id'], message['amount'], message['price']))

        insert_trade(
            tid=message['id'],
            price=message['price'],
            amount=message['amount'],
            asks=cls.latest_orders['asks'][:10],
            bids=cls.latest_orders['bids'][:10]
        )

        update_stat(1, 1)

        with lock:
            cls.last_ticker_transaction_ids.append(message['id'])

        if len(cls.last_ticker_transaction_ids) > cls.ticker_trigger:
            Ticker().fetch()
Пример #7
0
 async def updatestat(self, ctx, arg1, arg2, arg3):
     stats = ['hp','def','spatk','spdef','speed','atk']
     if arg2.lower() not in stats:
         await ctx.message.channel.send('Stat {} does not exist'.format(arg2))
         return False
     trainer = str(ctx.message.author.id)
     pokemon, error1 = db.get_battle_pokemon(trainer,arg1)
     if error1 != '':
         await ctx.message.channel.send('Something went wrong with verifying pokemon is in battle: {}'.format(error1))
         return False
     if len(arg3) < 2:
         await ctx.message.channel.send('Ensure that your stat value has a + or - and at least one number: {} did not'.format(arg3))
         return False
     sign = arg3[0]
     try:
         num = int(arg3[1::])
     except:
         await ctx.message.channel.send('Ensure that your stat value has a + or - and then a number: {} did not'.format(arg3))
         return False
     if sign == '-':
         num = -1 * num
     if len(pokemon) == 0:
         indexes = globals.STAT_LOC
         pokemon, error = db.get_pokemon(trainer,arg1)
         idx = indexes[arg2.lower()]
         current_val = pokemon[0][idx]
         new_val = current_val + num
         result, error2 = db.update_stat(trainer, arg1, arg2, new_val)
         if error2 != '':
             await ctx.message.channel.send('could not update stat due to error: {}'.format(error2))
             return False
         await ctx.message.channel.send("{}'s {} stat is now permanently {}".format(arg1, arg2, new_val))                           
     else:
         indexes = globals.STAT_LOC_BATTLE
         idx = indexes[arg2.lower()]
         current_val = pokemon[0][idx]
         new_val = current_val + num
         result, error2 = db.update_stat(trainer, arg1, arg2, new_val, True)
         if error2 != '':
             await ctx.message.channel.send('could not update stat due to error: {}'.format(error2))
             return False
         await ctx.message.channel.send("{}'s {} stat is now {} for this battle".format(arg1, arg2, new_val))