Пример #1
0
        async def on_end(self):
            print('before finishing my behaviour, i\'m going to check my friends')
            friends_guid = []
            for g in agent_guid_pool:
                friends_guid += am.get_friends(g)

            for g in friends_guid:
                for i in range(len(spy.users_retrived)):
                    if spy.users_retrived[i].guid == g:
                        spy.users_retrived[i].is_friend = True
            print('process finished')
            print('Reporting stats...')
            print(len(spy.users_retrived))
            am.plot_results(spy.users_retrived)
Пример #2
0
        async def on_start(self):
            print('Hello i\'m ' + self.agent.agName)
            friends_guid = []
            friends_guid += am.get_friends(self.agent.guid)
            print('process finished')

            for g in friends_guid:
                usr = usuario.Usuario(g, True, True)
                self.agent.users_retrived += [usr]

            indexes = [0, 1, 2, 3, 4]
            random.shuffle(indexes)
            for i in indexes:
                res = requests.get('http://localhost/services/api/rest/json/?',
                                   params={
                                       'method': 'users.select_users',
                                       'theme': i,
                                       'agentGUID': self.agent.guid
                                   })
                if res:
                    print('users information response received')
                    content = res.json()
                    if content['status'] == 0:
                        print('users information status good')
                        content = content['result']
                        for k in content.keys():
                            if int(k) not in agent_guid_pool:
                                aux = am.get_user(self.agent.users_retrived,
                                                  int(k))
                                if aux == -1:
                                    usr = usuario.Usuario(int(k), False, False)
                                    usr.information.append((i, content[k]))
                                    self.agent.users_retrived += [usr]
                                else:
                                    self.agent.users_retrived.remove(aux)
                                    aux.information.append((i, content[k]))
                                    self.agent.users_retrived += [aux]
                        print(
                            'users to be contacted and users indexed by theme correctly created with theme '
                            + str(i))
            print('start behaviour finished')
Пример #3
0
        async def on_end(self):  # report_info()
            # time.sleep(300)  # simulates the 5-minutes waiting time. Otherwise the last message hasn't wait time.
            print('before finishing my behaviour, i\'m going to check my friends')
            for g in agent_guid_pool:
                print(str(g))
                f = am.get_friends(g)
                spy.friends += f
                f_prima = list(set(f) - set(spy.initial_friends))
                spy.new_friends_by_identity[g] = f_prima
                print(spy.new_friends_by_identity)
            spy.friends = am.unique(spy.friends)
            spy.initial_friends = am.unique(spy.initial_friends)
            print('friendlist updated')
            print('Reporting stats...')
            print('At the beginning of my duty, i had: ' + str(len(spy.initial_friends)) + ' friends')
            print('Now, at the end, i have: ' + str(len(spy.friends)) + ' friends')

            if len(spy.friends) > len(spy.initial_friends):
                new_friends = list(set(spy.friends) - set(spy.initial_friends))
                print('This means that users with guids: ' + str(new_friends) + ' have added me because of my messages')
                am.plot_results(spy.users_removed, spy.total_users, spy.new_friends_by_identity)
            await self.agent.stop()
Пример #4
0
        async def on_start(self):  # get_agent_friends(), select_users()
            print('Hello i\'m ' + spy.agName)
            for g in agent_guid_pool:
                spy.friends += am.get_friends(g)
            print('friends added')
            spy.initial_friends = spy.friends
            print('i\'m now getting users information')
            indexes = [0, 1, 2, 3, 4]
            random.shuffle(indexes)
            for i in indexes:
                res = requests.get('http://localhost/services/api/rest/json/?',
                                   params={'method': 'users.select_users',
                                           'theme': i,
                                           'agentGUID': spy.guid}
                                   )
                if res:
                    print('users information response received')
                    print(res.text)
                    content = res.json()

                    if content['status'] == 0:
                        print('users information status good')
                        content = content['result']

                        for k in content.keys():
                            if int(k) not in spy.friends or int(k) != spy.guid:  # if it isn't a friend
                                tups = spy.users_information.get(int(k), [])
                                spy.users_information[int(k)] = tups + [(
                                    i, content[k], 0)]  # save the user to be contacted later
                        print('users to be contacted and users indexed by theme correctly created with theme ' + str(i))
                    else:
                        print('status ' + str(i) + ' incorrect')
                        print(content)
                else:
                    print('res ' + str(i) + ' failed')
                    print(res.json())
            spy.total_users = len(spy.users_information.keys())
            print('start behaviour finished')
