Exemplo n.º 1
0
 def process_overview(self, data):
     """Process the data retured from an Overview-Query."""
     data = data.get("reportData") or data
     summary_data = utils.get_nested_value(data, "report", "summary",
                                           "data") or {}
     self.duration = self.duration or summary_data.get("totalTime", 0)
     self.process_players(summary_data)
Exemplo n.º 2
0
    def test__preprocess_query_results__multiple_casts_with_end_event(self):

        zone = RaidZone(id=1, name="TestZone")
        boss = RaidBoss(zone=zone, id=10, name="TestBoss")
        boss.add_event(spell_id=100, until={"spell_id": 200})

        query_result = {
            'report': {
                'events': {
                    'data': [
                        {'timestamp': 100, 'type': 'cast', 'abilityGameID': 100},
                        {'timestamp': 110, 'type': 'cast', 'abilityGameID': 200},
                        {'timestamp': 200, 'type': 'cast', 'abilityGameID': 100},
                        {'timestamp': 230, 'type': 'cast', 'abilityGameID': 200},
                    ]
                }
            }
        }

        processed = boss.preprocess_query_results(query_result)

        casts = utils.get_nested_value(processed, "report", "events", "data") or []
        assert len(casts) == 2
        assert casts[0].get("duration") == 10
        assert casts[1].get("duration") == 30
Exemplo n.º 3
0
    def process_query_result(self, query_result):
        super().process_query_result(query_result)

        # for spec rankings we don't know the source ID upfront..
        # but we can fill that gap here
        if not self._has_source_id:
            casts = utils.get_nested_value(query_result, "report", "events",
                                           "data") or []
            for cast in casts:
                cast_type = cast.get("type")
                if cast_type == "cast":
                    self.source_id = cast.get("sourceID")
                    break
Exemplo n.º 4
0
    def preprocess_query_results(self, query_results):

        casts = utils.get_nested_value(query_results, "report", "events",
                                       "data") or []
        events_by_id = {event.get("spell_id"): event for event in self.events}

        def get_duration(event_data, cast_data, casts):
            """
                event_data: the event we are checking
                cast_data: the current cast of that event
                casts: list of all casts
            """
            until = event_data.get("until")
            if not until:
                return

            until_id = until.get("spell_id")
            timestamp = cast_data.get("timestamp")

            end_events = [
                cast for cast in casts if cast.get("abilityGameID") == until_id
                and cast.get("timestamp") > timestamp
            ]
            if not end_events:
                return
            end_event = end_events[0]
            end_event["remove"] = True
            cast_data["duration"] = end_event.get("timestamp") - cast_data.get(
                "timestamp")

        for cast_data in casts:
            spell_id = cast_data.get("abilityGameID")

            # check if this is a custom event
            event_data = events_by_id.get(spell_id)
            if not event_data:
                continue

            get_duration(event_data, cast_data, casts)

        casts = [cast for cast in casts if not cast.get("remove")]

        query_results["report"]["events"]["data"] = casts
        return query_results
Exemplo n.º 5
0
def test__get_nested_value__default():
    data = {"attr": {"name": 5}}
    assert utils.get_nested_value(data, "attr", "other", default=32) == 32
Exemplo n.º 6
0
def test__get_nested_value__simple_deep():
    data = {"some": {"deep": {"nested": {"attr": {"name": "Hello!"}}}}}

    assert utils.get_nested_value(data, "some", "deep", "nested", "attr",
                                  "name") == "Hello!"
Exemplo n.º 7
0
def test__get_nested_value__simple():
    data = {"attr": {"name": 5}}
    assert utils.get_nested_value(data, "attr", "name") == 5
Exemplo n.º 8
0
def test__get_nested_value__empty_input():
    assert utils.get_nested_value({}, "attr", "name") == None
Exemplo n.º 9
0
 def process_query_result(self, query_result):
     query_result = utils.get_nested_value(query_result, "worldData",
                                           "encounter", "characterRankings",
                                           "rankings") or {}
     self.add_new_fights(query_result)