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

Convert Disaster Recovery Objectives units #1168

Merged
merged 2 commits into from
Dec 11, 2024
Merged
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
18 changes: 17 additions & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,12 +1581,28 @@ def get_security_objectives_display(self) -> list[dict[str, str]]:
]

def get_disaster_recovery_objectives_display(self) -> list[dict[str, str]]:
def format_seconds(seconds: int) -> str:
hours, remainder = divmod(seconds, 3600)
minutes, secs = divmod(remainder, 60)

parts = []
if hours > 0:
parts.append(f"{hours}h")
if minutes > 0:
parts.append(f"{minutes:02d}m")
if secs > 0 or (
not parts
): # Always show seconds if no other parts, or if > 0
parts.append(f"{secs:02d}s")

return "".join(parts)

"""
Gets the disaster recovery objectives of a given asset as strings.
"""
disaster_recovery_objectives = self.get_disaster_recovery_objectives()
return [
{"str": f"{key}: {content.get('value', 0)}"}
{"str": f"{key}: {format_seconds(content.get('value', 0))}"}
for key, content in disaster_recovery_objectives.get(
"objectives", {}
).items()
Expand Down
Loading