Skip to content

Commit

Permalink
Merge branch '3.0.0-dev' into 3.0.0-dev-prop-color-and-size
Browse files Browse the repository at this point in the history
  • Loading branch information
luisvasq committed Nov 21, 2024
2 parents d96433d + 3583282 commit 6bf2b5d
Show file tree
Hide file tree
Showing 66 changed files with 849 additions and 944 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ venv

# Logs
logs

# Persistent Cache
__cache__
8 changes: 1 addition & 7 deletions cave_api/cave_api/data/static_data_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@
},
"appBar": {
"order": {
"data": ["refreshButton", "infoButton"]
"data": ["infoButton"]
},
"data": {
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft"
},
"infoButton": {
"icon": "md/MdInfo",
"apiCommand": "info",
Expand Down
12 changes: 3 additions & 9 deletions cave_api/cave_api/examples/api_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ def execute_command(session_data, socket, command="init", **kwargs):
"appBar": {
# Specify the order of items as they will appear in the app bar
"order": {
"data": ["refreshButton", "myCommandButton"],
"data": [
"myCommandButton",
],
},
"data": {
# Add a simple button to the app bar to trigger the `init` command
# This is useful for resetting the app to its initial state
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft",
},
# `myCommandButton` is a custom button that is added to the app bar
# Buttons are be used to trigger custom back end logic
"myCommandButton": {
Expand Down
16 changes: 6 additions & 10 deletions cave_api/cave_api/examples/api_command_export.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import json

def execute_command(session_data, socket, command="init", **kwargs):
# `init` is the default command that is run when a session is created
# It should return an initial state for the app
Expand All @@ -14,17 +16,11 @@ def execute_command(session_data, socket, command="init", **kwargs):
"appBar": {
# Specify the order of items as they will appear in the app bar
"order": {
"data": ["refreshButton", "myCommandButton"],
"data": [
"myCommandButton",
],
},
"data": {
# Add a simple button to the app bar to trigger the `init` command
# This is useful for resetting the app to its initial state
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft",
},
# `myCommandButton` is a custom button that is added to the app bar
# Buttons are be used to trigger custom back end logic
"myCommandButton": {
Expand All @@ -42,7 +38,7 @@ def execute_command(session_data, socket, command="init", **kwargs):
# For this example, `myCommand` defined in the api in appBar.data.myCommandButton.apiCommand
elif command == "myCommand":
# Send the current session data to app users
socket.export(session_data)
socket.export(f'data:application/json,{json.dumps(session_data)}')
# Log a message in the console
print("Console Log: `myCommand` has been triggered!")
return session_data
Expand Down
28 changes: 15 additions & 13 deletions cave_api/cave_api/examples/api_command_with_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,11 @@ def execute_command(session_data, socket, command="init", **kwargs):
"appBar": {
# Specify the order of items as they will appear in the app bar
"order": {
"data": ["refreshButton", "myCommandButton"],
"data": [
"myCommandButton",
],
},
"data": {
# Add a simple button to the app bar to trigger the `init` command
# This is useful for resetting the app to its initial state
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft",
},
# `myCommandButton` is a custom button that is added to the app bar
# Buttons are be used to trigger custom back end logic
"myCommandButton": {
Expand All @@ -49,18 +43,26 @@ def execute_command(session_data, socket, command="init", **kwargs):
current_icon = session_data["appBar"]["data"]["myCommandButton"]["icon"]
# Update the icon in the session data
session_data["appBar"]["data"]["myCommandButton"]["icon"] = (
"md/MdLightbulb" if current_icon == "md/MdLightbulbOutline" else "md/MdLightbulbOutline"
"md/MdLightbulb"
if current_icon == "md/MdLightbulbOutline"
else "md/MdLightbulbOutline"
)
# Send a series of notifications to the end user
socket.notify("Priming Thrusters...", title="Initialization", theme="info", duration=3)
socket.notify(
"Priming Thrusters...", title="Initialization", theme="info", duration=3
)
time.sleep(1)
socket.notify("Ignition...", title="Initialization", theme="info")
time.sleep(1)
socket.notify("Leak detected in primary power core!", title="Warning:", theme="warning")
socket.notify(
"Leak detected in primary power core!", title="Warning:", theme="warning"
)
time.sleep(1)
socket.notify("Engine Failure!", title="Error:", theme="error")
time.sleep(1)
socket.notify("Recalibrating Gravitons!", title="Attempting Fix:", theme="warning")
socket.notify(
"Recalibrating Gravitons!", title="Attempting Fix:", theme="warning"
)
time.sleep(1)
socket.notify("Fix Succeded!", title="Attempting Fix:", theme="success")
time.sleep(1)
Expand Down
20 changes: 5 additions & 15 deletions cave_api/cave_api/examples/chart_global_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,12 @@ def execute_command(session_data, socket, command="init", **kwargs):
},
"appBar": {
# Specify the order of items as they will appear in the app bar
"order": {"data": ["refreshButton", "session", "chartPage"]},
"order": {
"data": [
"chartPage",
],
},
"data": {
# Add a simple button to the app bar to trigger the `init` command
# This is useful for resetting the app to its initial state
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft",
},
# Add an appBar button to launch the sessions pane
"session": {
"icon": "md/MdApi",
"type": "session",
"bar": "upperLeft",
},
# Add an app bar button to launch a chart dashboard
"chartPage": {
"icon": "md/MdBarChart",
Expand Down
29 changes: 19 additions & 10 deletions cave_api/cave_api/examples/chart_grouped_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ def execute_command(session_data, socket, command="init", **kwargs):
},
"appBar": {
# Specify the order of items as they will appear in the app bar
"order": {"data": ["refreshButton", "chartPage"]},
"order": {
"data": [
"chartPage",
],
},
"data": {
# Add a simple button to the app bar to trigger the `init` command
# This is useful for resetting the app to its initial state
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft",
},
# Add an app bar button to launch a chart dashboard
"chartPage": {
"icon": "md/MdBarChart",
Expand Down Expand Up @@ -132,7 +128,20 @@ def execute_command(session_data, socket, command="init", **kwargs):
},
},
"valueLists": {
"demand": [100, 108, 115, 110, 70, 78, 67, 89, 95, 100, 100, 98],
"demand": [
100,
108,
115,
110,
70,
78,
67,
89,
95,
100,
100,
98,
],
"sales": [95, 100, 100, 98, 60, 65, 67, 75, 80, 90, 99, 98],
},
"groupLists": {
Expand Down
154 changes: 127 additions & 27 deletions cave_api/cave_api/examples/chart_grouped_outputs_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,125 @@
from cave_utils.builders.groups import GroupsBuilder
from pamda import pamda


def execute_command(session_data, socket, command="init", **kwargs):

# Specify some example data to use for the grouped outputs
example_data = [
{'country': 'USA', 'state': 'Michigan', 'color': 'Red', 'size': 'Medium', 'product': 'Apple', 'sales': 95, 'demand': 100},
{'country': 'USA', 'state': 'Massachusetts', 'color': 'Red', 'size': 'Medium', 'product': 'Apple', 'sales': 100, 'demand': 108},
{'country': 'Canada', 'state': 'Ontario', 'color': 'Red', 'size': 'Medium', 'product': 'Apple', 'sales': 100, 'demand': 115},
{'country': 'Canada', 'state': 'Quebec', 'color': 'Red', 'size': 'Medium', 'product': 'Apple', 'sales': 98, 'demand': 110},
{'country': 'USA', 'state': 'Michigan', 'color': 'Purple', 'size': 'Small', 'product': 'Grape', 'sales': 60, 'demand': 70},
{'country': 'USA', 'state': 'Massachusetts', 'color': 'Purple', 'size': 'Small', 'product': 'Grape', 'sales': 65, 'demand': 78},
{'country': 'Canada', 'state': 'Ontario', 'color': 'Purple', 'size': 'Small', 'product': 'Grape', 'sales': 67, 'demand': 67},
{'country': 'Canada', 'state': 'Quebec', 'color': 'Purple', 'size': 'Small', 'product': 'Grape', 'sales': 75, 'demand': 89},
{'country': 'USA', 'state': 'Michigan', 'color': 'Red', 'size': 'Small', 'product': 'Strawberry', 'sales': 80, 'demand': 95},
{'country': 'USA', 'state': 'Massachusetts', 'color': 'Red', 'size': 'Small', 'product': 'Strawberry', 'sales': 90, 'demand': 100},
{'country': 'Canada', 'state': 'Ontario', 'color': 'Red', 'size': 'Small', 'product': 'Strawberry', 'sales': 99, 'demand': 100},
{'country': 'Canada', 'state': 'Quebec', 'color': 'Red', 'size': 'Small', 'product': 'Strawberry', 'sales': 98, 'demand': 98},
{
"country": "USA",
"state": "Michigan",
"color": "Red",
"size": "Medium",
"product": "Apple",
"sales": 95,
"demand": 100,
},
{
"country": "USA",
"state": "Massachusetts",
"color": "Red",
"size": "Medium",
"product": "Apple",
"sales": 100,
"demand": 108,
},
{
"country": "Canada",
"state": "Ontario",
"color": "Red",
"size": "Medium",
"product": "Apple",
"sales": 100,
"demand": 115,
},
{
"country": "Canada",
"state": "Quebec",
"color": "Red",
"size": "Medium",
"product": "Apple",
"sales": 98,
"demand": 110,
},
{
"country": "USA",
"state": "Michigan",
"color": "Purple",
"size": "Small",
"product": "Grape",
"sales": 60,
"demand": 70,
},
{
"country": "USA",
"state": "Massachusetts",
"color": "Purple",
"size": "Small",
"product": "Grape",
"sales": 65,
"demand": 78,
},
{
"country": "Canada",
"state": "Ontario",
"color": "Purple",
"size": "Small",
"product": "Grape",
"sales": 67,
"demand": 67,
},
{
"country": "Canada",
"state": "Quebec",
"color": "Purple",
"size": "Small",
"product": "Grape",
"sales": 75,
"demand": 89,
},
{
"country": "USA",
"state": "Michigan",
"color": "Red",
"size": "Small",
"product": "Strawberry",
"sales": 80,
"demand": 95,
},
{
"country": "USA",
"state": "Massachusetts",
"color": "Red",
"size": "Small",
"product": "Strawberry",
"sales": 90,
"demand": 100,
},
{
"country": "Canada",
"state": "Ontario",
"color": "Red",
"size": "Small",
"product": "Strawberry",
"sales": 99,
"demand": 100,
},
{
"country": "Canada",
"state": "Quebec",
"color": "Red",
"size": "Small",
"product": "Strawberry",
"sales": 98,
"demand": 98,
},
]

# Use the pamda project statement to pull out the data for the location and product groups
# Project is analogous to a SQL SELECT statement only keeping the specified columns
location_group_data = pamda.project(['country', 'state'], example_data)
product_group_data = pamda.project(['color', 'size', 'product'], example_data)
location_group_data = pamda.project(["country", "state"], example_data)
product_group_data = pamda.project(["color", "size", "product"], example_data)

# Create a locations group builder
location_group_builder = GroupsBuilder(
Expand All @@ -56,7 +153,7 @@ def execute_command(session_data, socket, command="init", **kwargs):
"product": "Products",
},
)

return {
"settings": {
# Icon Url is used to load icons from a custom icon library
Expand All @@ -68,16 +165,12 @@ def execute_command(session_data, socket, command="init", **kwargs):
},
"appBar": {
# Specify the order of items as they will appear in the app bar
"order": {"data": ["refreshButton", "chartPage"]},
"order": {
"data": [
"chartPage",
],
},
"data": {
# Add a simple button to the app bar to trigger the `init` command
# This is useful for resetting the app to its initial state
"refreshButton": {
"icon": "md/MdRefresh",
"apiCommand": "init",
"type": "button",
"bar": "upperLeft",
},
# Add an app bar button to launch a chart dashboard
"chartPage": {
"icon": "md/MdBarChart",
Expand Down Expand Up @@ -147,11 +240,18 @@ def execute_command(session_data, socket, command="init", **kwargs):
},
},
# Select the appropriate columns and pivot them to be used in the grouped outputs
"valueLists": pamda.pivot(pamda.project(['sales', 'demand'], example_data)),
"valueLists": pamda.pivot(
pamda.project(["sales", "demand"], example_data)
),
# Get the relevant group ids given each item in the base data
"groupLists": {
"location": [location_group_builder.get_id(i) for i in location_group_data],
"product": [product_group_builder.get_id(i) for i in product_group_data],
"location": [
location_group_builder.get_id(i)
for i in location_group_data
],
"product": [
product_group_builder.get_id(i) for i in product_group_data
],
},
},
},
Expand Down
Loading

0 comments on commit 6bf2b5d

Please sign in to comment.