Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 8a08c39

Browse files
committed
Added exception cases and implemented the controller
1 parent 6dda69d commit 8a08c39

File tree

7 files changed

+70
-11
lines changed

7 files changed

+70
-11
lines changed

DesignDocument/DesignDocument.tex

+5-5
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ \subsubsection{User Input Activity Diagram}
192192
After the user enters his input into the \gls{CLI}, the CommandParser parses this input to a command.
193193
If the command equals quit, the program will exit.
194194
If not the command will be validated to contain enough information to start the desired module.
195-
If it is not valid, an error message will be printed and the user can enter a new input.
195+
If it is not valid, an exception message will be printed and the user can enter a new input.
196196
If the command is valid, the module will be started.
197197
Therefore the module computes his specific task in iterations.
198198
After each iteration it prints the current progress to the user.
@@ -537,7 +537,7 @@ \subsubsection{Class LabelingModule}
537537
The default paths are specified in a configuration file(see the training module for further details).
538538
If the User specifes his own paths they have to be vaild.
539539
Valid in this case means that the path points to a \gls{HDF5} file with the correct formatation.
540-
If this is not the case the program will print an error message to the command line so that the user can specify a correct path.
540+
If this is not the case the program will print an exception message to the command line so that the user can specify a correct path.
541541
\subsubsection{Class Solver}
542542
An Solver in our sense is an interative Solver which is able to to solve a linear system Ax=b for x, where A is a (in our case sparse) matrix of size nxn, x is a vector of size 1xn and b is vector of size 1xn(n$\in$N).
543543
The matrix A in our case will be the Matrix the method execute(matrix,preconditioner) will receive, the vector b will be a random vector with values between 0 and 1.
@@ -683,7 +683,7 @@ \subsubsection{Class Configuration File}
683683
\end{enumerate}
684684
The loading path of the set of matrices is the path in which the matrices that are used for the training and testing are stored.
685685
The training module only supports one \gls{HDF5} file.
686-
If the path is invalid, the labling module will throw an error that will be printed to the user.
686+
If the path is invalid, the labling module will throw an exception that will be printed to the user.
687687
For the training and testing of a new neural network being effective there should be at least 500 matrices in the \gls{HDF5} file.
688688
Otherwise the accuracy of the \gls{neural network} will be so low that it can not be used for classification.
689689
If there is no path specified in the start method, the training module will use a default path.
@@ -700,7 +700,7 @@ \subsubsection{Class Configuration File}
700700
This could be the case if the user interrupts the training process at a certain time and wants to to repeat the training later.
701701
Other use cases are of course possible too.
702702
The \gls{neural network} has to be a model of the Keras framework.
703-
If the path is any other file the training module will print an error so that the user can specify a valid path.
703+
If the path is any other file the training module will print an exception so that the user can specify a valid path.
704704
If this path is not specified the training module will create a new \gls{neural network} (with the model definition and hyperparamters of the next category) and train with this one. \newline
705705

706706
The model definition and hyperparameters are used to determine which \gls{neural network} will be trained and tested.
@@ -761,7 +761,7 @@ \subsection{Activity Diagarams}
761761
The configuration file will determine from which path the labeled matrices will be loaded.
762762
If there is no path specified in the method start, the default path will be used(see the class description of the configuration file).
763763
The labeled matrices will be loaded in one \gls{HDF5} file.
764-
If the path links to any other file, the class TrainingModule will print an error to the command line so that the user can specify a valid path. \newline
764+
If the path links to any other file, the class TrainingModule will print an exception to the command line so that the user can specify a valid path. \newline
765765

766766
Then the values of the matrix will be normalized.
767767
This means that every entry will be converted to a value between 0 and 1, such that relative distances are kept.

modules/controller/commands/command.py

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44

55
## Interface for the module specific commands
6+
from modules.view.output_service import OutputService
7+
8+
69
class Command:
710

811
arguments: List[Key]

modules/controller/controller.py

+39-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,45 @@
1-
## Main entry point for programm execution
1+
from modules.controller.command_parser import CommandParser
2+
from modules.controller.commands.command import Command
3+
from modules.exception.excpetions import IllegalArgumentException
4+
from modules.view.cli_output_service import CLIOutputService
5+
from modules.view.command_line_interface import CommandLineInterface
6+
7+
8+
## Main entry point for program execution
29
#
310
# it creates the view and executes the models
11+
from modules.view.output_service import OutputService
12+
13+
414
class Controller:
15+
16+
view: CommandLineInterface
17+
output_service: OutputService
18+
519
def __init__(self):
6-
pass
20+
finished: bool = False
21+
view = CommandLineInterface()
22+
output_service = CLIOutputService(view)
23+
self._register_output_service()
24+
while not finished:
25+
command: Command = self._get_command()
26+
if isinstance(command, Command):
27+
finished = True
28+
else:
29+
command.execute()
30+
31+
output_service.print_line("Finished")
32+
33+
def _get_command(self) -> Command:
34+
input_string: str = self.view.read_input("Which module do you want to execute?")
35+
command: Command
36+
try:
37+
command = CommandParser.parse_input(input_string)
38+
except IllegalArgumentException as e:
39+
self.output_service.print_error(str(e))
40+
return command
741

8-
def _get_command(self):
42+
43+
def _register_output_service(self):
944
pass
45+

modules/exception/__init__.py

Whitespace-only changes.

modules/exception/excpetions.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class IllegalArgumentException(Exception):
2+
pass
3+
4+
5+
class InvalidConfigException(Exception):
6+
pass
7+
8+
9+
class IOException(Exception):
10+
pass
11+
12+
13+
class InvalidOSException(Exception):
14+
pass

modules/view/cli_output_service.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from modules.shared.matrix import Matrix
2+
from modules.view.command_line_interface import CommandLineInterface
23
from modules.view.observable import Observable
34
from modules.view.output_service import OutputService
45
from modules.view.subscriber import Subscriber
@@ -7,6 +8,11 @@
78
## This class communicates with the command line interface
89
class CLIOutputService(OutputService, Subscriber):
910

11+
view: CommandLineInterface
12+
13+
def __init__(self, view: CommandLineInterface):
14+
self.view = view
15+
1016
def print_line(self, line: str) -> None:
1117
super().print_line(line)
1218

@@ -20,4 +26,4 @@ def print_matrix(self, matrix: Matrix):
2026
super().print_matrix(matrix)
2127

2228
def update(self, value: str) -> None:
23-
super().update(value)
29+
super().update(value)

modules/view/output_service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def print_line(self, line: str) -> None:
1818
def print_overriding(self, message: str, observable: Observable):
1919
pass
2020

21-
## Prints an error to the view
21+
## Prints an exception to the view
2222
#
23-
# @param error the string with the error message
23+
# @param exception the string with the exception message
2424
def print_error(self, error: str) -> None:
2525
pass
2626

0 commit comments

Comments
 (0)