def get_agent_stats()

in src/dfcx_scrapi/tools/stats_util.py [0:0]


    def get_agent_stats(self, agent_id: str = None, output="stdout"):
        """Provides a snapshot of resource stats from the specified CX Agent

        Pulls all resources from CX Agent and iterates over Flows/Pages to calc
        various design-time stats to be used for offline analysis, determining
        bot complexity, and various other tasks.

        Args:
          agent_id: the CX Agent ID to pull stats from
          output: Optional output format of the stats which can be ONEOF:
            'stdout', 'dict'
        """

        if not agent_id:
            agent_id = self.agent_id

        agent_obj = self._agents_tracker.get_agent(agent_id)

        flows_map = self._get_flows_map(agent_id)

        all_intents = self._intents_tracker.bulk_intent_to_df(
            agent_id=agent_id)
        all_entity_types = self._entity_tracker.list_entity_types(
            agent_id=agent_id)
        all_pages = self._list_all_pages(flows_map)
        all_rgs = self._list_all_rgs(flows_map)

        agent_display_name = agent_obj.display_name
        flows_count = len(flows_map.keys())
        pages_count = len(all_pages)
        intents_count = all_intents.display_name.nunique()
        tp_count = all_intents.shape[0]
        entity_types_count = len(all_entity_types)
        rg_count = len(all_rgs)

        if output == "stdout":
            print(f"Agent ID: {agent_id}")
            print(f"Agent Display Name: {agent_display_name}")
            print(f"Total # of Flows: {flows_count}")
            print(f"Total # of Pages: {pages_count}")
            print(f"Total # of Intents: {intents_count}")
            print(f"Total # of Training Phrases: {tp_count}")
            print(f"Total # of Entity Types: {entity_types_count}")
            print(f"Total # of Route Groups: {rg_count}")

        if output == "dict":
            stats = {
                "agent_id": agent_id,
                "display_name": agent_display_name,
                "flows": flows_count,
                "pages": pages_count,
                "intents": intents_count,
                "training_phrases": tp_count,
                "entity_types": entity_types_count,
                "route_groups": rg_count
            }

            return stats

        return None