ApiLogicServer 14.3.20__py3-none-any.whl → 14.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- api_logic_server_cli/api_logic_server.py +5 -14
- api_logic_server_cli/api_logic_server_info.yaml +3 -3
- api_logic_server_cli/cli.py +52 -5
- api_logic_server_cli/create_from_model/__pycache__/create_db_from_model.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/__pycache__/ont_build.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/__pycache__/ont_create.cpython-312.pyc +0 -0
- api_logic_server_cli/create_from_model/create_db_from_model.py +2 -0
- api_logic_server_cli/create_from_model/ont_build.py +19 -14
- api_logic_server_cli/create_from_model/ont_create.py +5 -5
- api_logic_server_cli/create_from_model/safrs-react-admin-npm-build/static/.DS_Store +0 -0
- api_logic_server_cli/database/nw-gold-fix.sql +62 -0
- api_logic_server_cli/database/nw-gold.sqlite +0 -0
- api_logic_server_cli/fragments/docker-compose.yml +27 -0
- api_logic_server_cli/genai/genai.py +43 -11
- api_logic_server_cli/genai/genai_graphics.py +379 -0
- api_logic_server_cli/genai/genai_logic_builder.py +2 -2
- api_logic_server_cli/genai/genai_svcs.py +24 -8
- api_logic_server_cli/manager.py +19 -10
- api_logic_server_cli/prototypes/.DS_Store +0 -0
- api_logic_server_cli/prototypes/base/.DS_Store +0 -0
- api_logic_server_cli/prototypes/base/.vscode/launch.json +19 -0
- api_logic_server_cli/prototypes/base/api/expose_api_models.py +3 -1
- api_logic_server_cli/prototypes/base/api_logic_server_run.py +5 -2
- api_logic_server_cli/prototypes/base/config/activate_logicbank.py +1 -0
- api_logic_server_cli/prototypes/base/config/config.py +95 -24
- api_logic_server_cli/prototypes/base/config/logging.yml +1 -0
- api_logic_server_cli/prototypes/base/config/server_setup.py +33 -1
- api_logic_server_cli/prototypes/base/database/test_data/readme.md +3 -1
- api_logic_server_cli/prototypes/base/devops/docker-standard-image/docker-compose-standard-image.yml +7 -2
- api_logic_server_cli/prototypes/base/docs/graphics/readme.md +12 -0
- api_logic_server_cli/prototypes/base/docs/training/logic_bank_api.prompt +314 -0
- api_logic_server_cli/prototypes/base/docs/training/logic_example.py +41 -0
- api_logic_server_cli/prototypes/base/integration/kafka/kafka_producer.py +7 -3
- api_logic_server_cli/prototypes/base/integration/system/FlaskKafka.py +5 -1
- api_logic_server_cli/prototypes/base/security/authentication_provider/keycloak/auth_provider.py +1 -1
- api_logic_server_cli/prototypes/base/security/declare_security.py +4 -0
- api_logic_server_cli/prototypes/base/ui/admin/admin_loader.py +3 -1
- api_logic_server_cli/prototypes/base/ui/templates/bar_chart.jinja +64 -0
- api_logic_server_cli/prototypes/genai_demo/ui/admin/admin.yaml +1 -1
- api_logic_server_cli/prototypes/manager/README.md +56 -5
- api_logic_server_cli/prototypes/manager/system/genai/.DS_Store +0 -0
- api_logic_server_cli/prototypes/manager/system/genai/examples/.DS_Store +0 -0
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/.DS_Store +0 -0
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.prompt +0 -8
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo.response_example +90 -60
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_docs_logic/docs/002_create_db_models.prompt +4 -4
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_docs_logic/docs/003_create_db_models.response +77 -47
- api_logic_server_cli/prototypes/manager/system/genai/examples/genai_demo/genai_demo_informal.prompt +1 -1
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/dashboard_services.jinja +83 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_dashboard_WIP.py +34 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_services_api_xxx.py +32 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_services_db.jinja +46 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_services_db_each_method.jinja +36 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/html_template.jinja +76 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/index.html +19 -0
- api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/sales_by_region.jinja +63 -0
- api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/graphics.prompt +22 -0
- api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/graphics_request.prompt +5 -0
- api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/response_format.prompt +15 -0
- api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/sqlite_inserts.prompt +2 -0
- api_logic_server_cli/prototypes/manager/system/install-ApiLogicServer-dev/install-ApiLogicServer-dev.ps1 +100 -0
- api_logic_server_cli/prototypes/manager/system/install-ApiLogicServer-dev/install-ApiLogicServer-dev.sh +116 -0
- api_logic_server_cli/prototypes/manager/system/install-ApiLogicServer-dev/readme.md +7 -0
- api_logic_server_cli/prototypes/manager/system/style-guide.yaml +2 -2
- api_logic_server_cli/prototypes/manager/webgenai/README.md +6 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/count_orders_by_category.prompt +1 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/order_count_by_month.prompt +1 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/request copy.json +892 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/request.json +6 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/response.json +17 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/response.yaml +59 -0
- api_logic_server_cli/prototypes/nw/docs/graphics/sales_by_category.prompt +1 -0
- api_logic_server_cli/prototypes/nw/ui/admin/home.js +5 -4
- api_logic_server_cli/prototypes/nw/ui/app_model_custom.yaml +851 -1082
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/count_orders_by_category.prompt +1 -0
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/request copy.json +892 -0
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/request.json +6 -0
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/response.json +17 -0
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/response.yaml +59 -0
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/sales_by_category.prompt +1 -0
- api_logic_server_cli/prototypes/nw_no_cust/docs/graphics/sales_by_employee.prompt +1 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/1_langchain_loader.py +19 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/2_gpt_mcp_prompt.txt +19 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/3_executor_test_agent.py +38 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/README.md +17 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/resources/curl.txt +4 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/resources/nw_swagger_3.yaml +16660 -0
- api_logic_server_cli/prototypes/nw_no_cust/integration/mcp/run_executor.py +23 -0
- api_logic_server_cli/prototypes/ont_app/ontimize_seed/nginx/nginx.conf +2 -2
- api_logic_server_cli/prototypes/ont_app/ontimize_seed/package.json +6 -6
- api_logic_server_cli/prototypes/ont_app/ontimize_seed/src/app/app.config.ts +2 -1
- api_logic_server_cli/prototypes/ont_app/ontimize_seed/src/environments/environment.prod.ts +5 -5
- api_logic_server_cli/prototypes/ont_app/ontimize_seed/src/environments/environment.ts +5 -5
- api_logic_server_cli/prototypes/ont_app/templates/app_config.jinja +1 -1
- api_logic_server_cli/prototypes/ont_app/templates/detail_template.html +1 -1
- api_logic_server_cli/prototypes/ont_app/templates/new_template.html +16 -16
- apilogicserver-14.4.0.dist-info/METADATA +76 -0
- {apilogicserver-14.3.20.dist-info → apilogicserver-14.4.0.dist-info}/RECORD +102 -59
- {apilogicserver-14.3.20.dist-info → apilogicserver-14.4.0.dist-info}/WHEEL +1 -1
- api_logic_server_cli/prototypes/manager/system/genai/prompt_inserts/zsqlite_inserts_iterations.prompt +0 -29
- api_logic_server_cli/prototypes/manager/webgenai/docker-compose-webg.yml +0 -33
- api_logic_server_cli/prototypes/manager/webgenai/webg_config/license.json +0 -6
- api_logic_server_cli/prototypes/manager/webgenai/webg_config/web_genai.txt +0 -13
- apilogicserver-14.3.20.dist-info/METADATA +0 -167
- {apilogicserver-14.3.20.dist-info → apilogicserver-14.4.0.dist-info}/entry_points.txt +0 -0
- {apilogicserver-14.3.20.dist-info → apilogicserver-14.4.0.dist-info}/licenses/LICENSE +0 -0
- {apilogicserver-14.3.20.dist-info → apilogicserver-14.4.0.dist-info}/top_level.txt +0 -0
|
@@ -2,140 +2,170 @@
|
|
|
2
2
|
"models": [
|
|
3
3
|
{
|
|
4
4
|
"classname": "Customer",
|
|
5
|
-
"code": "class Customer(Base):\n __tablename__ = 'customer'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String
|
|
6
|
-
"description": "
|
|
7
|
-
"name": "
|
|
5
|
+
"code": "class Customer(Base):\n __tablename__ = 'customer'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, unique=True)\n balance = Column(DECIMAL)\n credit_limit = Column(DECIMAL)",
|
|
6
|
+
"description": "Defines the Customer entity with a unique name, balance, and credit limit.",
|
|
7
|
+
"name": "Customer"
|
|
8
8
|
},
|
|
9
9
|
{
|
|
10
10
|
"classname": "Order",
|
|
11
|
-
"code": "class Order(Base):\n __tablename__ = 'order'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n customer_id = Column(Integer, ForeignKey('customer.id'))\n date_shipped = Column(
|
|
12
|
-
"description": "
|
|
13
|
-
"name": "
|
|
11
|
+
"code": "class Order(Base):\n __tablename__ = 'order'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n notes = Column(String)\n customer_id = Column(Integer, ForeignKey('customer.id'), nullable=False)\n date_shipped = Column(Date)\n amount_total = Column(DECIMAL)",
|
|
12
|
+
"description": "Defines the Order entity which belongs to a customer. Includes notes and amount total.",
|
|
13
|
+
"name": "Order"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
"classname": "Item",
|
|
17
|
-
"code": "class Item(Base):\n __tablename__ = 'item'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n order_id = Column(Integer, ForeignKey('order.id'))\n product_id = Column(Integer, ForeignKey('product.id'))\n quantity = Column(Integer, nullable=False)\n
|
|
18
|
-
"description": "
|
|
19
|
-
"name": "
|
|
17
|
+
"code": "class Item(Base):\n __tablename__ = 'item'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n order_id = Column(Integer, ForeignKey('order.id'))\n product_id = Column(Integer, ForeignKey('product.id'), nullable=False)\n quantity = Column(Integer, nullable=False)\n amount = Column(DECIMAL)\n unit_price = Column(DECIMAL)",
|
|
18
|
+
"description": "Defines the Item entity with quantity, amounts, and unit price details.",
|
|
19
|
+
"name": "Item"
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
"classname": "Product",
|
|
23
|
-
"code": "class Product(Base):\n __tablename__ = 'product'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String
|
|
24
|
-
"description": "
|
|
25
|
-
"name": "
|
|
23
|
+
"code": "class Product(Base):\n __tablename__ = 'product'\n\n id = Column(Integer, primary_key=True, autoincrement=True)\n name = Column(String, unique=True)\n unit_price = Column(DECIMAL)",
|
|
24
|
+
"description": "Defines the Product entity with a unique name and unit price.",
|
|
25
|
+
"name": "Product"
|
|
26
26
|
}
|
|
27
27
|
],
|
|
28
28
|
"rules": [
|
|
29
29
|
{
|
|
30
|
-
"name": "
|
|
31
|
-
"description": "Ensure customer balance is
|
|
30
|
+
"name": "Customer Balance Constraint",
|
|
31
|
+
"description": "Ensure the customer's balance is less than their credit limit.",
|
|
32
32
|
"use_case": "Check Credit",
|
|
33
33
|
"entity": "Customer",
|
|
34
|
-
"code": "Rule.constraint(validate=Customer,
|
|
34
|
+
"code": "Rule.constraint(validate=Customer, as_condition=lambda row: row.balance <= row.credit_limit, error_msg=\"Customer balance ({row.balance}) exceeds credit limit ({row.credit_limit})\")"
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
"name": "Customer Balance
|
|
38
|
-
"description": "
|
|
37
|
+
"name": "Customer Balance Derivation",
|
|
38
|
+
"description": "Derive the customer's balance as the sum of order totals where not yet shipped.",
|
|
39
39
|
"use_case": "Check Credit",
|
|
40
40
|
"entity": "Customer",
|
|
41
|
-
"code": "Rule.sum(derive=Customer.balance,
|
|
41
|
+
"code": "Rule.sum(derive=Customer.balance, as_sum_of=Order.amount_total, where=lambda row: row.date_shipped is None)"
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
|
-
"name": "Order
|
|
45
|
-
"description": "
|
|
44
|
+
"name": "Order Total Derivation",
|
|
45
|
+
"description": "Derive the order's total amount from the sum of item amounts.",
|
|
46
46
|
"use_case": "Check Credit",
|
|
47
47
|
"entity": "Order",
|
|
48
|
-
"code": "Rule.sum(derive=Order.amount_total,
|
|
48
|
+
"code": "Rule.sum(derive=Order.amount_total, as_sum_of=Item.amount)"
|
|
49
49
|
},
|
|
50
50
|
{
|
|
51
|
-
"name": "Item Amount
|
|
52
|
-
"description": "Calculate item amount
|
|
51
|
+
"name": "Item Amount Calculation",
|
|
52
|
+
"description": "Calculate item amount based on quantity and unit price.",
|
|
53
53
|
"use_case": "Check Credit",
|
|
54
54
|
"entity": "Item",
|
|
55
|
-
"code": "Rule.formula(derive=Item.amount,
|
|
55
|
+
"code": "Rule.formula(derive=Item.amount, as_expression=lambda row: row.quantity * row.unit_price)"
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
"name": "
|
|
58
|
+
"name": "Item Unit Price Copy",
|
|
59
59
|
"description": "Copy unit price from product to item.",
|
|
60
60
|
"use_case": "Check Credit",
|
|
61
61
|
"entity": "Item",
|
|
62
|
-
"code": "Rule.copy(derive=Item.unit_price,
|
|
62
|
+
"code": "Rule.copy(derive=Item.unit_price, from_parent=Product.unit_price)"
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
"name": "Order
|
|
66
|
-
"description": "Send
|
|
65
|
+
"name": "Order Kafka Notification",
|
|
66
|
+
"description": "Send order details to Kafka if order is shipped.",
|
|
67
67
|
"use_case": "App Integration",
|
|
68
68
|
"entity": "Order",
|
|
69
|
-
"code": "Rule.after_flush_row_event(on_class=Order,
|
|
69
|
+
"code": "Rule.after_flush_row_event(on_class=Order, calling=kafka_producer.send_row_to_kafka, if_condition=lambda row: row.date_shipped is not None, with_args={'topic': 'order_shipping'})"
|
|
70
70
|
}
|
|
71
71
|
],
|
|
72
|
-
"
|
|
72
|
+
"graphics": [
|
|
73
|
+
{
|
|
74
|
+
"sqlalchemy_query": "session.query(Product.name, func.sum(Item.amount).label('TotalSales')).join(Item, Product.id == Item.product_id).filter(Order.date_shipped.isnot(None)).group_by(Product.name).order_by(func.sum(Item.amount).desc())",
|
|
75
|
+
"sql_query": "SELECT Product.name, SUM(Item.amount) AS TotalSales FROM Product JOIN Item ON Product.id = Item.product_id JOIN Order ON Item.order_id = Order.id WHERE Order.date_shipped IS NOT NULL GROUP BY Product.name ORDER BY TotalSales DESC",
|
|
76
|
+
"classes_used": "Product, Item, Order",
|
|
77
|
+
"class_x_axis": "Product",
|
|
78
|
+
"name": "sales_by_product",
|
|
79
|
+
"prompt": "Graph Sales by Product",
|
|
80
|
+
"title": "Sales by Product",
|
|
81
|
+
"xAxis": "Product",
|
|
82
|
+
"yAxis": "Total Sales",
|
|
83
|
+
"dashboard": true,
|
|
84
|
+
"graph_type": "Bar",
|
|
85
|
+
"html_code": "var data = result.result; var categories = data.map(item => item[0]); var totals = data.map(item => item[1]); var ctx = document.getElementById('salesByProductChart').getContext('2d'); new Chart(ctx, {type: 'bar', data: {labels: categories, datasets: [{label: 'Sales by Product', data: totals}]}});"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"sqlalchemy_query": "session.query(Customer.name, func.sum(Order.amount_total).label('TotalCustomerSales')).join(Order, Customer.id == Order.customer_id).filter(Order.date_shipped.isnot(None)).group_by(Customer.name).order_by(func.sum(Order.amount_total).desc())",
|
|
89
|
+
"sql_query": "SELECT Customer.name, SUM(Order.amount_total) AS TotalCustomerSales FROM Customer JOIN Order ON Customer.id = Order.customer_id WHERE Order.date_shipped IS NOT NULL GROUP BY Customer.name ORDER BY TotalCustomerSales DESC",
|
|
90
|
+
"classes_used": "Customer, Order",
|
|
91
|
+
"class_x_axis": "Customer",
|
|
92
|
+
"name": "sales_by_customer",
|
|
93
|
+
"prompt": "Graph Sales by Customer",
|
|
94
|
+
"title": "Sales by Customer",
|
|
95
|
+
"xAxis": "Customer",
|
|
96
|
+
"yAxis": "Total Sales",
|
|
97
|
+
"dashboard": true,
|
|
98
|
+
"graph_type": "Bar",
|
|
99
|
+
"html_code": "var data = result.result; var customers = data.map(item => item[0]); var sales = data.map(item => item[1]); var ctx = document.getElementById('salesByCustomerChart').getContext('2d'); new Chart(ctx, {type: 'bar', data: {labels: customers, datasets: [{label: 'Sales by Customer', data: sales}]}});"
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
"test_data": "This is the test data generated for Customers, Orders, Items, and Products in the new system.",
|
|
73
103
|
"test_data_rows": [
|
|
74
104
|
{
|
|
75
105
|
"test_data_row_variable": "customer1",
|
|
76
|
-
"code": "customer1 = Customer(
|
|
106
|
+
"code": "customer1 = Customer(name=\"Alice\", balance=1000.00, credit_limit=5000.00)"
|
|
77
107
|
},
|
|
78
108
|
{
|
|
79
109
|
"test_data_row_variable": "customer2",
|
|
80
|
-
"code": "customer2 = Customer(
|
|
110
|
+
"code": "customer2 = Customer(name=\"Bob\", balance=2000.00, credit_limit=3000.00)"
|
|
81
111
|
},
|
|
82
112
|
{
|
|
83
113
|
"test_data_row_variable": "customer3",
|
|
84
|
-
"code": "customer3 = Customer(
|
|
114
|
+
"code": "customer3 = Customer(name=\"Charlie\", balance=500.00, credit_limit=2000.00)"
|
|
85
115
|
},
|
|
86
116
|
{
|
|
87
117
|
"test_data_row_variable": "customer4",
|
|
88
|
-
"code": "customer4 = Customer(
|
|
118
|
+
"code": "customer4 = Customer(name=\"Diana\", balance=0.00, credit_limit=1000.00)"
|
|
89
119
|
},
|
|
90
120
|
{
|
|
91
121
|
"test_data_row_variable": "product1",
|
|
92
|
-
"code": "product1 = Product(
|
|
122
|
+
"code": "product1 = Product(name=\"Gadget\", unit_price=150.00)"
|
|
93
123
|
},
|
|
94
124
|
{
|
|
95
125
|
"test_data_row_variable": "product2",
|
|
96
|
-
"code": "product2 = Product(
|
|
126
|
+
"code": "product2 = Product(name=\"Widget\", unit_price=90.00)"
|
|
97
127
|
},
|
|
98
128
|
{
|
|
99
129
|
"test_data_row_variable": "product3",
|
|
100
|
-
"code": "product3 = Product(
|
|
130
|
+
"code": "product3 = Product(name=\"Thingamajig\", unit_price=75.00)"
|
|
101
131
|
},
|
|
102
132
|
{
|
|
103
133
|
"test_data_row_variable": "product4",
|
|
104
|
-
"code": "product4 = Product(
|
|
134
|
+
"code": "product4 = Product(name=\"Doodad\", unit_price=110.00)"
|
|
105
135
|
},
|
|
106
136
|
{
|
|
107
137
|
"test_data_row_variable": "order1",
|
|
108
|
-
"code": "order1 = Order(
|
|
138
|
+
"code": "order1 = Order(notes=\"First Order\", customer_id=1, date_shipped=date(2023, 3, 22), amount_total=300.00)"
|
|
109
139
|
},
|
|
110
140
|
{
|
|
111
141
|
"test_data_row_variable": "order2",
|
|
112
|
-
"code": "order2 = Order(
|
|
142
|
+
"code": "order2 = Order(notes=\"Second Order\", customer_id=2, date_shipped=None, amount_total=0.00)"
|
|
113
143
|
},
|
|
114
144
|
{
|
|
115
145
|
"test_data_row_variable": "order3",
|
|
116
|
-
"code": "order3 = Order(
|
|
146
|
+
"code": "order3 = Order(notes=\"Pending Shipment\", customer_id=3, date_shipped=None, amount_total=300.00)"
|
|
117
147
|
},
|
|
118
148
|
{
|
|
119
149
|
"test_data_row_variable": "order4",
|
|
120
|
-
"code": "order4 = Order(
|
|
150
|
+
"code": "order4 = Order(notes=\"Urgent Order\", customer_id=4, date_shipped=date(2023, 7, 15), amount_total=220.00)"
|
|
121
151
|
},
|
|
122
152
|
{
|
|
123
153
|
"test_data_row_variable": "item1",
|
|
124
|
-
"code": "item1 = Item(
|
|
154
|
+
"code": "item1 = Item(order_id=1, product_id=1, quantity=2, amount=300.00, unit_price=150.00)"
|
|
125
155
|
},
|
|
126
156
|
{
|
|
127
157
|
"test_data_row_variable": "item2",
|
|
128
|
-
"code": "item2 = Item(
|
|
158
|
+
"code": "item2 = Item(order_id=2, product_id=2, quantity=1, amount=90.00, unit_price=90.00)"
|
|
129
159
|
},
|
|
130
160
|
{
|
|
131
161
|
"test_data_row_variable": "item3",
|
|
132
|
-
"code": "item3 = Item(
|
|
162
|
+
"code": "item3 = Item(order_id=3, product_id=4, quantity=2, amount=220.00, unit_price=110.00)"
|
|
133
163
|
},
|
|
134
164
|
{
|
|
135
165
|
"test_data_row_variable": "item4",
|
|
136
|
-
"code": "item4 = Item(
|
|
166
|
+
"code": "item4 = Item(order_id=4, product_id=3, quantity=4, amount=300.00, unit_price=75.00)"
|
|
137
167
|
}
|
|
138
168
|
],
|
|
139
|
-
"test_data_sqlite": "INSERT INTO customer (
|
|
169
|
+
"test_data_sqlite": "INSERT INTO customer (name, balance, credit_limit) VALUES ('Alice', 1000.00, 5000.00);\nINSERT INTO customer (name, balance, credit_limit) VALUES ('Bob', 2000.00, 3000.00);\nINSERT INTO customer (name, balance, credit_limit) VALUES ('Charlie', 500.00, 2000.00);\nINSERT INTO customer (name, balance, credit_limit) VALUES ('Diana', 0.00, 1000.00);\n\nINSERT INTO product (name, unit_price) VALUES ('Gadget', 150.00);\nINSERT INTO product (name, unit_price) VALUES ('Widget', 90.00);\nINSERT INTO product (name, unit_price) VALUES ('Thingamajig', 75.00);\nINSERT INTO product (name, unit_price) VALUES ('Doodad', 110.00);\n\nINSERT INTO [order] (notes, customer_id, date_shipped, amount_total) VALUES ('First Order', 1, '2023-03-22', 300.00);\nINSERT INTO [order] (notes, customer_id, date_shipped, amount_total) VALUES ('Second Order', 2, NULL, 0.00);\nINSERT INTO [order] (notes, customer_id, date_shipped, amount_total) VALUES ('Pending Shipment', 3, NULL, 300.00);\nINSERT INTO [order] (notes, customer_id, date_shipped, amount_total) VALUES ('Urgent Order', 4, '2023-07-15', 220.00);\n\nINSERT INTO item (order_id, product_id, quantity, amount, unit_price) VALUES (1, 1, 2, 300.00, 150.00);\nINSERT INTO item (order_id, product_id, quantity, amount, unit_price) VALUES (2, 2, 1, 90.00, 90.00);\nINSERT INTO item (order_id, product_id, quantity, amount, unit_price) VALUES (3, 4, 2, 220.00, 110.00);\nINSERT INTO item (order_id, product_id, quantity, amount, unit_price) VALUES (4, 3, 4, 300.00, 75.00);",
|
|
140
170
|
"name": "CustomerOrderSystem"
|
|
141
171
|
}
|
api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/dashboard_services.jinja
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from database import models
|
|
2
|
+
import logging
|
|
3
|
+
from safrs import jsonapi_attr
|
|
4
|
+
from sqlalchemy.orm import relationship, remote, foreign
|
|
5
|
+
from functools import wraps # This convenience func preserves name and docstring
|
|
6
|
+
import decimal as decimal
|
|
7
|
+
from sqlalchemy import extract, func
|
|
8
|
+
from flask import request, jsonify
|
|
9
|
+
from safrs import jsonapi_rpc, SAFRSAPI
|
|
10
|
+
from database import models
|
|
11
|
+
import safrs
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
"""
|
|
15
|
+
Called by iFrame in home.js when admin app is loaded
|
|
16
|
+
|
|
17
|
+
Returns iFrame for ui/admin/home.js, with entries like this to populate the dashboard:
|
|
18
|
+
<iframe src="http://localhost:5656/chart_graphics/sales_per_category" style="flex: 1; border: none; width: 90%; height: 200px;">
|
|
19
|
+
|
|
20
|
+
curl -X GET "http://localhost:5656/dashboard"
|
|
21
|
+
|
|
22
|
+
You typically do not alter this file - it is rebuilt on `als genai-graphics`
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
app_logger = logging.getLogger(__name__)
|
|
27
|
+
dashboard_result = {}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def add_service(app, api, project_dir, swagger_host: str, PORT: str, method_decorators = []):
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
@app.route('/dashboard', methods=['GET','OPTIONS'])
|
|
34
|
+
def dashboard():
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if request.method == 'OPTIONS':
|
|
38
|
+
return jsonify({"result": "ok"})
|
|
39
|
+
|
|
40
|
+
server = request.host_url
|
|
41
|
+
|
|
42
|
+
iframe_template = '<div class="dashboard-iframe"><iframe src="{url}" style="flex: 1; border: none; width: 90%; height: 200px;"></iframe></div>'
|
|
43
|
+
{% for iframe in iframe_templates %}
|
|
44
|
+
{{iframe}}
|
|
45
|
+
{% endfor %}
|
|
46
|
+
|
|
47
|
+
{% if has_iframe %}
|
|
48
|
+
return f'<div style="display: flex; flex-direction: row; gap: 10px; border: none; ">{{ iframe_links }}</div>'
|
|
49
|
+
{% endif %}
|
|
50
|
+
{% if has_iframe == false %}
|
|
51
|
+
return jsonify({})
|
|
52
|
+
{% endif %}
|
|
53
|
+
|
|
54
|
+
@app.route('/chart_graphics/<path:path>', methods=['GET','OPTIONS'])
|
|
55
|
+
def chart_graphics(path):
|
|
56
|
+
if request.method == 'OPTIONS':
|
|
57
|
+
return jsonify({"result": "ok"})
|
|
58
|
+
|
|
59
|
+
dashboards = get_dashboards()
|
|
60
|
+
if len(dashboards) == 0:
|
|
61
|
+
return jsonify({"result": "No dashboards Found"}), 404
|
|
62
|
+
if path in dashboards:
|
|
63
|
+
return dashboards[path]
|
|
64
|
+
return jsonify({"result": "not found"}), 404
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
##############################
|
|
68
|
+
# generated queries follow
|
|
69
|
+
##############################
|
|
70
|
+
|
|
71
|
+
def get_dashboards():
|
|
72
|
+
if len(dashboard_result) > 0:
|
|
73
|
+
return dashboard_result
|
|
74
|
+
|
|
75
|
+
from jinja2 import Environment, FileSystemLoader
|
|
76
|
+
env = Environment(loader = FileSystemLoader('ui/templates'))
|
|
77
|
+
template = env.get_template('bar_chart.jinja')
|
|
78
|
+
|
|
79
|
+
{% for dashboard in dashboards %}
|
|
80
|
+
{{dashboard}}
|
|
81
|
+
{% endfor %}
|
|
82
|
+
|
|
83
|
+
return dashboard_result
|
api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_dashboard_WIP.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
import logging
|
|
3
|
+
from flask_jwt_extended import get_jwt, jwt_required, verify_jwt_in_request
|
|
4
|
+
from config.config import Config, Args
|
|
5
|
+
from security.system.authorization import Security
|
|
6
|
+
import api.system.api_utils as api_utils
|
|
7
|
+
from typing import List
|
|
8
|
+
import safrs
|
|
9
|
+
import sqlalchemy
|
|
10
|
+
from flask import request, jsonify
|
|
11
|
+
from safrs import jsonapi_rpc, SAFRSAPI
|
|
12
|
+
from sqlalchemy.ext.hybrid import hybrid_property
|
|
13
|
+
from sqlalchemy.orm import object_mapper
|
|
14
|
+
from sqlalchemy import extract, func
|
|
15
|
+
from database import models
|
|
16
|
+
from flask_cors import cross_origin
|
|
17
|
+
from logic_bank.rule_bank.rule_bank import RuleBank
|
|
18
|
+
import integration.system.RowDictMapper as row_dict_mapper
|
|
19
|
+
|
|
20
|
+
# called by home.js to populate dashboard iFrame with results of all dsahboard queries
|
|
21
|
+
|
|
22
|
+
app_logger = logging.getLogger("api_logic_server_app")
|
|
23
|
+
|
|
24
|
+
def add_service(app, api, project_dir, swagger_host: str, PORT: str, method_decorators = []):
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
api.expose_object(GraphicsDashboard) # Swagger-visible services
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class GraphicsDashboard(safrs.JABase):
|
|
31
|
+
"""GraphicsDashboard service - results of all dsahboard queries"""
|
|
32
|
+
result = []
|
|
33
|
+
|
|
34
|
+
{{dashboard_lines}}
|
api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_services_api_xxx.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from functools import wraps
|
|
2
|
+
import logging
|
|
3
|
+
from flask_jwt_extended import get_jwt, jwt_required, verify_jwt_in_request
|
|
4
|
+
from config.config import Config, Args
|
|
5
|
+
from security.system.authorization import Security
|
|
6
|
+
import api.system.api_utils as api_utils
|
|
7
|
+
from typing import List
|
|
8
|
+
import safrs
|
|
9
|
+
import sqlalchemy
|
|
10
|
+
from flask import request, jsonify
|
|
11
|
+
from safrs import jsonapi_rpc, SAFRSAPI
|
|
12
|
+
from sqlalchemy.ext.hybrid import hybrid_property
|
|
13
|
+
from sqlalchemy.orm import object_mapper
|
|
14
|
+
from sqlalchemy import extract, func
|
|
15
|
+
from database import models
|
|
16
|
+
from flask_cors import cross_origin
|
|
17
|
+
from logic_bank.rule_bank.rule_bank import RuleBank
|
|
18
|
+
import integration.system.RowDictMapper as row_dict_mapper
|
|
19
|
+
|
|
20
|
+
# Customize this file to add endpoints/services, using SQLAlchemy as required
|
|
21
|
+
# Separate from expose_api_models.py, to simplify merge if project rebuilt
|
|
22
|
+
# Called by api_logic_server_run.py
|
|
23
|
+
|
|
24
|
+
app_logger = logging.getLogger("api_logic_server_app")
|
|
25
|
+
|
|
26
|
+
# called by api_logic_server_run.py, to customize api (new end points, services).
|
|
27
|
+
# separate from expose_api_models.py, to simplify merge if project recreated
|
|
28
|
+
|
|
29
|
+
def add_service(app, api, project_dir, swagger_host: str, PORT: str, method_decorators = []):
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
|
api_logic_server_cli/prototypes/manager/system/genai/graphics_templates/graphics_services_db.jinja
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from database import models
|
|
2
|
+
import logging
|
|
3
|
+
from safrs import jsonapi_attr
|
|
4
|
+
from sqlalchemy.orm import relationship, remote, foreign
|
|
5
|
+
from functools import wraps # This convenience func preserves name and docstring
|
|
6
|
+
import decimal as decimal
|
|
7
|
+
from sqlalchemy import extract, func
|
|
8
|
+
from flask import request, jsonify
|
|
9
|
+
from safrs import jsonapi_rpc, SAFRSAPI
|
|
10
|
+
import safrs
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
Graphics methods for database classes, created when:
|
|
14
|
+
* `als genai create` contains prompts like: 'Graph Sales by Category', etc.
|
|
15
|
+
* `als add-graphics` --using the docs/graphics directory
|
|
16
|
+
|
|
17
|
+
Called by api/api_discovery/dashboard_services.py when admin app loaded
|
|
18
|
+
|
|
19
|
+
You typically do not alter this file - rebuilt on als genai--graphics.
|
|
20
|
+
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
app_logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def add_method(cls):
|
|
27
|
+
"""
|
|
28
|
+
Decorator to add method to class, e.g., db class group by query method
|
|
29
|
+
|
|
30
|
+
Thanks to: https://mgarod.medium.com/dynamically-add-a-method-to-a-class-in-python-c49204b85bd6
|
|
31
|
+
"""
|
|
32
|
+
def decorator(func):
|
|
33
|
+
@wraps(func)
|
|
34
|
+
def wrapper(self, *args, **kwargs):
|
|
35
|
+
return func(*args, **kwargs)
|
|
36
|
+
|
|
37
|
+
setattr(cls, func.__name__, wrapper)
|
|
38
|
+
# Note we are not binding func, but wrapper which accepts self but does exactly the same as func
|
|
39
|
+
return func # returning func means func can still be used normally
|
|
40
|
+
return decorator
|
|
41
|
+
|
|
42
|
+
##############################
|
|
43
|
+
# generated services follow
|
|
44
|
+
##############################
|
|
45
|
+
|
|
46
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
@classmethod
|
|
3
|
+
@add_method(models.{{class_x_axis}})
|
|
4
|
+
@jsonapi_rpc(http_methods=['GET', 'OPTIONS'])
|
|
5
|
+
def {{name}}(*args, **kwargs):
|
|
6
|
+
"""
|
|
7
|
+
Complex query with multiple joins, for graphics, from 'Graph Sales by Category', etc.
|
|
8
|
+
Test with Swagger.
|
|
9
|
+
"""
|
|
10
|
+
if request.method == 'OPTIONS':
|
|
11
|
+
return jsonify({ "result": "ok" })
|
|
12
|
+
|
|
13
|
+
from database.models import {{classes_used}}
|
|
14
|
+
db = safrs.DB
|
|
15
|
+
session = db.session # sqlalchemy.orm.scoping.scoped_session
|
|
16
|
+
# Security.set_user_sa() # an endpoint that requires no auth header (see also @bypass_security)
|
|
17
|
+
|
|
18
|
+
# SQLAlchemy query
|
|
19
|
+
query = {{ sqlalchemy_query }}
|
|
20
|
+
# Execute query and fetch results
|
|
21
|
+
results = query.all()
|
|
22
|
+
from decimal import Decimal
|
|
23
|
+
columns = ['{{ xAxis }}' , '{{ yAxis }}']
|
|
24
|
+
results = [{columns[0]: row[0], columns[1]: round(float(row[1]), 2)} for row in results]
|
|
25
|
+
title = '{{ title }}'
|
|
26
|
+
graph_type = '{{ graph_type }}'.lower()
|
|
27
|
+
json_results = {
|
|
28
|
+
"results": results,
|
|
29
|
+
"columns": columns,
|
|
30
|
+
"title": title,
|
|
31
|
+
"chart_type": graph_type,
|
|
32
|
+
"xAxis": columns[0],
|
|
33
|
+
"yAxis": columns[1],
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return json_results
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Bar Chart Example</title>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<canvas id="myChart" width="400" height="200"></canvas>
|
|
11
|
+
<script>
|
|
12
|
+
// Input data
|
|
13
|
+
fetch('http://localhost:5656/api/GraphicsServices/{{ name }}', {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers: {
|
|
16
|
+
'accept': 'application/vnd.api+json',
|
|
17
|
+
'Content-Type': 'application/json'
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify({}) // Add any required payload here
|
|
20
|
+
})
|
|
21
|
+
.then(response => {
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
24
|
+
}
|
|
25
|
+
return response.json();
|
|
26
|
+
})
|
|
27
|
+
.then(result => {
|
|
28
|
+
const labels = [];
|
|
29
|
+
const data = [];
|
|
30
|
+
const type = result.meta.result.chart_type;
|
|
31
|
+
const title = result.meta.result.title;
|
|
32
|
+
const columns = result.meta.result.columns;
|
|
33
|
+
console.log(JSON.stringify(result));
|
|
34
|
+
result.meta.result.results.forEach(item => {
|
|
35
|
+
labels.push(item[columns[0]]);
|
|
36
|
+
data.push(parseFloat(item[columns[1]]));
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Create the bar chart
|
|
40
|
+
const ctx = document.getElementById('myChart').getContext('2d');
|
|
41
|
+
const myChart = new Chart(ctx, {
|
|
42
|
+
type: type,
|
|
43
|
+
data: {
|
|
44
|
+
labels: labels,
|
|
45
|
+
datasets: [{
|
|
46
|
+
label: title,
|
|
47
|
+
data: data,
|
|
48
|
+
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
|
49
|
+
borderColor: 'rgba(75, 192, 192, 1)',
|
|
50
|
+
borderWidth: 1
|
|
51
|
+
}]
|
|
52
|
+
},
|
|
53
|
+
options: {
|
|
54
|
+
responsive: true,
|
|
55
|
+
plugins: {
|
|
56
|
+
legend: {
|
|
57
|
+
position: 'top',
|
|
58
|
+
},
|
|
59
|
+
title: {
|
|
60
|
+
display: true,
|
|
61
|
+
text: title
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
scales: {
|
|
65
|
+
y: {
|
|
66
|
+
beginAtZero: true
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
})
|
|
72
|
+
.catch(error => console.error('Error fetching data:', error));
|
|
73
|
+
|
|
74
|
+
</script>
|
|
75
|
+
</body>
|
|
76
|
+
</html>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<title>Sales by Region</title>
|
|
8
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<h1>Sales by Region</h1>
|
|
12
|
+
<p>This page displays a bar chart of sales by region.</p>
|
|
13
|
+
|
|
14
|
+
<div style="display: flex; flex-direction: row; width: 50%; height: 100vh;">
|
|
15
|
+
<iframe id="iframeTarget1" src="http://localhost:5656/sales_by_region" style="flex: 1; border: none;"></iframe>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Sales by Region</title>
|
|
7
|
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
align-items: center;
|
|
15
|
+
height: 100%;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
}
|
|
18
|
+
canvas {
|
|
19
|
+
display: block;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<canvas id="salesChart" width="200" height="200"></canvas>
|
|
25
|
+
<script>
|
|
26
|
+
const labels = [];
|
|
27
|
+
const data = [];
|
|
28
|
+
result = {{ result | tojson }};
|
|
29
|
+
console.log(result);
|
|
30
|
+
const type = result.chart_type;
|
|
31
|
+
const title = result.title;
|
|
32
|
+
const columns = result.columns;
|
|
33
|
+
console.log(JSON.stringify(result));
|
|
34
|
+
result.results.forEach(item => {
|
|
35
|
+
labels.push(item[columns[0]]);
|
|
36
|
+
data.push(parseFloat(item[columns[1]]));
|
|
37
|
+
});
|
|
38
|
+
const ctx = document.getElementById('salesChart').getContext('2d');
|
|
39
|
+
const salesChart = new Chart(ctx, {
|
|
40
|
+
type: type,
|
|
41
|
+
data: {
|
|
42
|
+
labels: labels,
|
|
43
|
+
datasets: [{
|
|
44
|
+
label: title,
|
|
45
|
+
data: data,
|
|
46
|
+
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
|
47
|
+
borderColor: 'rgba(75, 192, 192, 1)',
|
|
48
|
+
borderWidth: 1
|
|
49
|
+
}]
|
|
50
|
+
},
|
|
51
|
+
options: {
|
|
52
|
+
responsive: true,
|
|
53
|
+
maintainAspectRatio: false,
|
|
54
|
+
scales: {
|
|
55
|
+
y: {
|
|
56
|
+
beginAtZero: true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
</script>
|
|
62
|
+
</body>
|
|
63
|
+
</html>
|