Skip to content

Commit

Permalink
Rewrite visualise
Browse files Browse the repository at this point in the history
  • Loading branch information
mberk committed Jul 25, 2021
1 parent 34b4e1a commit 2e4a2ab
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions betfairviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24586,20 +24586,32 @@ def _create_runner_book_iframe(runner_book: Union[Dict[str, Any], RunnerBook]) -


def visualise(
market_book: Union[Dict[str, Any], MarketBook],
market_book_or_runner_book: Union[Dict[str, Any], MarketBook, RunnerBook],
depth: int = 3,
style: Union[str, Style] = Style.DEFAULT) -> Union[HTML, Pretty]:
if (5 < depth) or (depth < 3):
raise ValueError(f'depth = {depth} is unsupported. Valid values are 3, 4 and 5')
if type(style) is str:
style = Style(style)

if style is Style.DEFAULT:
return HTML(_create_market_book_iframe(market_book=market_book, depth=depth))
elif style is Style.RAW:
return Pretty(pretty(market_book))
if is_market_book(market_book_or_runner_book):
market_book = market_book_or_runner_book
if style is Style.DEFAULT:
return HTML(_create_market_book_iframe(market_book=market_book, depth=depth))
elif style is Style.RAW:
return Pretty(pretty(market_book))
else:
raise ValueError(f'Unrecognised style: {style}')
elif is_runner_book(market_book_or_runner_book):
runner_book = market_book_or_runner_book
if style is Style.DEFAULT:
return HTML(_create_runner_book_iframe(runner_book=runner_book))
elif style is Style.RAW:
return Pretty(pretty(runner_book))
else:
raise ValueError(f'Unrecognised style: {style}')
else:
raise ValueError(f'Unrecognised style: {style}')
raise TypeError(f'market_book_or_runner_book is neither a market book nor a runner book')


visualize = visualise
Expand Down

0 comments on commit 2e4a2ab

Please sign in to comment.