Esempio n. 1
0
def process_file():
    if not request.json or not request.json['fileId']:
        requestData = request.json or str(request.form) or request.data
        return make_response('Invalid content: ' + requestData, 400)

    db = MongoInit().initialize()

    payload = { 'fileId': request.json['fileId'], 'user': get_current_user().id }

    fileService = FileService(db)
    messageService = MessageService(db)
    
    chunks = fileService.getChunksByFileId(payload['fileId'])

    messages = []
    if all(c.user == payload['user'] for c in chunks):
        messages = messageService.parseFileChunks(chunks)

    topMessages = []

    for message in messages[:50]:
        topMessages.append({'subject': message.subject, 'sender': message.sender, 'content': message.content, 'date': message.date})

    result = {'fileId': payload['fileId'], 'messages': topMessages}

    return make_response(jsonify(result))
Esempio n. 2
0
    def test_get_messages_when_message_in_repository_empty(self):
        message_service = MessageService(self.mock_image_repository)

        self.mock_image_repository.find_all.return_value = []
        messages = message_service.get_messages()

        expected_message = []
        self.assertEqual(messages, expected_message)
Esempio n. 3
0
    def test_store_message_when_message_in_repository_empty(self):
        message_service = MessageService(self.mock_image_repository)

        self.mock_image_repository.save.return_value = 'New Message'
        response = message_service.store('New Message')

        expected_reponse = 'New Message'
        self.assertEqual(response, expected_reponse)
Esempio n. 4
0
def get_message(id):
    db = MongoInit().initialize()
    
    messageService = MessageService(db)
    
    message = messageService.getMessageById(id)
    
    result = {'subject': message.subject, 'sender': message.sender, 'content': message.content, 'date': message.date}
    
    return make_response(jsonify(result), 200)
Esempio n. 5
0
def index():
    user = get_current_user()    
    if user == None:
        return redirect('/login',302)
    else:
        db = MongoInit().initialize()
        messageService = MessageService(db)
        messages = messageService.getMessagesByUserByPage(user.id, 0, 50)
        return render_template("index.html",
                               title='Home',
                               user=user,
                               messages=messages)
Esempio n. 6
0
def check_correctness(audio : str, position : int):
    
    if round_dict[1] == None:
        round_dict[1] = (audio, position)
        position_to_screen = (position, None)
        message = f"Reproduzindo audio na posição {position}: {audio}"
        MessageService.show_screen(completed, positions_played = position_to_screen, message=message)
        SoundService.play_sound(audio)
        
        
    elif round_dict[1][0] == audio and round_dict[1][1]!=position:
        completed[round_dict[1][1]] = 1
        completed[position] = 1
        position_to_screen = (round_dict[1][1], position)
        message = f"Reproduzindo audio na posição {position}: {audio}"
        MessageService.show_screen(completed, positions_played = position_to_screen, message=message)
        SoundService.play_sound(audio)
        SoundService.play_sound(CORRECT_AUDIO)
        round_dict[1] = None
        round_dict[2] = None
        position_to_screen = (None, None)
        
    else:
        position_to_screen = (round_dict[1][1], position)
        message = f"Reproduzindo audio na posição {position}: {audio}"
        MessageService.show_screen(completed, positions_played = position_to_screen, message=message)
        SoundService.play_sound(audio)
        SoundService.play_sound(WRONG_AUDIO)
        round_dict[1] = None
        round_dict[2] = None
        position_to_screen = (None, None)

        
    MessageService.show_screen(completed, positions_played = position_to_screen)
Esempio n. 7
0
def get_clusters(userId):
    db = MongoInit().initialize()
    messageService = MessageService(db)
    messages = messageService.getMessagesByUser(userId)

    nlpService = NLPService()
    clusters = nlpService.processMessages(messages)

    result = []

    for key, values in clusters.iteritems():
        clusterId = int(key)
        clusteredMessages = [{'subject': v.subject, 'sender': v.sender, 'content': v.originalContent, 'date': v.date} for v in values[:10]]
        cluster = {'clusterId': clusterId, 'messages': clusteredMessages}
        result.append(cluster)
    
    return make_response(jsonify({'clusters':result}), 200)
    def post(self):
        arg = self.get_argument_dict(
            must_keys=["name", "tel", "email", "content"], check_token=False)

        result = MessageService().create_message(name=arg.get("name"),
                                                 tel=arg.get("tel"),
                                                 email=arg.get("email"),
                                                 content=arg.get("content"))
        return {"code": 0, "msg": "success", "data": result}
Esempio n. 9
0
def on_press(key):

    MessageService.show_screen(completed)

    if key == keyboard.Key.esc:
            return False

    for i in range(10):

        if key == keyboard.KeyCode.from_char(str(i)):
            audio_to_play = new_audio_list[i]
            check_correctness(audio_to_play, i)

    if key.vk == 65437:
        audio_to_play = new_audio_list[5]
        check_correctness(audio_to_play, 5)


    if sum(completed) == len(completed):
        MessageService.show_screen(completed, message="Parabéns, voce concluiu o jogo")
        SoundService.play_sound(WINNER_AUDIO)
        return False        
    def post(self):
        self.get_argument_dict(must_keys=["user_id"])
        message_list = MessageService().messages()

        result_list = []
        for message in message_list:
            result = {
                "id": message.id,
                "created_at": str(message.created_at),
                "name": message.name,
                "tel": message.tel,
                "email": message.email,
                "content": message.content
            }
            result_list.append(result)

        return {"code": 0, "msg": "success", "data": result_list}
Esempio n. 11
0
def main():
    tornado.options.parse_command_line()
    message_repository = MessageRepository()
    message_service = MessageService(message_repository)

    app = tornado.web.Application(handlers=[
        (r"/real-time-message", RealTimeMessageHandler),
        (r"/", IndexHandler),
        (r"/message", MessageHandler, {
            'message_service': message_service
        }),
        (r"/static/(.*)", tornado.web.StaticFileHandler, {
            'path': TEMPLATE_PATH
        }),
    ],
                                  template_path=TEMPLATE_PATH)
    server = tornado.httpserver.HTTPServer(app)
    server.bind(PORT)
    server.start()
    logging.info('Server Start')
    ioloop.IOLoop.current().start()
Esempio n. 12
0
            return False

    for i in range(10):

        if key == keyboard.KeyCode.from_char(str(i)):
            audio_to_play = new_audio_list[i]
            check_correctness(audio_to_play, i)

    if key.vk == 65437:
        audio_to_play = new_audio_list[5]
        check_correctness(audio_to_play, 5)


    if sum(completed) == len(completed):
        MessageService.show_screen(completed, message="Parabéns, voce concluiu o jogo")
        SoundService.play_sound(WINNER_AUDIO)
        return False        

def main():

    with keyboard.Listener(on_press=on_press) as listener:
        listener.join()

if __name__ == "__main__":
    new_audio_list = shuffle_game(AUDIO_LIST)
    completed = [0] * 10
    round_dict = {1: None, 2: None}
    
    MessageService.show_screen(completed)

    main()