Types#

A primary objective of our framework is to simplify its usage for those who wish to employ it without delving into development. We aim to offer them a straightforward and effortless setup process, minimizing the complexities and initializations associated with numerous classes. This approach reduces potential bugs and allows users to focus on their primary task: developing an application using our framework. To ensure uniformity throughout the framework and to effectively manage new Tasks while avoiding incorrect class initializations, we have introduced Types identifiers. These identifiers, at a high level, determine the specific type of task required. Consequently, CHA users are relieved from the intricate details of initializing Task objects, integrating them into the CHA, and handling setups.

Tasks Types#

This enumeration class defines different types of task. This ensures consistency in case the task developer decides to change the name of their task, the end user need not to change their code cause they use the keys. It inherits from the str class and the Enum class in Python’s enum module. Each value in this enumeration represents a specific type of task. The key naming convention should be all uppercase with underscore, and the value naming convention should be underscore_case: NAME_OF_TASK = this_is_a_sample_task_name

from enum import Enum


class TaskType(str, Enum):
    SERPAPI = "serpapi"
    EXTRACT_TEXT = "extract_text"
    AFFECT_SLEEP_GET = "affect_sleep_get"
    AFFECT_ACTIVITY_GET = "affect_activity_get"
    AFFECT_SLEEP_ANALYSIS = "affect_sleep_analysis"
    AFFECT_ACTIVITY_ANALYSIS = "affect_activity_analysis"
    GOOGLE_TRANSLATE = "google_translate"
    ASK_USER = "ask_user"
    TEST_FILE = "test_file"
    RUN_PYTHON_CODE = "run_python_code"
    PPG_GET = "affect_ppg_get"
    PPG_ANALYSIS = "affect_ppg_analysis"
    STRESS_ANALYSIS = "affect_stress_analysis"
    QUERY_NUTRITIONIX = "query_nutritionix"
    CALCULATE_FOOD_RISK_FACTOR = "calculate_food_risk_factor"
    GOOGLE_SEARCH = "google_search"

Types#

This dictionary is used to map each TaskType value to its corresponding Task class. It allows for easy retrieval of the appropriate class based on the planner type.

from typing import Dict
from typing import Type

from openCHA.tasks import AskUser
from openCHA.tasks import BaseTask
from openCHA.tasks import ExtractText
from openCHA.tasks import GoogleSearch
from openCHA.tasks import GoogleTranslate
from openCHA.tasks import RunPythonCode
from openCHA.tasks import SerpAPI
from openCHA.tasks import TaskType
from openCHA.tasks import TestFile
from openCHA.tasks.affect import ActivityAnalysis
from openCHA.tasks.affect import ActivityGet
from openCHA.tasks.affect import PPGAnalysis
from openCHA.tasks.affect import PPGGet
from openCHA.tasks.affect import SleepAnalysis
from openCHA.tasks.affect import SleepGet
from openCHA.tasks.affect import StressAnalysis
from openCHA.tasks.nutritionix import (
    CalculateFoodRiskFactor,
)
from openCHA.tasks.nutritionix import QueryNutritionix


TASK_TO_CLASS: Dict[TaskType, Type[BaseTask]] = {
    TaskType.SERPAPI: SerpAPI,
    TaskType.EXTRACT_TEXT: ExtractText,
    TaskType.AFFECT_SLEEP_GET: SleepGet,
    TaskType.AFFECT_ACTIVITY_GET: ActivityGet,
    TaskType.AFFECT_SLEEP_ANALYSIS: SleepAnalysis,
    TaskType.AFFECT_ACTIVITY_ANALYSIS: ActivityAnalysis,
    TaskType.GOOGLE_TRANSLATE: GoogleTranslate,
    TaskType.ASK_USER: AskUser,
    TaskType.TEST_FILE: TestFile,
    TaskType.RUN_PYTHON_CODE: RunPythonCode,
    TaskType.PPG_GET: PPGGet,
    TaskType.PPG_ANALYSIS: PPGAnalysis,
    TaskType.STRESS_ANALYSIS: StressAnalysis,
    TaskType.QUERY_NUTRITIONIX: QueryNutritionix,
    TaskType.CALCULATE_FOOD_RISK_FACTOR: CalculateFoodRiskFactor,
    TaskType.GOOGLE_SEARCH: GoogleSearch,
}