Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ron and Mark Request Updates #65

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions odins_spear/reports/group_users_call_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,52 @@ def main(api: object, service_provider_id: str, group_id: str,

# Fetches complete list of users in group
users = api.get.users(service_provider_id, group_id)
failed_users = []

# Pulls stats for each user, instantiates call_records_statistics, and append to group_users_statistics
for user in tqdm(users, "Fetching individual stats for each user. This may take several minutes"):
user_statistics = api.get.users_stats(
user["userId"],
start_date,
end_date,
start_time,
end_time,
time_zone
)

try:
user_statistics = api.get.users_stats(
user["userId"],
start_date,
end_date,
start_time,
end_time,
time_zone
)

user_services = api.get.user_services(
user_id=user["userId"]
)

except Exception:
# attempt 2
try:
user_statistics = api.get.users_stats(
user["userId"],
start_date,
end_date,
start_time,
end_time,
time_zone
)

user_services = api.get.user_services(
user_id=user["userId"]
)

except Exception:
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"]

user_statistic_record = call_records_statistics.from_dict(user["extension"], user_statistics)
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
Expand All @@ -71,6 +100,14 @@ def main(api: object, service_provider_id: str, group_id: str,

for user in group_users_statistics:
writer.writerow(user.__dict__)

# Adds list of failed users to the bottom
if failed_users:
writer.writerow({})
writer.writerow({fieldnames[1]: "Failed Users"})

for failed_user in failed_users:
writer.writerow({fieldnames[1]: failed_user['userId']})

# Add made_with_os.png for output
copy_single_file_to_target_directory("./odins_spear/assets/images/", "./os_reports/", "made_with_os.png")
Expand Down
8 changes: 7 additions & 1 deletion odins_spear/reports/report_utils/report_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ class external_number:

@dataclass
class call_records_statistics:
first_name: str
last_name: str
extension: str
userId: str
feature_packs: list
total: int
totalAnsweredAndMissed: str
answeredTotal: str
Expand All @@ -36,10 +39,13 @@ def replace_none_with_0(self):
setattr(self, field.name, 0)

@classmethod
def from_dict(cls, extension, data):
def from_dict(cls, first_name, last_name, extension, data):
return cls(
first_name = first_name,
last_name = last_name,
extension = extension,
userId= data.get("userId"),
feature_packs = data.get("servicePackServices"),
total= data.get("total"),
totalAnsweredAndMissed= str(data.get("totalAnsweredAndMissed")),
answeredTotal= data.get("answeredTotal"),
Expand Down