Skip to content

Commit

Permalink
Update load files. Remove handle_on. Update requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
us8945 committed Sep 18, 2024
1 parent 1c421a0 commit b545985
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 60 deletions.
5 changes: 4 additions & 1 deletion emp-churn-step-by-step/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
h2o-wave==0.24.0
h2o-wave==1.5.1
altair==5.4.1
pandas==2.2.2
numpy==2.1.1
4 changes: 2 additions & 2 deletions emp-churn-step-by-step/src/app1.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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()


Expand Down
16 changes: 9 additions & 7 deletions emp-churn-step-by-step/src/app10.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# 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
import pandas as pd
from typing import List

import logging
from os import environ
import os
import traceback

log = logging.getLogger("app")
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 9 additions & 6 deletions emp-churn-step-by-step/src/app11.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +10,7 @@
import os

import logging
from os import environ
import os
import traceback

log = logging.getLogger("app")
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions emp-churn-step-by-step/src/app12.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
# 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
import pandas as pd
from typing import List

import logging
from os import environ
import os
import traceback

log = logging.getLogger("app")
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 9 additions & 7 deletions emp-churn-step-by-step/src/app13.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -11,7 +11,7 @@
import pandas as pd

import logging
from os import environ
import os
import traceback

log = logging.getLogger("app")
Expand All @@ -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():
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions emp-churn-step-by-step/src/app2.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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()


Expand Down
12 changes: 8 additions & 4 deletions emp-churn-step-by-step/src/app3.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions emp-churn-step-by-step/src/app4.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions emp-churn-step-by-step/src/app5.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions emp-churn-step-by-step/src/app6.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions emp-churn-step-by-step/src/app7.py
Original file line number Diff line number Diff line change
@@ -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('/')
Expand All @@ -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:
Expand Down
Loading

0 comments on commit b545985

Please sign in to comment.