Skip to content

console.py

Leon edited this page Nov 11, 2024 · 2 revisions

The Console class is part of the LILY-QML project, developed by Leon Kaiser, and serves as a command-line interface for interacting with the LLY-DML module. This class provides a user-friendly, text-based interface to access and manage various functionalities, such as training models, testing models, and generating reports. The Console class is highly interactive, guiding users through a structured menu system and providing distinct options for each primary functionality of the LLY-DML system.

Overview

Class: Console

The Console class presents a command-line interface with multiple menus, allowing the user to:

  1. Train models with different optimizers.
  2. Test models and log results.
  3. Generate detailed reports on training and testing.

Attributes

  • banner : str

    • A formatted ASCII banner displaying the LILY-QML branding.
  • info : str

    • A formatted informational string containing details about the LLY-DML version and project contact information.

Methods

display_main_menu()

Displays the main menu with options for training, testing, report generation, and program exit. The method clears the terminal screen and outputs the ASCII banner and project information followed by menu options.

display_training_menu()

Clears the terminal and displays options specific to training models. Options include:

  • Training all optimizers.
  • Training specific optimizers.
  • Exiting to return to the main menu.

display_test_menu()

Clears the terminal and displays options for testing models. Options include:

  • Starting the testing process and writing results to test_data.json.
  • Exiting to return to the main menu.

display_report_menu()

Clears the terminal and displays options for generating reports. Options include:

  • Creating a training report.
  • Creating a test report.
  • Creating a combined report for training and testing.
  • Exiting to return to the main menu.

get_user_choice()

Prompts the user for input in a visually distinct command line styled prompt (customized with ASCII color codes). This method captures the user’s menu choice for further processing.

run()

The main method that initiates and maintains the command-line interface loop. It continuously displays the main menu and processes user choices. Depending on the selected option, it redirects to the appropriate submenu for training, testing, or reporting. The method terminates when the user selects the exit option.

Example Usage

The Console class provides a clean, color-coded terminal interface where users interact through simple numeric inputs to navigate through various menus and execute tasks.

if __name__ == "__main__":
    console = Console()
    action = console.run()
    print(f"Selected Action: {action}")

Color Codes

This class uses ANSI escape codes to provide color-coded text outputs:

  • Blue (\033[1;34m): Command prompt display.
  • Green (\033[1;32m): Information display (project version and contact).
  • Yellow (\033[1;33m): Menu titles and dividers.
  • Cyan (\033[1;36m): Menu item numbers.
  • White (\033[0;37m): Menu item descriptions.

Sample Display

The interface uses banners and color codes for a professional and clear command-line presentation, enhancing readability and user experience.

 ____   __  __   _
|  _ \ |  \/  | | |
| | | || |\/| | | |
| |_| || |  | | | |___
|____/ |_|  |_| |_____|

LLY-DML - Part of the LILY Project - Version 1.6 Beta - info@lilyqml.de - lilyqml.de

Choose an option:
1. Training - Train a new Model
2. Test - Test an existing Model
3. Create Report - Create a Report
4. Exit