-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Class: Start
The Start class is responsible for loading essential references and verifying that all necessary files and logs are correctly present at the start of the program. It coordinates the initialization process by conducting various checks and responds accordingly if any issues are detected. All important events and errors are documented in a log file.
Attributes
-
reader(Reader):An instance of the
Readerclass, used for file and log management. -
train_json_exists(bool):A flag indicating whether the
train.jsonfile exists after the initial check. Set toFalseupon instantiation of the class.
Methods
1. __init__(self, reader)
Description:
Initializes the Start class and sets the train_json_exists flag to False.
Parameters:
reader(Reader): An instance of theReaderclass used for file and log management.
Functionalities:
- Assigns the
readerinstance to an attribute for use in other methods. - Initializes the
train_json_existsflag toFalse.
2. run(self)
Description:
The run() method is the main execution method that coordinates the initialization process. It performs the following steps:
-
File Check:
- Action: Calls the
fileCheck()method from theReaderclass to verify the presence of essential files and directories. - Log Message:
"Initiating file check..." - Result Handling:
-
Error Code:
'var' Folder is MissingError Code: 1001 - 'var' folder is missing. Log Message: "ERROR: 'var' folder is missing. Terminating program."- Action: Logs the error and terminates the program with the corresponding error code.
-
Error Code:
'data.json' MissingError Code: 1002 - 'data.json' file is missing in 'var' folder. Log Message: "ERROR: 'data.json' file is missing. Terminating program."- Action: Logs the error and terminates the program with the corresponding error code.
-
Error Code:
'config.json' MissingError Code: 1003 - 'config.json' file is missing in 'var' folder. Log Message: "ERROR: 'config.json' file is missing. Terminating program."- Action: Logs the error and terminates the program with the corresponding error code.
-
Success Code: All Files Present,
'train.json'ExistsSuccess Code: 2001 - All files are present. 'train.json' exists. Log Message: "SUCCESS: All files are present. 'train.json' exists."-
Action: Sets the
train_json_existsflag toTrueand logs a corresponding message:Log Message: "'train.json' found. Proceeding with initialization."
-
-
Success Code: All Files Present,
'train.json'MissingSuccess Code: 2002 - All files are present. 'train.json' is missing. Log Message: "SUCCESS: All files are present. 'train.json' is missing."-
Action: Leaves the
train_json_existsflag asFalseand logs a corresponding message. The program is not terminated iftrain.jsonis missing.Log Message: "'train.json' missing. Proceeding without training file."
-
-
Unexpected Error Code:
Error Code: 100105 - Unexpected error during file check. Log Message: "ERROR: Unexpected error during file check. Terminating program."- Action: Logs the error and terminates the program with the corresponding error code.
-
- Action: Calls the
-
Logfile Check:
- Action: Calls the
checkLog()method from theReaderclass to ensure an up-to-date log file exists. - Log Message:
"Checking for an existing log file..." - Result Handling:
-
If the log file is valid and up-to-date:
Log Message: "Log file is valid and up-to-date." -
If the log file cannot be created or accessed:
Error Code: 100106 - Failed to create or access log file. Log Message: "ERROR: Failed to create or access log file. Terminating program."- Action: Logs the error and terminates the program with the corresponding error code.
-
- Action: Calls the
-
Data Consistency Check:
- Action: Calls the
dataConsistency()method from theReaderclass to ensure thedata.jsonfile is consistent. - Log Message:
"Verifying data consistency for 'data.json'..." - Result Handling:
-
If
data.jsonis inconsistent:Error Code: 100104 - 'data.json' file is inconsistent. Log Message: "ERROR: 'data.json' file is inconsistent. Terminating program."- Action: Logs the error and terminates the program with the corresponding error code.
-
If
data.jsonis consistent:Success Code: 200103 - 'data.json' is consistent. Proceeding with execution. Log Message: "'data.json' is consistent. Proceeding with execution."- Action: Logs the successful consistency check and allows the program to continue.
-
- Action: Calls the
Process Overview
-
Initialization:
- A
Readerinstance is created. - A
Startinstance is created, which receives theReaderinstance.
- A
-
Execution (
Start.run()):-
File Check:
- Calls
fileCheck()to ensure all necessary files and directories are present. - Depending on the outcome, appropriate error or success codes are logged, and the program may be terminated.
- Calls
-
Logfile Check:
- Calls
checkLog()to verify the existence and currency of the log file. - If there are issues, the program terminates with the corresponding error.
- Calls
-
Data Consistency Check:
- Calls
dataConsistency()to check the consistency of thedata.jsonfile. - If inconsistent, the program terminates with the corresponding error.
- If successful, the program continues.
- Calls
-
-
Further Initialization:
- After successfully running
run(), the program can proceed with additional initialization, such as loading and processing data.
- After successfully running