Exemple #1
0
    def privmsg(self, prefix, channel, msg):
        """This will get called when the bot receives a message."""
        user = self.parse_nickname(prefix)

        try:
            if msg == '!release':
                print('releasing')
                del self.adapter[channel]
            elif msg == '!reload':
                reload(adapter)
                self.adapter[channel] = adapter.Adapter(self, channel)
            elif msg.startswith('!exec '):
                exec(msg[len('!exec '):])
            elif msg[0] == '!':
                self.adapter[channel].msg(user, msg[1:])
            else:
                print("%s <%s> %s" % (channel, user, msg))
        except KeyError:
            pass

        # Check to see if they're sending me a private message
        if channel == self.nickname:
            msg = "It isn't nice to whisper!  Play nice with the group."
            self.msg(user, msg)
            return

        # Otherwise check to see if it is a message directed at me
        if msg.startswith(self.nickname + ":"):
            msg = "%s: I am a log bot" % user
            self.msg(channel, msg)
            print("<%s> %s" % (self.nickname, msg))
Exemple #2
0
2019-8-16:
这种方法的计算复杂度好像很高。估计是自己代码实现的问题
'''
if __name__ == '__main__':
    export_csv = 'results/fm.csv'
    metric = []
    metric.append(ac.HitRate(20))
    metric.append(ac.HitRate(15))
    metric.append(ac.HitRate(10))
    metric.append(ac.HitRate(5))
    metric.append(ac.MRR(20))
    metric.append(ac.MRR(15))
    metric.append(ac.MRR(10))
    metric.append(ac.MRR(5))

    pr = ad.Adapter()

    start_time = time.time()
    print("  fit  ", "fm")
    pr.fit()

    res = {}

    res["fm"] = eval_last.evaluate_sessions(pr, metric, pr.instance.dataset.test_set)

    end_time = time.time()
    print("total time is: ", end_time - start_time, " s")

    for k, l in res.items():
        for e in l:
            print(k, ":", e[0], " ", e[1])
    def __init__(self,
                 parent,
                 name=None,
                 debug=False,
                 shared=False,
                 agentSupport=False,
                 agent=None):
        """
		My adapter

		@param parent: parent testcase
		@type parent: testcase

		@param name: adapter name used with from origin/to destination (default=None)
		@type name: string/none

		@param debug: active debug mode (default=False)
		@type debug:	boolean

		@param shared: shared adapter (default=False)
		@type shared:	boolean
		
		@param agentSupport: agent support (default=False)
		@type agentSupport: boolean
		
		@param agent: agent to use (default=None)
		@type agent: string/none
		"""
        # check the agent
        if agent is not None:
            if agentSupport:
                if not isinstance(agent, dict):
                    raise TestAdapterLib.ValueException(
                        TestAdapterLib.caller(),
                        "agent argument is not a dict (%s)" % type(agent))
                if not len(agent['name']):
                    raise TestAdapterLib.ValueException(
                        TestAdapterLib.caller(), "agent name cannot be empty")
                if unicode(agent['type']) != unicode(AGENT_TYPE_EXPECTED):
                    raise TestAdapterLib.ValueException(
                        TestAdapterLib.caller(),
                        'Bad agent type: %s, expected: %s' %
                        (agent['type'], unicode(AGENT_TYPE_EXPECTED)))

        TestAdapter.Adapter.__init__(self,
                                     name=__NAME__,
                                     parent=parent,
                                     debug=debug,
                                     realname=name,
                                     agentSupport=agentSupport,
                                     agent=agent,
                                     shared=shared)
        self.parent = parent
        self.cfg = {}
        if agent is not None:
            self.cfg['agent'] = agent
            self.cfg['agent-name'] = agent['name']
        self.cfg['agent-support'] = agentSupport

        self.TIMER_ALIVE_AGT = TestAdapter.Timer(parent=self,
                                                 duration=20,
                                                 name="keepalive-agent",
                                                 callback=self.aliveAgent,
                                                 logEvent=False,
                                                 enabled=True)
        self.__checkConfig()

        # initialize the agent with no data
        if agent is not None:
            if self.cfg['agent-support']:
                self.prepareAgent(data={'shared': shared})
                if self.agentIsReady(timeout=30) is None:
                    raise TestAdapter.ValueException(
                        TestAdapter.caller(),
                        "Agent %s is not ready" % self.cfg['agent-name'])

                self.TIMER_ALIVE_AGT.start()

        # state and timer initialization
        self.state = TestAdapter.State(parent=self,
                                       name='AUTOMATE',
                                       initial=STATE_OFF)
        self.TIMER_A = TestAdapter.Timer(parent=self,
                                         duration=2,
                                         name="TIMER A",
                                         callback=self.onTimerA_Fired,
                                         logEvent=True,
                                         enabled=True,
                                         callbackArgs={})
        self.TIMER_A.start()

        self.ADP = adapter.Adapter(parent=parent,
                                   debug=debug,
                                   name=None,
                                   shared=shared)
Exemple #4
0
def adapter_setup(test_data):
    a = adapter.Adapter(test_data)
    return a.result
Exemple #5
0
 def joined(self, channel):
     """This will get called when the bot joins the channel."""
     if channel == channelname:
         self.adapter[channel] = adapter.Adapter(self, channel)
     #self.msg(channel, "\x0304red friend =)\x03")
     """self.msg(channel, "\x0303green friend =)\x03")
Exemple #6
0
                         help='Unlock code.',
                         type=str,
                         required=True)
parser_dump.set_defaults(func=dump)

if __name__ == '__main__':
    args = parser.parse_args()

    fmt = '%(message)s'
    if args.timestamps:
        fmt = '%(asctime)-15s %(levelname)s %(message)s'
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG, format=fmt)
    else:
        logging.basicConfig(level=logging.INFO, format=fmt)

    adapter_logger, protocol_logger = None, None
    if args.debug_adapter:
        adapter_logger = logging
    if args.debug_protocol:
        protocol_logger = logging

    a = adapter.Adapter(args.port, logger=adapter_logger)
    s = serialio.SerialIO(a, logger=protocol_logger)
    s.adapter.connect()
    logging.info("Connected to adapter version {}".format(s.adapter.version()))
    s.connect()
    logging.info("Connected to target version {}".format(s.version()))

    sys.exit(args.func(args, s) or 0)