Пример #5
0
        async def run(self):  # get_friends -> send_message() -> send_friend_request()
            to_rm = []
            print('before starting sending messages')
            spy.friends += am.get_friends(spy.guid)
            spy.friends = am.unique(spy.friends)
            print('friendlist updated')

            print('preparing to send a lot of messages')
            users = spy.users_information.keys()
            for usr in users:
                info = spy.users_information[usr]
                print(info)
                conver = am.check_conversation(info)
                sub, con, new_info = am.head_body_selector(conver, info[-1], spy.agName)
                print('user selected, about to send him a message')
                if usr not in spy.friends or spy.users_removed.get(usr, []) == []:
                    print('this user is not my friend, so let\'s go')
                    sender = requests.post('http://localhost/services/api/rest/json/?',
                                           params={'method': 'users.send_message',
                                                   'agentGUID': spy.guid,
                                                   'receiverGUID': usr,
                                                   'subject': sub,
                                                   'content': con})
                    if sender:
                        print('message sent with exit with status: ' + str(sender.json()))
                    else:
                        print('message sent failed')
                        print(sender.json())

                    print('after sending the message, i\'m going to send a friend request')
                    sender = requests.post('http://localhost/services/api/rest/json/?',
                                           params={'method': 'users.send_Friend_Request',
                                                   'agentGUID': spy.guid,
                                                   'receiverGUID': usr})
                    if sender:
                        print('message sent with exit with status: ' + str(sender.json()))
                        content = sender.json()
                        if content['status'] == -1:
                            print('I\'ve already sent him a friend request and he hasn\'t answered yet')
                    else:
                        print('message sent failed')
                        print(sender.json())

                    if new_info[-1] > 2:
                        print('last contact with ' + str(usr) + ' about ' + new_info[1])
                        spy.neds_change = True

                    spy.users_information[usr] = am.update_dict_value(info, new_info)
                else:
                    print('user ' + str(usr) + ' already is my friend, so my job with him is done.' +
                          ' Removing him from the contact list. i\'ve sent him ' +
                          str(conver[-1])
                          + ' messages about ' + conver[1])
                    to_rm += [usr]

            for u in to_rm:
                spy.users_removed[u] = spy.users_information.pop(u, -1)

            if spy.neds_change:
                if spy.changes_count < spy.max_changes:
                    spy.changes_count += 1
                    spy.agName = agent_name_pool[spy.changes_count]
                    spy.guid = agent_guid_pool[spy.changes_count]
                    spy.neds_change = False
                    print("Now i\'m " + spy.agName)
                else:
                    self.kill()

            if not spy.users_information:
                self.kill()
