Beispiel #1
0
 def parse_update_datetime_intent(self, initial_words, now):
     """
     :param initial_words: The words after !cortana date.
     :param now: Now as a datetime.
     :return: A datetime update intent.
     :raises: If the words are not in the format (old_datetime) [new_datetime].
     """
     (activity_type, words) = self.parse_activity_type(initial_words)
     (old_date_time, _, words) = self.parse_datetime(words, now)
     try:
         (new_date_time, _, words) = self.parse_datetime(words, now)
     except:
         new_date_time = old_date_time
         old_date_time = None
     self.assert_words_empty(words)
     activity_intent = ActivityIntent()
     activity_intent.activity_id.type = activity_type
     old_when = to_when(old_date_time)
     new_when = to_when(new_date_time)
     if old_when:
         activity_intent.activity_id.when.CopyFrom(old_when)
     if new_when:
         activity_intent.update_when.CopyFrom(new_when)
     intent = Intent()
     intent.activity_intent.CopyFrom(activity_intent)
     return intent
Beispiel #2
0
    def test_to_when(self):
        """Verifies the datetime to when converter works as expected."""
        when = to_when(DATETIME1)
        expectation = When()
        expectation.datetime = DATETIME1_STR
        expectation.time_specified = True
        self.assertEqual(when, expectation)

        when = to_when(DATETIME2)
        expectation = When()
        expectation.datetime = DATETIME2_STR
        expectation.time_specified = False
        self.assertEqual(when, expectation)

        when = to_when(DATETIME3)
        expectation = When()
        expectation.datetime = DATETIME3_STR
        expectation.time_specified = True
        self.assertEqual(when, expectation)

        when = to_when(None)
        expectation = None
        self.assertEqual(when, expectation)
