Skip to content

Commit

Permalink
made capture_duration to use Type_Safe base class
Browse files Browse the repository at this point in the history
  • Loading branch information
DinisCruz committed Jul 25, 2024
1 parent 780f82a commit 941e9ce
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions osbot_utils/context_managers/capture_duration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from osbot_utils.base_classes.Type_Safe import Type_Safe
from osbot_utils.utils.Misc import timestamp_utc_now


class capture_duration():
def __init__(self):
self.duration = None
self.start_timestamp = None
self.end_timestamp = None
self.seconds = None
class capture_duration(Type_Safe):
action_name : str
duration : float
start_timestamp : int
end_timestamp : int
seconds : float

def __enter__(self):
self.start_timestamp = timestamp_utc_now()
Expand All @@ -23,7 +24,10 @@ def data(self):

def print(self):
print()
print(f'action took: {self.seconds} seconds')
if self.action_name:
print(f'action "{self.action_name}" took: {self.seconds} seconds')
else:
print(f'action took: {self.seconds} seconds')

class print_duration(capture_duration):

Expand Down

0 comments on commit 941e9ce

Please sign in to comment.