diff --git a/emp-churn-step-by-step/requirements.txt b/emp-churn-step-by-step/requirements.txt index 6d6f2a1..3719054 100644 --- a/emp-churn-step-by-step/requirements.txt +++ b/emp-churn-step-by-step/requirements.txt @@ -1 +1,4 @@ -h2o-wave==0.24.0 \ No newline at end of file +h2o-wave==1.5.1 +altair==5.4.1 +pandas==2.2.2 +numpy==2.1.1 \ No newline at end of file diff --git a/emp-churn-step-by-step/src/app1.py b/emp-churn-step-by-step/src/app1.py index 4d384f3..c036212 100644 --- a/emp-churn-step-by-step/src/app1.py +++ b/emp-churn-step-by-step/src/app1.py @@ -1,7 +1,7 @@ # Step 1 # Setting Up Layout:Header, main page and footer # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data @app('/') @@ -12,7 +12,7 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() diff --git a/emp-churn-step-by-step/src/app10.py b/emp-churn-step-by-step/src/app10.py index c438681..fa86428 100644 --- a/emp-churn-step-by-step/src/app10.py +++ b/emp-churn-step-by-step/src/app10.py @@ -2,7 +2,7 @@ # Refresh only relevant components. Stop re-creating cards - just refresh attributes # Set H2O_WAVE_NO_LOG=1 to avoid printing server (waved) messages # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, data import altair import numpy as np @@ -10,7 +10,7 @@ from typing import List import logging -from os import environ +import os import traceback log = logging.getLogger("app") @@ -28,7 +28,7 @@ def setup_logger(): ) ch.setFormatter(formatter) log.addHandler(ch) - log.setLevel(environ.get("LOG_LEVEL", "INFO").upper()) + log.setLevel(os.environ.get("LOG_LEVEL", "INFO").upper()) def on_startup(): @@ -95,11 +95,13 @@ async def serve(q: Q): async def init_app(q: Q) -> None: # Read and load data into memory - log.info("==Start init_app Function ==") - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") - log.info("==Complete init_app Function ==") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app11.py b/emp-churn-step-by-step/src/app11.py index 9ae227b..5220e28 100644 --- a/emp-churn-step-by-step/src/app11.py +++ b/emp-churn-step-by-step/src/app11.py @@ -1,7 +1,7 @@ # Step 11 # Add logic to read data from Delta Lake tables # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, data import altair import numpy as np @@ -10,7 +10,7 @@ import os import logging -from os import environ +import os import traceback log = logging.getLogger("app") @@ -28,7 +28,7 @@ def setup_logger(): ) ch.setFormatter(formatter) log.addHandler(ch) - log.setLevel(environ.get("LOG_LEVEL", "INFO").upper()) + log.setLevel(os.environ.get("LOG_LEVEL", "INFO").upper()) def on_startup(): @@ -94,10 +94,13 @@ async def serve(q: Q): async def init_app(q: Q) -> None: # Read and load data into memory - log.info("==Start init_app Function ==") - q.app.predictions, q.app.shapley = load_data_from_db() + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - log.info("==Complete init_app Function ==") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app12.py b/emp-churn-step-by-step/src/app12.py index 3f35149..f56874b 100644 --- a/emp-churn-step-by-step/src/app12.py +++ b/emp-churn-step-by-step/src/app12.py @@ -2,7 +2,7 @@ # Employee table pagination - handle large number of records in table # Set H2O_WAVE_NO_LOG=1 to avoid printing server (waved) messages # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, data import altair import numpy as np @@ -10,7 +10,7 @@ from typing import List import logging -from os import environ +import os import traceback log = logging.getLogger("app") @@ -29,7 +29,7 @@ def setup_logger(): ) ch.setFormatter(formatter) log.addHandler(ch) - log.setLevel(environ.get("LOG_LEVEL", "INFO").upper()) + log.setLevel(os.environ.get("LOG_LEVEL", "INFO").upper()) def on_startup(): @@ -102,11 +102,13 @@ async def serve(q: Q): async def init_app(q: Q) -> None: # Read and load data into memory - log.info("==Start init_app Function ==") - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") - log.info("==Complete init_app Function ==") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app13.py b/emp-churn-step-by-step/src/app13.py index 217b25e..f4773aa 100644 --- a/emp-churn-step-by-step/src/app13.py +++ b/emp-churn-step-by-step/src/app13.py @@ -2,7 +2,7 @@ # Add tabs and tabs switching # Set H2O_WAVE_NO_LOG=1 to avoid printing server (waved) messages # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, data from h2o_wave.core import expando_to_dict from typing import Optional, List @@ -11,7 +11,7 @@ import pandas as pd import logging -from os import environ +import os import traceback log = logging.getLogger("app") @@ -31,7 +31,7 @@ def setup_logger(): ) ch.setFormatter(formatter) log.addHandler(ch) - log.setLevel(environ.get("LOG_LEVEL", "INFO").upper()) + log.setLevel(os.environ.get("LOG_LEVEL", "INFO").upper()) def on_startup(): @@ -129,11 +129,13 @@ async def serve(q: Q): async def init_app(q: Q) -> None: # Read and load data into memory - log.info("==Start init_app Function ==") - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") - log.info("==Complete init_app Function ==") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app2.py b/emp-churn-step-by-step/src/app2.py index f7a935c..f089065 100644 --- a/emp-churn-step-by-step/src/app2.py +++ b/emp-churn-step-by-step/src/app2.py @@ -1,7 +1,7 @@ # Step 2 # Changing Cards descriptions # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data @app('/') @@ -12,7 +12,7 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() diff --git a/emp-churn-step-by-step/src/app3.py b/emp-churn-step-by-step/src/app3.py index f044a9c..7221967 100644 --- a/emp-churn-step-by-step/src/app3.py +++ b/emp-churn-step-by-step/src/app3.py @@ -1,9 +1,10 @@ # Step 3 # Read data and add plot # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data import pandas as pd +import os @app('/') @@ -19,13 +20,16 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() async def init_app(q: Q) -> None: - # Read Shapley values - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") + # Read and load data into memory + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app4.py b/emp-churn-step-by-step/src/app4.py index ff3f926..11abd65 100644 --- a/emp-churn-step-by-step/src/app4.py +++ b/emp-churn-step-by-step/src/app4.py @@ -1,10 +1,11 @@ # Step 4 # Add Churn Prediction Chart # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data import altair import pandas as pd +import os @app('/') @@ -20,15 +21,19 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() async def init_app(q: Q) -> None: # Read and load data into memory - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app5.py b/emp-churn-step-by-step/src/app5.py index 0bf1c31..e381ddd 100644 --- a/emp-churn-step-by-step/src/app5.py +++ b/emp-churn-step-by-step/src/app5.py @@ -1,10 +1,11 @@ # Step 5 # Add Threshold Slider and description card above # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data import altair import pandas as pd +import os @app('/') @@ -20,15 +21,19 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() async def init_app(q: Q) -> None: # Read and load data into memory - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app6.py b/emp-churn-step-by-step/src/app6.py index 9229fe1..bd09d40 100644 --- a/emp-churn-step-by-step/src/app6.py +++ b/emp-churn-step-by-step/src/app6.py @@ -1,10 +1,11 @@ # Step 6 # Add Stats Card below Threshold Slider # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data import altair import pandas as pd +import os @app('/') @@ -20,15 +21,19 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() async def init_app(q: Q) -> None: # Read and load data into memory - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app7.py b/emp-churn-step-by-step/src/app7.py index 8e439b4..5804243 100644 --- a/emp-churn-step-by-step/src/app7.py +++ b/emp-churn-step-by-step/src/app7.py @@ -1,11 +1,12 @@ # Step 7 # Add Employee details table below Stats Card # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, run_on, data import altair import numpy as np import pandas as pd +import os @app('/') @@ -21,15 +22,19 @@ async def serve(q: Q): q.client.initialized = True # Other browser interactions - await handle_on(q) + await run_on(q) await q.page.save() async def init_app(q: Q) -> None: # Read and load data into memory - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app8.py b/emp-churn-step-by-step/src/app8.py index 7ff0281..fbaf72b 100644 --- a/emp-churn-step-by-step/src/app8.py +++ b/emp-churn-step-by-step/src/app8.py @@ -1,11 +1,12 @@ # Step 8 # Add Shapley contributions below Employee table # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, data import altair import numpy as np import pandas as pd +import os @app('/') @@ -27,9 +28,13 @@ async def serve(q: Q): async def init_app(q: Q) -> None: # Read and load data into memory - q.app.predictions = pd.read_csv("./src/static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./src/static/shapley_values.csv") + q.app.shapley = pd.read_csv(shapley_file) async def init(q: Q) -> None: diff --git a/emp-churn-step-by-step/src/app9.py b/emp-churn-step-by-step/src/app9.py index a4c5d71..1237234 100644 --- a/emp-churn-step-by-step/src/app9.py +++ b/emp-churn-step-by-step/src/app9.py @@ -2,14 +2,14 @@ # Add Logging and Error Handling. # Set H2O_WAVE_NO_LOG=1 to avoid printing server (waved) messages # --- -from h2o_wave import main, app, Q, ui, on, handle_on, data +from h2o_wave import main, app, Q, ui, on, data import altair import numpy as np import pandas as pd import logging -from os import environ +import os import traceback log = logging.getLogger("app") @@ -27,7 +27,7 @@ def setup_logger(): ) ch.setFormatter(formatter) log.addHandler(ch) - log.setLevel(environ.get("LOG_LEVEL", "INFO").upper()) + log.setLevel(os.environ.get("LOG_LEVEL", "INFO").upper()) def on_startup(): @@ -74,9 +74,14 @@ async def serve(q: Q): async def init_app(q: Q) -> None: # Read and load data into memory log.info("==Start init_app Function ==") - q.app.predictions = pd.read_csv("./static/predictions.csv") + file_path = os.path.abspath(__file__) + dir_path = os.path.dirname(file_path) + log.info(f"dir_path: {dir_path}") + predictions_file = os.path.join(dir_path, 'static', 'predictions.csv') + shapley_file = os.path.join(dir_path, 'static', 'shapley_values.csv') + q.app.predictions = pd.read_csv(predictions_file) q.app.predictions = q.app.predictions.rename(columns={'Attrition.Yes': "Prediction"}) - q.app.shapley = pd.read_csv("./static/shapley_values.csv") + q.app.shapley = pd.read_csv(shapley_file) log.info("==Complete init_app Function ==")