Beispiel #3
0
    def test_parse_milestone_intent(self):
        """Verifies milestone intents can properly be parsed."""
        intent = self.sut.parse(
            "!cortana milestone calus prestige save au boss", SUT_BUNDLE,
            SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LEVIATHAN_PRESTIGE
        expectation.activity_intent.set_milestone = "Save au boss"
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana milestone couronne 31/8 21h45 reporté", SUT_BUNDLE,
            SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.CROWN_OF_SORROW
        date_time = datetime(2020,
                             8,
                             31,
                             hour=21,
                             minute=45,
                             tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        expectation.activity_intent.set_milestone = "Reporté"
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana milestone dernier voeu demain save étape 2", SUT_BUNDLE,
            SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        date_time = datetime(2020, 8, 13)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        expectation.activity_intent.set_milestone = "Save étape 2"
        self.assertEqual(intent, expectation)
Beispiel #4
0
    def test_parse_finish_intent(self):
        """Verifies finish intents can properly be parsed."""
        intent = self.sut.parse("!cortana finish jds", SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.GARDEN_OF_SALVATION
        expectation.activity_intent.mark_finished = True
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana finish flèche 5/9 18h", SUT_BUNDLE,
                                SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.SPIRE_OF_STARS
        date_time = datetime(2020, 9, 5, hour=18, tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        expectation.activity_intent.mark_finished = True
        self.assertEqual(intent, expectation)
Beispiel #5
0
    def test_parse_clear_intent(self):
        """Verifies clear intents can properly be parsed."""
        intent = self.sut.parse("!cortana clear couronne", SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.CROWN_OF_SORROW
        expectation.activity_intent.clear = True
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana clear fleau 12/9 21h30", SUT_BUNDLE,
                                SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.SCOURGE_OF_THE_PAST
        date_time = datetime(2020,
                             9,
                             12,
                             hour=21,
                             minute=30,
                             tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        expectation.activity_intent.clear = True
        self.assertEqual(intent, expectation)
Beispiel #6
0
 def parse_clear_intent(self, initial_words, now):
     """
     :param initial_words: The words after !cortana clear.
     :param now: Now as a datetime.
     :return: An activity removal intent.
     :raises: If the words are not in the format [activity_type] (datetime).
     """
     (activity_type, words) = self.parse_activity_type(initial_words)
     date_time = None
     try:
         (date_time, _, words) = self.parse_datetime(words, now)
     except:
         pass
     activity_intent = ActivityIntent()
     activity_intent.activity_id.type = activity_type
     when = to_when(date_time)
     if when:
         activity_intent.activity_id.when.CopyFrom(when)
     self.assert_words_empty(words)
     activity_intent.clear = True
     intent = Intent()
     intent.activity_intent.CopyFrom(activity_intent)
     return intent
Beispiel #7
0
 def parse_update_milestone_intent(self, initial_words, now):
     """
     :param initial_words: The words after !cortana milestone.
     :param now: Now as a datetime.
     :return: A milestone update intent.
     :raises: If the words are not in the format [activity_type] (datetime) [milestone].
     """
     (activity_type, words) = self.parse_activity_type(initial_words)
     date_time = None
     try:
         (date_time, _, words) = self.parse_datetime(words, now)
     except:
         pass
     activity_intent = ActivityIntent()
     activity_intent.activity_id.type = activity_type
     when = to_when(date_time)
     if when:
         activity_intent.activity_id.when.CopyFrom(when)
     if len(words) == 0:
         raise ValueError("Il manque le nom de la milestone")
     activity_intent.set_milestone = " ".join(words).capitalize()
     intent = Intent()
     intent.activity_intent.CopyFrom(activity_intent)
     return intent
Beispiel #8
0
    def test_parse_update_squad_intent(self):
        """Verifies update squad intents with main players can properly be parsed."""
        intent = self.sut.parse(
            "!cortana vœu +cosa -croptus -klaexy +darklight -hartog +Franstuk -ObyChick +kyzerjo",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        player = RatedPlayer()
        player.gamer_tag = "Cosa58"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "croptus"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "KLaeXy"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "dark0l1ght"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Hartog31"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "Franstuk"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Oby1Chick"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "kyzerjo88"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana calus prestige demain 19h +Oby1Chik -live x gamling",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LEVIATHAN_PRESTIGE
        date_time = datetime(2020, 8, 13, hour=19, tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "Oby1Chick"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "LiVe x GamIing"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana flèche prestige 30/08 -snipro -pistache espita -Jezebell +NaughtySOft -cosa",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.SPIRE_OF_STARS_PRESTIGE
        date_time = datetime(2020, 8, 30)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "snippro34"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "pistache espita"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "Jezehbell"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "NaughtySoft"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Cosa58"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana dévoreur dimanche 20h45 SuperFayaChonch +xxmariexx -duality cobra -carnage",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.EATER_OF_WORLDS
        date_time = datetime(2020,
                             8,
                             16,
                             hour=20,
                             minute=45,
                             tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "SuperFayaChonch"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "xXmarie91Xx"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Duality Cobra"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        player.gamer_tag = "CarNaGe4720"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana backup calus prestige samedi 21h30 affectevil bab x waza",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LEVIATHAN_PRESTIGE
        date_time = datetime(2020,
                             8,
                             15,
                             hour=21,
                             minute=30,
                             tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "affectevil"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.substitutes.append(
            player)
        player.gamer_tag = "BAB x WaZZa"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.substitutes.append(
            player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana backup vœu +darklucifel -croptus -strikers frwyx -hartog Franstuk +kyzerjo",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        player = RatedPlayer()
        player.gamer_tag = "DarkLucifiel77"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.substitutes.append(
            player)
        player.gamer_tag = "croptus"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.substitutes.append(
            player)
        player.gamer_tag = "Striikers"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.removed.substitutes.append(
            player)
        player.gamer_tag = "frwyx"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.substitutes.append(
            player)
        player.gamer_tag = "Hartog31"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.removed.substitutes.append(
            player)
        player.gamer_tag = "Franstuk"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.substitutes.append(
            player)
        player.gamer_tag = "kyzerjo88"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.substitutes.append(
            player)
        self.assertEqual(intent, expectation)
Beispiel #9
0
    def test_parse_create_squad_intent(self):
        """Verifies create squad intents with main players can properly be parsed."""
        intent = self.sut.parse(
            "!cortana jds cosa croptus Walnut Waffle darklight hartog Franstuk",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.GARDEN_OF_SALVATION
        player = RatedPlayer()
        player.gamer_tag = "Cosa58"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "croptus"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Walnut Waffle"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "dark0l1ght"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Hartog31"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Franstuk"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana fleau demain 19h Oby1Chik live x gamling", SUT_BUNDLE,
            SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.SCOURGE_OF_THE_PAST
        date_time = datetime(2020, 8, 13, hour=19, tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "Oby1Chick"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "LiVe x GamIing"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana couronne 15/08 snipro pistache espita Jezebell NaughtySOft",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.CROWN_OF_SORROW
        date_time = datetime(2020, 8, 15)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "snippro34"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "pistache espita"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Jezehbell"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "NaughtySoft"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana dernier veu dimanche 14h45 affectevil xxmariexx duality cobra FranckRabbit",
            SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        date_time = datetime(2020,
                             8,
                             16,
                             hour=14,
                             minute=45,
                             tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(date_time))
        player = RatedPlayer()
        player.gamer_tag = "affectevil"
        player.rating = RatedPlayer.Rating.BEGINNER
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "xXmarie91Xx"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "Duality Cobra"
        player.rating = RatedPlayer.Rating.INTERMEDIATE
        expectation.activity_intent.upsert_squad.added.players.append(player)
        player.gamer_tag = "FranckRabbit"
        player.rating = RatedPlayer.Rating.EXPERIENCED
        expectation.activity_intent.upsert_squad.added.players.append(player)
        self.assertEqual(intent, expectation)
Beispiel #10
0
    def test_parse_datetime_intent(self):
        """Verifies date time update intents can properly be parsed."""
        intent = self.sut.parse("!cortana date fureur 25/08 19h", SUT_BUNDLE,
                                SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.WRATH_OF_THE_MACHINE
        new_date_time = datetime(2020, 8, 25, hour=19, tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date caveau vendredi", SUT_BUNDLE,
                                SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.VAULT_OF_GLASS
        new_date_time = datetime(2020, 8, 14)
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date fleau samedi samedi 19h",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.SCOURGE_OF_THE_PAST
        old_date_time = datetime(2020, 8, 15)
        new_date_time = datetime(2020, 8, 15, hour=19, tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana date devoreur demain 21h 30/08 14h30", SUT_BUNDLE,
            SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.EATER_OF_WORLDS
        old_date_time = datetime(2020, 8, 13, hour=21, tzinfo=SUT_TIMEZONE)
        new_date_time = datetime(2020,
                                 8,
                                 30,
                                 hour=14,
                                 minute=30,
                                 tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date devoreur hier demain",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.EATER_OF_WORLDS
        old_date_time = datetime(2020, 8, 11)
        new_date_time = datetime(2020, 8, 13)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date devoreur hier demain 22h05",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.EATER_OF_WORLDS
        old_date_time = datetime(2020, 8, 11)
        new_date_time = datetime(2020,
                                 8,
                                 13,
                                 hour=22,
                                 minute=5,
                                 tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date jardin du salut 22/08 23/08",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.GARDEN_OF_SALVATION
        old_date_time = datetime(2020, 8, 22)
        new_date_time = datetime(2020, 8, 23)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date dernier voeu 20/08 16h45 19/08",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        old_date_time = datetime(2020,
                                 8,
                                 20,
                                 hour=16,
                                 minute=45,
                                 tzinfo=SUT_TIMEZONE)
        new_date_time = datetime(2020, 8, 19)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse(
            "!cortana date dernier voeu 20/08 16h45 19/08 21h30", SUT_BUNDLE,
            SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        old_date_time = datetime(2020,
                                 8,
                                 20,
                                 hour=16,
                                 minute=45,
                                 tzinfo=SUT_TIMEZONE)
        new_date_time = datetime(2020,
                                 8,
                                 19,
                                 hour=21,
                                 minute=30,
                                 tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date dernier voeu vendredi vendredi",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        old_date_time = datetime(2020, 8, 14)
        new_date_time = datetime(2020, 8, 14)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date dernier voeu 20/8 20/8 16h",
                                SUT_BUNDLE, SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LAST_WISH
        old_date_time = datetime(2020, 8, 20)
        new_date_time = datetime(2020,
                                 8,
                                 20,
                                 hour=16,
                                 minute=0,
                                 tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)

        intent = self.sut.parse("!cortana date calus 9/8 9/8 23h", SUT_BUNDLE,
                                SUT_NOW)
        expectation = Intent()
        expectation.activity_intent.activity_id.type = ActivityID.Type.LEVIATHAN
        old_date_time = datetime(2020, 8, 9)
        new_date_time = datetime(2020,
                                 8,
                                 9,
                                 hour=23,
                                 minute=0,
                                 tzinfo=SUT_TIMEZONE)
        expectation.activity_intent.activity_id.when.CopyFrom(
            to_when(old_date_time))
        expectation.activity_intent.update_when.CopyFrom(
            to_when(new_date_time))
        self.assertEqual(intent, expectation)
Beispiel #11
0
    def parse_upsert_squad_intent(self, initial_words, backup, api_bundle,
                                  now):
        """
        :param initial_words: The words after !cortana or !cortana backup.
        :param backup: A boolean telling whether this upsert squad intent must be for substitutes.
        :param api_bundle: The API Bundle used to resolve gamer tags and experience levels.
        :param now: Now as a datetime.
        :return: A squad upsert intent.
        :raises: If the words are not in the format [activity_type] (datetime) [players].
        Each player can be prefixed with a + or a - if needed.
        """
        (activity_type, words) = self.parse_activity_type(initial_words)
        date_time = None
        try:
            (date_time, _, words) = self.parse_datetime(words, now)
        except:
            pass
        activity_intent = ActivityIntent()
        activity_intent.activity_id.type = activity_type
        when = to_when(date_time)
        if when:
            activity_intent.activity_id.when.CopyFrom(when)
        at_least_once = False
        added = []
        removed = []
        while len(words) > 0 or not at_least_once:
            at_least_once = True
            gamer_tag, is_add, words = self.parse_gamer_tag(words, api_bundle)
            stats = api_bundle.stats_by_player[gamer_tag].activity_stats
            rating = RatedPlayer.Rating.UNKNOWN
            for stat in stats:
                if stat.activity_type == activity_type:
                    completions = stat.completions
                    if completions > EXPERIENCED_MIN_COMPLETIONS:
                        rating = RatedPlayer.Rating.EXPERIENCED
                    elif completions > INTERMEDIATE_MIN_COMPLETIONS:
                        rating = RatedPlayer.Rating.INTERMEDIATE
                    else:
                        rating = RatedPlayer.Rating.BEGINNER
                    break
            player = RatedPlayer()
            player.gamer_tag = gamer_tag
            player.rating = rating
            if is_add:
                added.append(player)
            else:
                removed.append(player)

        if len(added) > 0:
            added_squad = Squad()
            if backup:
                added_squad.substitutes.extend(added)
            else:
                added_squad.players.extend(added)
            activity_intent.upsert_squad.added.CopyFrom(added_squad)

        if len(removed) > 0:
            removed_squad = Squad()
            if backup:
                removed_squad.substitutes.extend(removed)
            else:
                removed_squad.players.extend(removed)
            activity_intent.upsert_squad.removed.CopyFrom(removed_squad)

        intent = Intent()
        intent.activity_intent.CopyFrom(activity_intent)
        return intent