2021-10-23 13:20:37 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# IMPORTS
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
from code.local.typing import *;
|
|
|
|
|
|
|
|
from code.core.log import *;
|
2021-10-24 16:35:29 +02:00
|
|
|
from code.setup.cli import GetArgumentParser;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODS display help
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
def DisplayHelpMessage():
|
|
|
|
parser = GetArgumentParser();
|
|
|
|
parser.print_help();
|
|
|
|
return;
|
2021-10-23 13:20:37 +02:00
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODS display case
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-24 23:34:42 +02:00
|
|
|
def DisplayStartOfCase(index: int, descr: Any):
|
2021-10-24 12:40:09 +02:00
|
|
|
DisplayBar(80);
|
2021-10-24 23:34:42 +02:00
|
|
|
if not isinstance(descr, str) or descr == '':
|
|
|
|
logPlain('\033[92;1mCASE {index}\033[0m.'.format(index=index));
|
|
|
|
else:
|
|
|
|
logPlain('\033[92;1mCASE {index}\033[0m (\033[1;2m{descr}\033[0m).'.format(index=index, descr=descr));
|
2021-10-24 12:40:09 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
def DisplayEndOfCase():
|
|
|
|
DisplayBar(80);
|
2021-10-23 13:20:37 +02:00
|
|
|
return;
|
|
|
|
|
2021-10-24 23:34:42 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODS display value
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
def RepresentValue(value: Any) -> Any:
|
|
|
|
if value is None or isinstance(value, (str, bool, int, float)):
|
|
|
|
return value;
|
|
|
|
elif isinstance(value, list):
|
|
|
|
if len(value) > 10:
|
|
|
|
value = value[:3] + [ '...' ] + value[-2:];
|
|
|
|
# return '[{}, ..., {}]'.format(', '.join(value[:3]), ', '.join(value[-2:])
|
|
|
|
return value;
|
|
|
|
return value;
|
|
|
|
|
2021-10-23 13:20:37 +02:00
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODS display algorithm start/end
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-10-24 12:29:06 +02:00
|
|
|
def DisplayStartOfAlgorithm(name: str, *_: Any, **inputs: Any):
|
|
|
|
logPlain('Ausführung vom Algorithmus: \033[92;1m{}\033[0m'.format(name));
|
|
|
|
logPlain('INPUTS');
|
2021-10-23 13:20:37 +02:00
|
|
|
for varname, value in inputs.items():
|
2021-10-24 23:34:42 +02:00
|
|
|
logPlain(' - {} = {}'.format(varname, RepresentValue(value)))
|
2021-10-23 13:20:37 +02:00
|
|
|
return;
|
|
|
|
|
2021-10-24 12:29:06 +02:00
|
|
|
def DisplayEndOfAlgorithm(*_: Any, **outputs: Any):
|
|
|
|
logPlain('OUTPUTS:')
|
2021-10-23 13:20:37 +02:00
|
|
|
for varname, value in outputs.items():
|
2021-10-24 23:34:42 +02:00
|
|
|
logPlain(' - {} = {}'.format(varname, RepresentValue(value)))
|
2021-10-23 13:20:37 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
def DisplayMetrics():
|
2021-10-24 12:32:59 +02:00
|
|
|
logPlain('Dauer der Ausführung: t = \033[1m{}\033[0m'.format(TimeElapsed()));
|
2021-10-24 12:29:06 +02:00
|
|
|
logPlain('Anzahl der Schritte: T(n) = \033[1m{}\033[0m'.format(NumberOfSteps()));
|
|
|
|
return;
|
|
|
|
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
# METHODS Verschiedenes
|
|
|
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
def DisplayBar(n: int = 80):
|
|
|
|
logPlain('+{}+'.format('-'*n));
|
2021-10-23 13:20:37 +02:00
|
|
|
return;
|