Skip to content

bala-actuary/Indicator-Checker-for-Prophet

Repository files navigation

Indicator Expression Checker for Prophet

Overview

This project provides a tool to check which Prophet products qualify for a given Indicator Expression based on a set of predefined indicators. It uses a CSV file as the data source for product-indicator mappings (you can create from running Schedule in Prophet) and leverages Python with Pandas for data manipulation and expression evaluation. A Jupyter Notebook interface provides a user-friendly way to input expressions and view results.

The system uses a caching mechanism (.pkl file) to speed up data loading on subsequent runs.

Features

  • Reads product-indicator data from a CSV file.
  • Supports complex logical expressions involving indicators and operators (AND, OR, NOT).
  • Parentheses can be used for grouping in expressions.
  • Uses a caching system (pickle file) to improve performance on repeated runs.
  • Provides a list of both "Qualified" and "Non-Qualified" products for a given expression.
  • User-friendly Jupyter Notebook interface with:
    • Interactive text input for expressions.
    • Button to clear the cache and reload data from CSV.

Project Structure

your_project_root_directory/
├── indicator_logic.py # Core Python module with data loading and expression evaluation logic
├── Indicator_Checker.ipynb # Jupyter Notebook for user interaction
├── products_indicators.csv # CSV data file mapping products to indicators
├── cached_product_data.pkl # Auto-generated cache file (do not edit manually)
└── README.md # This file

Prerequisites

  • Python 3.x
  • The following Python libraries:
    • pandas
    • ipywidgets (for the Jupyter Notebook interactive elements)

Installation / Setup

  1. Clone or download the project files into a local directory.

  2. Ensure Python 3.x is installed. It's recommended to use a virtual environment (e.g., Anaconda/conda environment).

    # Example using conda to create and activate an environment
    conda create -n indicator_env python=3.9
    conda activate indicator_env
  3. Install required Python libraries:

    pip install pandas ipywidgets
  4. For Jupyter Notebook ipywidgets: If you haven't used ipywidgets before, you might need to enable the notebook extension:

    jupyter nbextension enable --py widgetsnbextension

    If using JupyterLab, you might also need:

    jupyter labextension install @jupyter-widgets/jupyterlab-manager

    Restart your Jupyter server/kernel after installation if necessary.

  5. Prepare your data file:

    • Ensure your product-indicator data is in a CSV file named products_indicators.csv and placed in the project's root directory.
    • CSV Format:
      • The first column must be the product identifier (e.g., named Product).
      • Subsequent columns should be indicator names (e.g., Ind_1, Ind_2).
      • Use an asterisk (*) in a cell to signify that a product possesses an indicator.
      • Leave cells blank if a product does not possess an indicator.
      • Example:
        Product,Ind_1,Ind_2,Ind_3
        Prod_A,*,*,
        Prod_B,,*,*
        Prod_C,*,*,*

How to Use

  1. Launch Jupyter Notebook or JupyterLab from your activated environment in the project's root directory:

    jupyter notebook
    # OR
    jupyter lab
  2. Open the Indicator_Checker.ipynb notebook.

  3. Run the notebook cells sequentially:

    • Cell 1 (Imports): Run to import necessary libraries and the custom indicator_logic module.
    • Cell 2 (Data Load & Cache Management):
      • Run this cell to load the data. On the first run, it will load from products_indicators.csv and create cached_product_data.pkl.
      • On subsequent runs, it will use the cache by default.
      • This cell also displays a "Delete Cache & Reload Data" button. Click this button if you have updated products_indicators.csv and want to force a reload from the CSV, which will also rebuild the cache.
    • Cell 3 (Expression Input):
      • Run this cell. An interactive text box labeled "Expression:" will appear in the output.
      • Type your desired indicator expression into this text box (e.g., Ind_1 AND (Ind_5 OR NOT Ind_7)).
    • Cell 4 (Evaluate & Display Results):
      • Run this cell to evaluate the expression entered in Cell 3.
      • The output will show a list of "Qualified Products" and "Non-Qualified Products."
  4. To check a new expression:

    • Modify the text in the input box (displayed by Cell 3).
    • Re-run Cell 4.

Indicator Expression Syntax

  • Indicator Names: Use the exact names as they appear in the header of your products_indicators.csv file (e.g., Ind_1, Ind_X).
  • Logical Operators:
    • AND (or and)
    • OR (or or)
    • NOT (or not) (Operators are case-insensitive in the input but are converted to lowercase for processing).
  • Parentheses: Use ( and ) for grouping to control the order of operations.
  • Examples:
    • Ind_1 AND Ind_5
    • Ind_1 OR Ind_2
    • NOT Ind_3
    • (Ind_1 AND Ind_2) OR Ind_7
    • Ind_1 AND NOT (Ind_5 OR Ind_6)

Caching

  • The script indicator_logic.py automatically creates a cache file named cached_product_data.pkl in the project directory after successfully loading and processing products_indicators.csv.
  • On subsequent runs, the system will use this cache file by default to speed up data loading.
  • To force a reload from products_indicators.csv (e.g., if the CSV has been updated):
    1. Click the "Delete Cache & Reload Data" button in the Jupyter Notebook (output of Cell 2).
    2. Alternatively, manually delete the cached_product_data.pkl file from the project directory and then re-run the data loading cell in the notebook.

Troubleshooting

  • "ModuleNotFoundError": Ensure you have activated the correct Python environment where pandas and ipywidgets are installed.
  • "FileNotFoundError" for products_indicators.csv: Make sure the CSV file is named exactly products_indicators.csv and is in the same directory as indicator_logic.py and Indicator_Checker.ipynb.
  • Widgets not appearing/working: Ensure ipywidgets is correctly installed and the notebook extension is enabled. Try restarting the Jupyter kernel and server.
  • Incorrect Results:
    • Verify that your products_indicators.csv data is accurate and that * correctly represents True and blanks represent False.
    • Double-check your indicator expression for correct syntax and logic.
    • Use the "Delete Cache & Reload Data" button to ensure you're not working with stale cached data if you've recently modified the CSV.
  • "SyntaxError" or "UndefinedVariableError" during expression evaluation:
    • This usually means there's an issue with your expression string (e.g., mismatched parentheses, invalid operator) or an indicator name used in the expression does not exist as a column in your data. The error message from the script should provide more details.

Future Enhancements (Ideas)

  • Configuration file for filenames (CSV_FILENAME, CACHE_FILENAME).
  • More advanced data validation for the input CSV.
  • Unit tests for indicator_logic.py.
  • Integration of Python's logging module for more robust logging.

About

Indicaor Checker tool for Prophet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors