Ejemplo n.º 1
0
    def test_nmd_alert_for_user(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 46, 1))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NMD, "ERROR"
Ejemplo n.º 2
0
    def test_nmd_alert_not_sent_when_there_is_alert_before_it(self):
        msg_info_1 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 32, 59))
        msg_info_2 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_DS, 0, 0, dt.datetime(2018, 3, 17, 16, 35, 0))
        msg_info_3 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 38, 00))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.DS, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_3) is CriticalMoment.NONE, "ERROR"
Ejemplo n.º 3
0
    def test_tec_alert_for_group(self):
        msg_info_1 = mi.MessageInfo(MessageTag.TEC, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.TEC, MessageType.TEXT, 0, 1, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_3 = mi.MessageInfo(MessageTag.TEC, MessageType.TEXT, 0, 2, dt.datetime(2018, 3, 17, 16, 41, 0))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_3) is CriticalMoment.TEC, "ERROR"
Ejemplo n.º 4
0
    def test_idleness_text_alert_for_group(self):
        msg_info_1 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 35, 0))
        # no idleness in this message since five minutes have not passed
        msg_info_2 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 39, 0))
        msg_info_3 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 39, 0))
        msg_info_4 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 42, 1))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_2.room_id, msg_info_2.timestamp) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_3) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_4.room_id, msg_info_4.timestamp) is CriticalMoment.IDLENESS, "ERROR"
Ejemplo n.º 5
0
    def test_idleness_alert_for_user(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_CONNECT, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 1, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_3 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 1, dt.datetime(2018, 3, 17, 16, 44, 0))
        msg_info_4 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 45, 0))
        msg_info_5 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 46, 30))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_3) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_4.room_id, msg_info_4.timestamp) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_5.room_id, msg_info_5.timestamp) is CriticalMoment.IDLENESS, "ERROR"
Ejemplo n.º 6
0
    def test_idleness_drag_alert_for_group(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NONE, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.NONE, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 44, 0))
        msg_info_3 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 45, 0))
        msg_info_4 = mi.MessageInfo(MessageTag.NONE, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 47, 0))
        msg_info_5 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 48, 1))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_3.room_id, msg_info_3.timestamp) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_4) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_5.room_id, msg_info_5.timestamp) is CriticalMoment.IDLENESS, "ERROR"
Ejemplo n.º 7
0
    def test_tec_alert_more_important_than_nmd_alert(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 35, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.TEC, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 40, 1))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.TEC, "ERROR"
Ejemplo n.º 8
0
    def test_no_idleness_when_all_users_disconnect_then_connect(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_CONNECT, 0, 0,
                                    dt.datetime(2018, 3, 17, 16, 41, 0))

        # this message opens the room
        msg_info_2 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 42, 0))

        msg_info_3 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0,
                                    dt.datetime(2018, 3, 17, 16, 47, 1))

        msg_info_4 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_DISCONNECT, 0, 0, dt.datetime(2018, 3, 17, 16, 48, 0))

        msg_info_5 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0,
                                    dt.datetime(2018, 3, 17, 16, 55, 0))

        msg_info_6 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_CONNECT, 0, 0,
                                    dt.datetime(2018, 3, 17, 16, 56, 0))

        msg_info_7 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0,
                                    dt.datetime(2018, 3, 17, 16, 59, 30))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_3.room_id,
                                                    msg_info_3.timestamp) is CriticalMoment.IDLENESS, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_4) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_5.room_id,
                                                    msg_info_5.timestamp) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_6) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_7.room_id,
                                                    msg_info_7.timestamp) is CriticalMoment.NONE, "ERROR"
Ejemplo n.º 9
0
    def test_nmd_alert_for_group(self):
        # message just opening the room
        msg_info_0 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 35, 0))

        msg_info_1 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 1, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_3 = mi.MessageInfo(MessageTag.NMD, MessageType.TEXT, 0, 2, dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_4 = mi.MessageInfo(MessageTag.NONE, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))

        assert self.alerter.handle_message_tag(msg_info_0) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_3) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_4) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_4) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_4) is CriticalMoment.NMD, "ERROR"
Ejemplo n.º 10
0
    def post(self):
        json_data = request.get_json(force=True)

        room_id = int(json_data['room_id'])
        timestamp = json_data['timestamp']

        message_info = mi.MessageInfo(
            MessageTag.NONE, MessageType.CHECK_DS, room_id, 0,
            date_parser.parse(timestamp, dayfirst=True))
        critical_moment = alerter.handle_message_tag(message_info)

        return jsonify(critical_moment=critical_moment.value)
Ejemplo n.º 11
0
    def post(self):
        json_data = request.get_json(force=True)

        message_text = json_data['message_text']
        room_id = int(json_data['room_id'])
        user_id = json_data['user_id']
        timestamp = json_data['timestamp']

        message_tag = tagger.tag_sentence(message_text)
        message_info = mi.MessageInfo(
            message_tag, MessageType.TEXT, room_id, user_id,
            date_parser.parse(timestamp, dayfirst=True))
        critical_moment = alerter.handle_message_tag(message_info)

        return jsonify(critical_moment=critical_moment.value)
Ejemplo n.º 12
0
    def test_no_idleness_after_user_disconnects(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_CONNECT, 0, 0,
                                    dt.datetime(2018, 3, 17, 16, 41, 0))
        msg_info_2 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_CONNECT, 0, 1,
                                    dt.datetime(2018, 3, 17, 16, 41, 1))

        # this message opens the room
        msg_info_3 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 42, 0))

        msg_info_4 = mi.MessageInfo(MessageTag.NONE, MessageType.USER_DISCONNECT, 0, 1, dt.datetime(2018, 3, 17, 16, 43, 0))

        # this is a message for not getting idleness from this user
        msg_info_5 = mi.MessageInfo(MessageTag.MAT, MessageType.TEXT, 0, 0, dt.datetime(2018, 3, 17, 16, 45, 00))

        msg_info_6 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 47, 30))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_2) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_3) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_4) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_5) is CriticalMoment.NONE, "ERROR"
        assert self.alerter.check_idleness_for_test(msg_info_6.room_id, msg_info_6.timestamp) is CriticalMoment.NONE, "ERROR"
Ejemplo n.º 13
0
    def test_no_idleness_no_messages(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_IDLENESS, 0, 0, dt.datetime(2018, 3, 17, 16, 44, 1))

        assert self.alerter.check_idleness_for_test(msg_info_1.room_id, msg_info_1.timestamp) is CriticalMoment.NONE, "ERROR"
Ejemplo n.º 14
0
    def test_ds_alert(self):
        msg_info_1 = mi.MessageInfo(MessageTag.NONE, MessageType.CHECK_DS, 0, 0, dt.datetime(2018, 3, 17, 16, 41, 0))

        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.DS, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.DS, "ERROR"
        assert self.alerter.handle_message_tag(msg_info_1) is CriticalMoment.DS, "ERROR"