From 51f84dd1205bf5e1a6d555b849b834fae66d92fb Mon Sep 17 00:00:00 2001 From: Jordan Prescott Date: Tue, 8 Oct 2024 09:24:12 +0100 Subject: [PATCH] 49 call flow issues 2 (#126) --- odins_spear/methods/get.py | 19 ++++ odins_spear/reports/call_flow.py | 6 +- .../reports/report_utils/graphviz_module.py | 87 ++++++++++++------- 3 files changed, 79 insertions(+), 33 deletions(-) diff --git a/odins_spear/methods/get.py b/odins_spear/methods/get.py index ef3382c..46d0d19 100644 --- a/odins_spear/methods/get.py +++ b/odins_spear/methods/get.py @@ -161,6 +161,25 @@ def user_call_center(self, user_id: str): + def group_call_center_agents(self, service_user_id: str): + """Returns list of agents assigned to the target call center. + + Args: + service_user_id (str): Service user ID of target call center. + + Returns: + Dict: List of agents assigned to call center + """ + + endpoint = "/groups/call-centers/agents" + + params = { + "serviceUserId": service_user_id + } + + return self.requester.get(endpoint, params=params) + + def group_call_center_bounced_calls(self, service_user_id: str): """Retrieves the number of rings before a call is bounced from the specified call center. diff --git a/odins_spear/reports/call_flow.py b/odins_spear/reports/call_flow.py index e193a66..6b47c4c 100644 --- a/odins_spear/reports/call_flow.py +++ b/odins_spear/reports/call_flow.py @@ -68,7 +68,11 @@ def main(api, service_provider_id: str, group_id: str, number: str, number_type: call_centers = api.get.group_call_centers(service_provider_id, group_id) for cc in tqdm(call_centers, desc=f"Fetching all Call Centers."): - call_center = bre.CallCenter.from_dict(group= group, data= api.get.group_call_center(cc['serviceUserId'])) + + call_center = api.get.group_call_center(cc['serviceUserId']) + call_center['agents'] = api.get.group_call_center_agents(cc['serviceUserId'])['agents'] + + call_center = bre.CallCenter.from_dict(group= group, data= call_center) try: overflow_settings = api.get.group_call_center_overflow(call_center.service_user_id) diff --git a/odins_spear/reports/report_utils/graphviz_module.py b/odins_spear/reports/report_utils/graphviz_module.py index bf8461a..4cf6afa 100644 --- a/odins_spear/reports/report_utils/graphviz_module.py +++ b/odins_spear/reports/report_utils/graphviz_module.py @@ -31,40 +31,40 @@ class GraphvizModule: 'fontcolor': 'white' }, 'auto_attendant': { - 'shape': 'circle', + 'shape': 'record', 'style': 'filled', 'margin': '0.2', - 'color': '#5E1008', - 'fillcolor': '#FF0000', + 'color': '#1C3A3A', + 'fillcolor': '#356969', 'fontname': 'Arial', 'fontcolor': 'white' }, 'call_centre': { - 'shape': 'Mrecord', + 'shape': 'record', 'style': 'filled', 'margin': '0.2', - 'color': '#68272E', - 'fillcolor': '#FFC0CB', + 'color': '#9773F1', + 'fillcolor': '#B4A0E5', 'fontname': 'Arial', 'fontcolor': 'white' }, 'hunt_group': { - 'shape': 'Mrecord', + 'shape': 'record', 'style': 'filled', 'margin': '0.2', - 'color': '#3D4066', - 'fillcolor': '#9C1FE9', + 'color': '#E892E2', + 'fillcolor': '#E9BCE6', 'fontname': 'Arial', - 'fontcolor': 'white' + 'fontcolor': 'black' }, 'user': { - 'shape': 'Mrecord', + 'shape': 'record', 'style': 'filled', 'margin': '0.2', - 'color': '#B87700', - 'fillcolor': '#FBA200', + 'color': '#CAE188', + 'fillcolor': '#E3FE97', 'fontname': 'Arial', - 'fontcolor': 'white' + 'fontcolor': 'black' }, } @@ -85,14 +85,29 @@ def generate_call_flow_graph(self, nodes: list, number: str): # build nodes self.dot.node("Start", "Start", GraphvizModule.NODE_STYLING["start"]) for n in nodes: + + try: + node_config = f" Extension: {n.extension} " + except AttributeError: + node_config = "" + if isinstance(n, bre.User): - self.dot.node(n.id, n.extension, GraphvizModule.NODE_STYLING["user"]) - elif isinstance(n, bre.CallCenter): - self.dot.node(n.service_user_id, n.extension, GraphvizModule.NODE_STYLING["call_centre"]) - elif isinstance(n, bre.HuntGroup): - self.dot.node(n.service_user_id, n.extension, GraphvizModule.NODE_STYLING["hunt_group"]) + self.dot.node(n.id, node_config, GraphvizModule.NODE_STYLING["user"]) + + elif isinstance(n, bre.CallCenter) or isinstance(n, bre.HuntGroup): + node_config += f"| Name: {n.name} | Policy: {n.policy}" + for i, a in enumerate(n.agents): + node_config += f"| <{a.id}> Agent {i+1}: {a.extension}" + self.dot.node(n.service_user_id, node_config, + GraphvizModule.NODE_STYLING["call_centre"] if isinstance(n, bre.CallCenter) + else GraphvizModule.NODE_STYLING["hunt_group"]) + elif isinstance(n, bre.AutoAttendant): - self.dot.node(n.service_user_id, n.extension, GraphvizModule.NODE_STYLING["auto_attendant"]) + node_config += f"| Name: {n.name}" + for k in n.business_hours_menu.keys: + node_config += f"| Option: {k.number}" + k.id = f"{n.service_user_id}:" + self.dot.node(n.service_user_id, node_config, GraphvizModule.NODE_STYLING["auto_attendant"]) # build edges for n in nodes: @@ -133,20 +148,28 @@ def generate_call_flow_graph(self, nodes: list, number: str): elif isinstance(n, bre.AutoAttendant): for key in n.business_hours_menu.keys: if "Transfer" in key.action: - self._format_edge(n, key.phone_number, key.number) + self._format_edge(key, key.phone_number, key.number) - def _format_edge(self, node_a: str, node_b: str, label: str): - try: - self.dot.edge(node_a.id, node_b.id, label, GraphvizModule.EDGE_STYLYING) - except AttributeError: - try: - self.dot.edge(node_a.id, node_b.service_user_id, label, GraphvizModule.EDGE_STYLYING) - except AttributeError: - try: - self.dot.edge(node_a.service_user_id, node_b.service_user_id, label, GraphvizModule.EDGE_STYLYING) - except AttributeError: - self.dot.edge(node_a.service_user_id, node_b.id, label, GraphvizModule.EDGE_STYLYING) + def _format_edge(self, node_a: str, node_b: str, label: str): + if node_b is None: + return None + + node_a_id = node_a.id if hasattr(node_a, 'id') else node_a.service_user_id + node_b_id = node_b.id if hasattr(node_b, 'id') else node_b.service_user_id + + self.dot.edge(node_a_id, node_b_id, label, GraphvizModule.EDGE_STYLYING) + + # try: + # self.dot.edge(node_a.id, node_b.id, label, GraphvizModule.EDGE_STYLYING) + # except AttributeError: + # try: + # self.dot.edge(node_a.id, node_b.service_user_id, label, GraphvizModule.EDGE_STYLYING) + # except AttributeError: + # try: + # self.dot.edge(node_a.service_user_id, node_b.service_user_id, label, GraphvizModule.EDGE_STYLYING) + # except AttributeError: + # self.dot.edge(node_a.service_user_id, node_b.id, label, GraphvizModule.EDGE_STYLYING) def _save_graph(self, filename: str):