master > master: code py - refactored code mit Endpunkten
This commit is contained in:
19
code/python/src/models/config/__init__.py
Normal file
19
code/python/src/models/config/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from src.models.config.app import *;
|
||||
from src.models.config.commands import *;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
__all__ = [
|
||||
'log_level',
|
||||
'command_from_json',
|
||||
'interpret_command',
|
||||
];
|
||||
31
code/python/src/models/config/app.py
Normal file
31
code/python/src/models/config/app.py
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from models.generated.config import AppOptions;
|
||||
from models.generated.config import EnumLogLevel;
|
||||
from src.core.log import *;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
__all__ = [
|
||||
'log_level',
|
||||
];
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODS log level
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def log_level(options: AppOptions) -> LOG_LEVELS:
|
||||
match options.log_level:
|
||||
case EnumLogLevel.debug:
|
||||
return LOG_LEVELS.DEBUG;
|
||||
case EnumLogLevel.info:
|
||||
return LOG_LEVELS.INFO;
|
||||
case _:
|
||||
return LOG_LEVELS.INFO;
|
||||
45
code/python/src/models/config/commands.py
Normal file
45
code/python/src/models/config/commands.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# IMPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from src.thirdparty.config import *;
|
||||
|
||||
from models.generated.commands import *;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
__all__ = [
|
||||
'command_from_json',
|
||||
'interpret_command',
|
||||
];
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# METHODS Convert to appropriate command type
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def command_from_json(command_json: str) -> Command:
|
||||
try:
|
||||
instructions = json.loads(command_json);
|
||||
except:
|
||||
raise Exception('Invalid json!');
|
||||
try:
|
||||
command = Command(**instructions);
|
||||
except:
|
||||
raise Exception('Invalid instruction format - consult schema!');
|
||||
command = interpret_command(command);
|
||||
return command;
|
||||
|
||||
def interpret_command(command: Command) -> Command:
|
||||
match command.name:
|
||||
case EnumAlgorithmNames.tarjan:
|
||||
return CommandTarjan(**command.dict());
|
||||
case EnumAlgorithmNames.tsp:
|
||||
return CommandTsp(**command.dict());
|
||||
case EnumAlgorithmNames.hirschberg:
|
||||
return CommandHirschberg(**command.dict());
|
||||
raise command;
|
||||
@@ -6,7 +6,7 @@
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from src.thirdparty.types import *;
|
||||
from src.setup.config import *;
|
||||
from src.setup import config;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
@@ -23,6 +23,6 @@ __all__ = [
|
||||
class Directions(Enum):
|
||||
UNSET = -1;
|
||||
# Prioritäten hier setzen
|
||||
DIAGONAL = OPTIONS.hirschberg.move_priorities.diagonal;
|
||||
HORIZONTAL = OPTIONS.hirschberg.move_priorities.horizontal;
|
||||
VERTICAL = OPTIONS.hirschberg.move_priorities.vertical;
|
||||
DIAGONAL = config.OPTIONS.hirschberg.move_priorities.diagonal;
|
||||
HORIZONTAL = config.OPTIONS.hirschberg.move_priorities.horizontal;
|
||||
VERTICAL = config.OPTIONS.hirschberg.move_priorities.vertical;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
from src.thirdparty.types import *;
|
||||
from src.setup.config import *;
|
||||
from src.setup import config;
|
||||
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
# EXPORTS
|
||||
@@ -22,7 +22,7 @@ __all__ = [
|
||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
def gap_penalty(x: str):
|
||||
return OPTIONS.hirschberg.penality_gap;
|
||||
return config.OPTIONS.hirschberg.penality_gap;
|
||||
|
||||
def missmatch_penalty(x: str, y: str):
|
||||
return 0 if x == y else OPTIONS.hirschberg.penality_mismatch;
|
||||
return 0 if x == y else config.OPTIONS.hirschberg.penality_mismatch;
|
||||
|
||||
Reference in New Issue
Block a user