diff --git a/odins_spear/reports/group_users_call_statistics.py b/odins_spear/reports/group_users_call_statistics.py index 4f1ef3b..8205a5a 100644 --- a/odins_spear/reports/group_users_call_statistics.py +++ b/odins_spear/reports/group_users_call_statistics.py @@ -52,9 +52,9 @@ def main(api: object, service_provider_id: str, group_id: str, user_services = api.get.user_services( user_id=user["userId"] ) - + except Exception: - # attempt 2 + # attempt 2 in case of connection time out try: user_statistics = api.get.users_stats( user["userId"], @@ -73,19 +73,29 @@ def main(api: object, service_provider_id: str, group_id: str, failed_users.append(user) continue - user_statistics["servicePackServices"] = [service["serviceName"] for service in user_services["servicePackServices"] if service["assigned"]] - # Correction for API removing userId if no calls made by user - if user_statistics["userId"] is None: - user_statistics["userId"] = user["userId"] + if not user_statistics: + user_statistics = { + "userId": user["userId"], + "total": 0, + "totalAnsweredAndMissed": 0, + "answeredTotal": 0, + "missedTotal": 0, + "busyTotal": 0, + "redirectTotal": 0, + "receivedTotal": 0, + "receivedMissed": 0, + "receivedAnswered": 0, + "placedTotal": 0, + "placedMissed": 0, + "placedAnswered": 0 + } + + user_statistics["servicePackServices"] = [service["serviceName"] for service in user_services["servicePackServices"] if service["assigned"]] user_statistic_record = call_records_statistics.from_dict(user["firstName"], user["lastName"], user["extension"], user_statistics) group_users_statistics.append(user_statistic_record) - # replace none with 0 if data returns None. Output is better if 0 allows user to make use of data better - for record in tqdm(group_users_statistics, "Formatting individual stats for each user"): - record.replace_none_with_0() - output_directory = "./os_reports" file_name = os.path.join(output_directory, f"{group_id} User Call Statistics - {start_date} to {end_date}.csv") diff --git a/odins_spear/reports/report_utils/report_entities.py b/odins_spear/reports/report_utils/report_entities.py index f297684..31c452b 100644 --- a/odins_spear/reports/report_utils/report_entities.py +++ b/odins_spear/reports/report_utils/report_entities.py @@ -30,13 +30,6 @@ class call_records_statistics: placedTotal: str placedMissed: str placedAnswered: str - - def replace_none_with_0(self): - for field in fields(self): - value = getattr(self, field.name) - # Replace None with 0 - if value is None or value == 'None': - setattr(self, field.name, 0) @classmethod def from_dict(cls, first_name, last_name, extension, data):