-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AnalysisFormatter moved to formatters file
- Loading branch information
1 parent
e7b847e
commit 7ce19aa
Showing
3 changed files
with
54 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import shutil | ||
from typing import List, Tuple | ||
from .enums import NotationFormat | ||
|
||
''' | ||
Class that contains and represents analysis data | ||
''' | ||
class AnalysisFormatter: | ||
|
||
def __init__( | ||
self, | ||
notation_format: NotationFormat, | ||
func_name: str = 'No name', | ||
func_attrs: List[Tuple[str, str]] | None = None, | ||
complexity: str = '1', | ||
memory: str = '1', | ||
) -> None: | ||
|
||
self.notation_format = notation_format | ||
self.func_name = func_name | ||
self.func_attrs = func_attrs | ||
self.complexity = complexity | ||
self.memory = memory | ||
|
||
def report(self, full=True): | ||
|
||
print() | ||
|
||
if full: | ||
print('Function name:', self.func_name) | ||
|
||
if self.func_attrs: | ||
print('Function attributes:', ', '.join([f'{attr_name}: {attr_type}' for attr_name, attr_type in self.func_attrs])) | ||
|
||
terminal_width = shutil.get_terminal_size().columns | ||
indent = max((terminal_width - len(self.notation_format.__str__()) - 2)//2, 0) | ||
print('-' * indent + f' {self.notation_format.__str__()} ' + '-' * indent) | ||
|
||
if self.notation_format == NotationFormat.BIG_O: | ||
print('Сomplexity of algorithm: O({})'.format(self.complexity)) | ||
print('Memory of algorithm: O({})'.format(self.memory)) | ||
|
||
if self.notation_format == NotationFormat.BIG_OMEGA: | ||
print('Сomplexity of algorithm: Ω({})'.format(self.complexity)) | ||
print('Memory of algorithm: Ω({})'.format(self.memory)) | ||
|
||
if self.notation_format == NotationFormat.BIG_THETA: | ||
print('Сomplexity of algorithm: Θ({})'.format(self.complexity)) | ||
print('Memory of algorithm: Θ({})'.format(self.memory)) | ||
|
||
print() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters