# Path: athlib/exceptions.py
# class RuleViolation(Exception):
#     """Exception to indicate incorrect athletics logic
# 
#     This may be used if, for example, there is a fourth
#     attempt at a high jump.  We use this as a form of
#     assertion within the code; others are welcome to as well.
#     """
#     pass


from decimal import Decimal
from .exceptions import RuleViolation
from typing import Tuple, List, Dict
        self.jumpers_by_bib[j.bib] = j
        self.jumpers.append(j)
        self.ranked_jumpers.append(j)

        # record what happened
        self.actions.append(('add_jumper', kwargs))

    def set_bar_height(self, new_height: Decimal) -> None:
        if self.state=='scheduled':
            self.state = 'started'
        elif self.state not in ('started','jumpoff','won'):
            raise RuleViolation('Bar height cannot be set in a %s competition!' % self.state)
        prev_height = (self.heights and self.heights[-1]) or Decimal("0.00")
        if (self.state!='jumpoff') and (prev_height >= new_height):
            raise RuleViolation("The bar can only go up, except in a jump-off")
        for j in self.jumpers:
            if not j.eliminated:
                j.dismissed = False
        self.heights.append(new_height)
        self.bar_height = new_height
        self.actions.append(('set_bar_height', new_height))

    def check_started(self, bib: str, label: str = 'jumping') -> Jumper:
        jumper = self.jumpers_by_bib[bib]
        state = self.state
        if state not in ('started','jumpoff'):
            if state in ('won','drawn'):
                if jumper.place!=1:
                    raise RuleViolation('The competition has been %s and %s is not allowed!' % (state,label))
            elif state == 'finished':

# Path: athlib/exceptions.py
# class RuleViolation(Exception):
#     """Exception to indicate incorrect athletics logic
# 
#     This may be used if, for example, there is a fourth
#     attempt at a high jump.  We use this as a form of
#     assertion within the code; others are welcome to as well.
#     """
#     pass


# Path: athlib/highjump.py
from decimal import Decimal
from .exceptions import RuleViolation
from typing import Tuple, List, Dict

        self.jumpers_by_bib[j.bib] = j
        self.jumpers.append(j)
        self.ranked_jumpers.append(j)

        # record what happened
        self.actions.append(('add_jumper', kwargs))

    def set_bar_height(self, new_height: Decimal) -> None:
        if self.state=='scheduled':
            self.state = 'started'
        elif self.state not in ('started','jumpoff','won'):
            raise RuleViolation('Bar height cannot be set in a %s competition!' % self.state)
        prev_height = (self.heights and self.heights[-1]) or Decimal("0.00")
        if (self.state!='jumpoff') and (prev_height >= new_height):
            raise RuleViolation("The bar can only go up, except in a jump-off")
        for j in self.jumpers:
            if not j.eliminated:
                j.dismissed = False
        self.heights.append(new_height)
        self.bar_height = new_height
        self.actions.append(('set_bar_height', new_height))

    def check_started(self, bib: str, label: str = 'jumping') -> Jumper:
        jumper = self.jumpers_by_bib[bib]
        state = self.state
        if state not in ('started','jumpoff'):
            if state in ('won','drawn'):
                if jumper.place!=1:
                    raise RuleViolation('The competition has been %s and %s is not allowed!' % (state,label))
            elif state == 'finished':

                raise RuleViolation('The competition has finished and %s is not allowed!' % label)