Skip to content

Commit

Permalink
72 update to api will cause issue with group user call statistics (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivCurtis authored Sep 23, 2024
1 parent c07cbff commit f73059c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
30 changes: 20 additions & 10 deletions odins_spear/reports/group_users_call_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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")

Expand Down
7 changes: 0 additions & 7 deletions odins_spear/reports/report_utils/report_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f73059c

Please sign in to comment.