Пример #6
0
        async def run(self):
            print('before starting sending messages')
            friends_guid = []
            friends_guid += am.get_friends(spy.guid)

            friends_guid = am.unique(friends_guid)
            for f in friends_guid:
                print(f)
                for i in range(len(spy.users_retrived)):
                    if f == spy.users_retrived[i].guid:
                        print('making an user my friend')
                        spy.users_retrived[i].is_friend = True
            print('friendlist updated')

            print('preparing to send a lot of messages')
            for i in range(len(spy.users_retrived)):
                u = spy.users_retrived[i]
                print(u.to_String())
                print('user selected, about to send him a message')
                if not u.is_friend:
                    info = u.information[0]  # no ha hecho falta check_conversation
                    sub, con = am.head_body_selector(info, u.messages_received, spy.agName)
                    spy.users_retrived[i].themes_contacted += [info[0]]
                    spy.users_retrived[i].last_theme = info[0]

                    spy.users_retrived[i].contacted_by = spy.agName
                    print('this user is not my friend, so let\'s go')
                    sender = requests.post('http://localhost/services/api/rest/json/?',
                                           params={'method': 'users.send_message',
                                                   'agentGUID': spy.guid,
                                                   'receiverGUID': u.guid,
                                                   'subject': sub,
                                                   'content': con})
                    if sender:
                        print('message sent with exit with status: ' + str(sender.json()))
                        spy.users_retrived[i].messages_received += 1
                    else:
                        print('message sent failed')
                        print(sender.json())

                    print('after sending the message, i\'m going to send a friend request')
                    sender = requests.post('http://localhost/services/api/rest/json/?',
                                           params={'method': 'users.send_Friend_Request',
                                                   'agentGUID': spy.guid,
                                                   'receiverGUID': u.guid})
                    if sender:
                        print('message sent with exit with status: ' + str(sender.json()))
                        content = sender.json()
                        if content['status'] == -1:
                            print('I\'ve already sent him a friend request and he hasn\'t answered yet')
                else:
                    if not u.initially_friend:
                        print('user ' + str(u.guid) + ' already is my friend, so my job with him is done.' +
                              ' Removing him from the contact list. i\'ve sent him ' +
                              str(u.messages_received)
                              + ' messages about ' + str(u.last_theme))
                if spy.users_retrived[i].messages_received > 0 and spy.users_retrived[i].messages_received % 3 == 0:
                    spy.users_retrived[i].information.pop(0)
                    spy.require_pers_change = True

            if spy.require_pers_change:
                if spy.count < spy.max_changes:
                    spy.count += 1
                    spy.agName = agent_name_pool[spy.count]
                    spy.guid = agent_guid_pool[spy.count]
                    spy.require_pers_change = False
                    print("Now i\'m " + spy.agName)
                else:
                    self.kill()
Пример #7
0
        async def run(self):
            print('before starting sending messages')
            friends_guid = []
            friends_guid += am.get_friends(self.agent.guid)

            friends_guid = am.unique(friends_guid)
            for f in friends_guid:
                print(f)
                for i in range(len(self.agent.users_retrived)):
                    if f == self.agent.users_retrived[i].guid:
                        print('making an user my friend')
                        self.agent.users_retrived[i].is_friend = True
            print('friendlist updated')

            print('preparing to send a lot of messages')
            for i in range(len(self.agent.users_retrived)):
                u = self.agent.users_retrived[i]
                print(u.to_String())
                print('user selected, about to send him a message')
                if not u.is_friend:
                    if u.current_info is None:
                        index = random.randint(0, len(u.information) - 1)
                        u.current_info = u.information[index]
                    info = u.current_info  # no ha hecho falta check_conversation
                    sub, con = am.head_body_selector(info, u.messages_received,
                                                     self.agent.agName)
                    self.agent.users_retrived[i].themes_contacted += [info[0]]
                    self.agent.users_retrived[i].last_theme = info[0]

                    self.agent.users_retrived[
                        i].contacted_by = self.agent.agName
                    print('this user is not my friend, so let\'s go')
                    sender = requests.post(
                        'http://localhost/services/api/rest/json/?',
                        params={
                            'method': 'users.send_message',
                            'agentGUID': self.agent.guid,
                            'receiverGUID': u.guid,
                            'subject': sub,
                            'content': con
                        })
                    if sender:
                        print('message sent with exit with status: ' +
                              str(sender.json()))
                        self.agent.users_retrived[i].messages_received += 1
                    else:
                        print('message sent failed')
                        print(sender.json())
                else:
                    if not u.initially_friend:
                        print(
                            'user ' + str(u.guid) +
                            ' already is my friend, so my job with him is done.'
                            +
                            ' Removing him from the contact list. i\'ve sent him '
                            + str(u.messages_received) + ' messages about ' +
                            str(u.last_theme))
                if self.agent.users_retrived[
                        i].messages_received > 0 and self.agent.users_retrived[
                            i].messages_received % 3 == 0:
                    # self.agent.users_retrived[i].information.pop(0)
                    self.agent.is_done = True

            if self.agent.is_done:
                self.kill()