Skip to content

Stopwatch

Bases: Model

Stopwatch Model

Note

The stopwatch model is not a regular interface and instead is dynamically generated on Access through the Card .stopwatch attribute. There is an override that intercepts __getitem__ to return a Stopwatch.

All Stopwatch methods directly update the .stopwatch attribute of the linked Card instance.

Attributes:

Name Type Description
startedAt datetime

The start date of the stopwatch

total int

The total time of the stopwatch (in seconds)

_card Card

The card the stopwatch is associated with (Managed by the Card class)

Source code in src/plankapy/models.py
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
@dataclass(eq=False)
class Stopwatch(Model):
    """Stopwatch Model

    Note:
        The stopwatch model is not a regular interface and instead is dynamically generated on
        Access through the `Card` `.stopwatch` attribute. There is an override that intercepts
        `__getitem__` to return a `Stopwatch`. 

        All `Stopwatch` methods directly update the `.stopwatch` attribute of the linked `Card` 
        instance.

    Attributes:
        startedAt (datetime): The start date of the stopwatch
        total (int): The total time of the stopwatch (in seconds)
        _card (Card): The card the stopwatch is associated with (Managed by the `Card` class)
    """
    _card: Optional[Card_]=Unset
    startedAt: Optional[str]=Unset
    total: Optional[int]=Unset

    def refresh(self):
        self._card.refresh()
        self.startedAt = self._card.stopwatch.startedAt
        self.total = self._card.stopwatch.total

    def start_time(self) -> datetime:
        """Returns the datetime the stopwatch was started"""
        self.refresh()
        return datetime.fromisoformat(self.startedAt) if self.startedAt else None

    def start(self) -> None:
        """Starts the stopwatch"""
        self.refresh()
        if self.startedAt:
            return
        self.startedAt = datetime.now().isoformat()
        with self._card.editor():
            self._card.stopwatch = self

    def stop(self) -> None:
        """Stops the stopwatch"""
        self.refresh()
        if not self.startedAt:
            return

        now = datetime.now()
        started = datetime.fromisoformat(self.startedAt)
        self.total += int(now.timestamp() - started.timestamp())
        self.startedAt = None
        with self._card.editor():
            self._card.stopwatch = self

    def set(self, hours: int=0, minutes: int=0, seconds: int=0) -> None:
        """Set an amount of time for the stopwatch

        Args:
            hours (int): Hours to set
            minutes (int): Minutes to set
            seconds (int): Seconds to set
        """
        self.total = (hours * 3600) + (minutes * 60) + seconds
        with self._card.editor():
            self._card.stopwatch = self

set(hours=0, minutes=0, seconds=0)

Set an amount of time for the stopwatch

Parameters:

Name Type Description Default
hours int

Hours to set

0
minutes int

Minutes to set

0
seconds int

Seconds to set

0
Source code in src/plankapy/models.py
674
675
676
677
678
679
680
681
682
683
684
def set(self, hours: int=0, minutes: int=0, seconds: int=0) -> None:
    """Set an amount of time for the stopwatch

    Args:
        hours (int): Hours to set
        minutes (int): Minutes to set
        seconds (int): Seconds to set
    """
    self.total = (hours * 3600) + (minutes * 60) + seconds
    with self._card.editor():
        self._card.stopwatch = self

start()

Starts the stopwatch

Source code in src/plankapy/models.py
652
653
654
655
656
657
658
659
def start(self) -> None:
    """Starts the stopwatch"""
    self.refresh()
    if self.startedAt:
        return
    self.startedAt = datetime.now().isoformat()
    with self._card.editor():
        self._card.stopwatch = self

start_time()

Returns the datetime the stopwatch was started

Source code in src/plankapy/models.py
647
648
649
650
def start_time(self) -> datetime:
    """Returns the datetime the stopwatch was started"""
    self.refresh()
    return datetime.fromisoformat(self.startedAt) if self.startedAt else None

stop()

Stops the stopwatch

Source code in src/plankapy/models.py
661
662
663
664
665
666
667
668
669
670
671
672
def stop(self) -> None:
    """Stops the stopwatch"""
    self.refresh()
    if not self.startedAt:
        return

    now = datetime.now()
    started = datetime.fromisoformat(self.startedAt)
    self.total += int(now.timestamp() - started.timestamp())
    self.startedAt = None
    with self._card.editor():
        self._card.stopwatch = self