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.
- 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.
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
- Python 3.x
- The following Python libraries:
pandasipywidgets(for the Jupyter Notebook interactive elements)
-
Clone or download the project files into a local directory.
-
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 -
Install required Python libraries:
pip install pandas ipywidgets
-
For Jupyter Notebook
ipywidgets: If you haven't usedipywidgetsbefore, you might need to enable the notebook extension:jupyter nbextension enable --py widgetsnbextensionIf using JupyterLab, you might also need:
jupyter labextension install @jupyter-widgets/jupyterlab-manager
Restart your Jupyter server/kernel after installation if necessary.
-
Prepare your data file:
- Ensure your product-indicator data is in a CSV file named
products_indicators.csvand 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,*,*,*
- The first column must be the product identifier (e.g., named
- Ensure your product-indicator data is in a CSV file named
-
Launch Jupyter Notebook or JupyterLab from your activated environment in the project's root directory:
jupyter notebook # OR jupyter lab -
Open the
Indicator_Checker.ipynbnotebook. -
Run the notebook cells sequentially:
- Cell 1 (Imports): Run to import necessary libraries and the custom
indicator_logicmodule. - Cell 2 (Data Load & Cache Management):
- Run this cell to load the data. On the first run, it will load from
products_indicators.csvand createcached_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.csvand want to force a reload from the CSV, which will also rebuild the cache.
- Run this cell to load the data. On the first run, it will load from
- 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."
- Cell 1 (Imports): Run to import necessary libraries and the custom
-
To check a new expression:
- Modify the text in the input box (displayed by Cell 3).
- Re-run Cell 4.
- Indicator Names: Use the exact names as they appear in the header of your
products_indicators.csvfile (e.g.,Ind_1,Ind_X). - Logical Operators:
AND(orand)OR(oror)NOT(ornot) (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_5Ind_1 OR Ind_2NOT Ind_3(Ind_1 AND Ind_2) OR Ind_7Ind_1 AND NOT (Ind_5 OR Ind_6)
- The script
indicator_logic.pyautomatically creates a cache file namedcached_product_data.pklin the project directory after successfully loading and processingproducts_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):- Click the "Delete Cache & Reload Data" button in the Jupyter Notebook (output of Cell 2).
- Alternatively, manually delete the
cached_product_data.pklfile from the project directory and then re-run the data loading cell in the notebook.
- "ModuleNotFoundError": Ensure you have activated the correct Python environment where
pandasandipywidgetsare installed. - "FileNotFoundError" for
products_indicators.csv: Make sure the CSV file is named exactlyproducts_indicators.csvand is in the same directory asindicator_logic.pyandIndicator_Checker.ipynb. - Widgets not appearing/working: Ensure
ipywidgetsis correctly installed and the notebook extension is enabled. Try restarting the Jupyter kernel and server. - Incorrect Results:
- Verify that your
products_indicators.csvdata is accurate and that*correctly representsTrueand blanks representFalse. - 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.
- Verify that your
- "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.
- 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
loggingmodule for more robust logging.