Skip to content

Commit

Permalink
Convert Disaster Recovery Objectives units (#1168)
Browse files Browse the repository at this point in the history
Co-authored-by: eric-intuitem <[email protected]>
  • Loading branch information
ab-smith and eric-intuitem authored Dec 11, 2024
1 parent 8bee503 commit c496f1b
Showing 1 changed file with 17 additions and 1 deletion.
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

0 comments on commit c496f1b

Please sign in to comment.