Current Query:
with
report as (
select * from Report_Data
where type = 'pnl'
and (created_at > '2020-01-01' or updated_at > '2020-01-01')
),
flattened as (
select
report.company_ID as "CID",
report.type,
report.from_date as "Report_Date",
f.*
--f.value:"title"
from report,
lateral flatten(input =>prepared:profitAndLoss:report:sections) f
--,lateral flatten(input =>f.value)f1
)
select * from flattened where CID = 908 limit 100;
Current Output for f:
[
{
"rows": [
{
"emphasize": false,
"name": "Product Sales",
"values": [
{
"rawValue": 19889.16,
"value": "19,889"
},
{
"rawValue": 56181.94,
"value": "56,182"
}
]
},
{
"emphasize": false,
"name": "Credits from Vendors",
"values": [
{
"rawValue": 38,
"value": "38"
},
{
"rawValue": 47.16,
"value": "47"
}
]
},
{
"emphasize": false,
"name": "Sales - PayPal",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 275,
"value": "275"
}
]
},
{
"emphasize": false,
"name": "Sales Returns and Allowances",
"values": [
{
"rawValue": -379.28,
"value": "(379)"
},
{
"rawValue": -941.78,
"value": "(942)"
}
]
}
],
"summary": {
"emphasize": false,
"name": "Total Revenue",
"values": [
{
"rawValue": 19547.88,
"value": "19,548"
},
{
"rawValue": 55562.32,
"value": "55,562"
}
]
},
"title": "Revenue"
},
{
"rows": [
{
"emphasize": false,
"name": "Product Costs",
"values": [
{
"rawValue": 9857.22,
"value": "9,857"
},
{
"rawValue": 31907.32,
"value": "31,907"
}
]
},
{
"emphasize": false,
"name": "Supplies",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 109.92,
"value": "110"
}
]
}
],
"summary": {
"emphasize": false,
"name": "Total Cost of Sales",
"values": [
{
"rawValue": 9857.22,
"value": "9,857"
},
{
"rawValue": 32017.24,
"value": "32,017"
}
]
},
"title": "Less Cost of Sales"
},
{
"rows": [
{
"emphasize": true,
"name": "Gross Profit",
"values": [
{
"rawValue": 9690.66,
"value": "9,691"
},
{
"rawValue": 23545.08,
"value": "23,545"
}
]
}
],
"summary": {
"name": "",
"values": []
},
"title": ""
},
{
"rows": [
{
"emphasize": false,
"name": "Advertising & Marketing",
"values": [
{
"rawValue": 100,
"value": "100"
},
{
"rawValue": 100,
"value": "100"
}
]
},
{
"emphasize": false,
"name": "Advertising Expenses",
"values": [
{
"rawValue": 22,
"value": "22"
},
{
"rawValue": 689,
"value": "689"
}
]
},
{
"emphasize": false,
"name": "Bank Fees",
"values": [
{
"rawValue": 53,
"value": "53"
},
{
"rawValue": 53,
"value": "53"
}
]
},
{
"emphasize": false,
"name": "Business Telephone and Internet",
"values": [
{
"rawValue": 10.08,
"value": "10"
},
{
"rawValue": 30.24,
"value": "30"
}
]
},
{
"emphasize": false,
"name": "Charitable Contributions",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": -81.89,
"value": "(82)"
}
]
},
{
"emphasize": false,
"name": "Computer and Software Expense",
"values": [
{
"rawValue": 20,
"value": "20"
},
{
"rawValue": 20,
"value": "20"
}
]
},
{
"emphasize": false,
"name": "Dues and Subscriptions",
"values": [
{
"rawValue": 0.99,
"value": "1"
},
{
"rawValue": 135.99,
"value": "136"
}
]
},
{
"emphasize": false,
"name": "Fees and Licenses",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 50,
"value": "50"
}
]
},
{
"emphasize": false,
"name": "Insurance Expense - General Liability",
"values": [
{
"rawValue": 101.6,
"value": "102"
},
{
"rawValue": 304.8,
"value": "305"
}
]
},
{
"emphasize": false,
"name": "Legal & Professional",
"values": [
{
"rawValue": 200,
"value": "200"
},
{
"rawValue": 600,
"value": "600"
}
]
},
{
"emphasize": false,
"name": "Merchant Account Fees",
"values": [
{
"rawValue": 444.91,
"value": "445"
},
{
"rawValue": 1221.71,
"value": "1,222"
}
]
},
{
"emphasize": false,
"name": "Office Expenses",
"values": [
{
"rawValue": 169.66,
"value": "170"
},
{
"rawValue": 988.42,
"value": "988"
}
]
},
{
"emphasize": false,
"name": "Payroll Processing Fee",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 0.45,
"value": "0"
}
]
},
{
"emphasize": false,
"name": "Rent",
"values": [
{
"rawValue": 1500,
"value": "1,500"
},
{
"rawValue": 6000,
"value": "6,000"
}
]
},
{
"emphasize": false,
"name": "Taxes",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 3000,
"value": "3,000"
}
]
},
{
"emphasize": false,
"name": "Travel",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 194.35,
"value": "194"
}
]
},
{
"emphasize": false,
"name": "Utilities",
"values": [
{
"rawValue": 559.59,
"value": "560"
},
{
"rawValue": 1769.63,
"value": "1,770"
}
]
}
],
"summary": {
"emphasize": false,
"name": "Total Operating Expenses",
"values": [
{
"rawValue": 3181.83,
"value": "3,182"
},
{
"rawValue": 15075.7,
"value": "15,076"
}
]
},
"title": "Operating Expenses"
},
{
"rows": [
{
"emphasize": false,
"name": "Operating Income / (Loss)",
"values": [
{
"rawValue": 6508.83,
"value": "6,509"
},
{
"rawValue": 8469.38,
"value": "8,469"
}
]
}
],
"summary": {
"name": "",
"values": []
},
"title": ""
},
{
"rows": [
{
"emphasize": false,
"name": "Interest",
"values": [
{
"rawValue": -85.44,
"value": "(85)"
},
{
"rawValue": -434.74,
"value": "(435)"
}
]
},
{
"emphasize": false,
"name": "Interest Income",
"values": [
{
"rawValue": 0.57,
"value": "1"
},
{
"rawValue": 1.24,
"value": "1"
}
]
},
{
"emphasize": false,
"name": "Other Income",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 100,
"value": "100"
}
]
}
],
"summary": {
"emphasize": false,
"name": "Total Other Income and Expense",
"values": [
{
"rawValue": -84.87,
"value": "(85)"
},
{
"rawValue": -333.5,
"value": "(334)"
}
]
},
"title": "Other Income and Expense"
},
{
"rows": [
{
"emphasize": true,
"name": "Net Income / (Loss) before Tax",
"values": [
{
"rawValue": 6423.96,
"value": "6,424"
},
{
"rawValue": 8135.88,
"value": "8,136"
}
]
}
],
"summary": {
"name": "",
"values": []
},
"title": ""
},
{
"rows": [
{
"emphasize": false,
"name": "Net Income",
"values": [
{
"rawValue": 6423.96,
"value": "6,424"
},
{
"rawValue": 8135.88,
"value": "8,136"
}
]
}
],
"summary": {
"name": "",
"values": []
},
"title": ""
},
{
"rows": [
{
"emphasize": false,
"name": "Total Comprehensive Income",
"values": [
{
"rawValue": 6423.96,
"value": "6,424"
},
{
"rawValue": 8135.88,
"value": "8,136"
}
]
}
],
"summary": {
"name": "",
"values": []
},
"title": ""
}
]
https://codebeautify.org/jsonviewer
Recommend c/p JSON into above link and selecting "tree viewer" to follow along with my navigation references
Problem:
Snowflake/ASNI SQL:
For each index in the array I need to evaluate a logical function that checks the "title" key, and if the value of the "title" key is X (for the sake of this exercise let's choose "Revenue"), return the "name" and "values" for each index of the "rows" key. Under rows:values you have 2 Values. They need to be re-keyed to MTD and YTD. They are consistently stored as [0]:MTD and [1]:YTD. I want these new keys to appear in a column I have named "periodicity." I know this is all one tricky flattening problem in snowflake, but I struggled with it all weekend in many different iterations and would like to see if someone can give it a shot. Thanks for the help!
Desired Output:
CID, TYPE, REPORT_DATE, "Title" Key, rows:Name as "Name", periodicity, rows:values:[0]:rawValue
EDIT: Sample output columns with values:
CID TYPE REPORT_DATE "Title" Key rows:Name as "Name"
47 PNL 2020-01-01 REVENUE "Sales - PayPal"
periodicity rows:values:[0]:rawValue
"MTD" 0
So the flatten is not too hard. If you take it step at a time:
with random_json as (
select '2020-05-27'::date as report_date, parse_json('[
{
"rows": [
{
"emphasize": false,
"name": "Product Sales",
"values": [
{
"rawValue": 19889.16,
"value": "19,889"
},
{
"rawValue": 56181.94,
"value": "56,182"
}
]
},
{
"emphasize": false,
"name": "Credits from Vendors",
"values": [
{
"rawValue": 38,
"value": "38"
},
{
"rawValue": 47.16,
"value": "47"
}
]
},
{
"emphasize": false,
"name": "Sales - PayPal",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 275,
"value": "275"
}
]
},
{
"emphasize": false,
"name": "Sales Returns and Allowances",
"values": [
{
"rawValue": -379.28,
"value": "(379)"
},
{
"rawValue": -941.78,
"value": "(942)"
}
]
}
],
"summary": {
"emphasize": false,
"name": "Total Revenue",
"values": [
{
"rawValue": 19547.88,
"value": "19,548"
},
{
"rawValue": 55562.32,
"value": "55,562"
}
]
},
"title": "Revenue"
},
{
"rows": [
{
"emphasize": false,
"name": "Product Costs",
"values": [
{
"rawValue": 9857.22,
"value": "9,857"
},
{
"rawValue": 31907.32,
"value": "31,907"
}
]
},
{
"emphasize": false,
"name": "Supplies",
"values": [
{
"rawValue": 0,
"value": "0"
},
{
"rawValue": 109.92,
"value": "110"
}
]
}
],
"summary": {
"emphasize": false,
"name": "Total Cost of Sales",
"values": [
{
"rawValue": 9857.22,
"value": "9,857"
},
{
"rawValue": 32017.24,
"value": "32,017"
}
]
},
"title": "Less Cost of Sales"
}
]') as json
), flatten_a AS (
select
r.report_date
,f.value:rows as r_rows
,f.value:summary as r_summary
,f.value:title as r_title
from random_json r
,lateral flatten(input=>r.json) f
), flatten_b AS (
select a.*
, f.value:name as rr_name
, f.value:values as rr_values
from flatten_a a
,lateral flatten(input=>a.r_rows) f
)
select b.report_date
,b.r_title as title_key
,b.rr_name as name
,case when f.index =0 then 'MTD' when f.index=1 then 'YTD' else 'WTF' end as periodicity
, f.value:rawValue raw_value
from flatten_b b
,lateral flatten(input=>b.rr_values) f;
gives:
REPORT_DATE TITLE_KEY NAME PERIODICITY RAW_VALUE
2020-05-27 "Revenue" "Product Sales" MTD 19889.16
2020-05-27 "Revenue" "Product Sales" YTD 56181.94
2020-05-27 "Revenue" "Credits from Vendors" MTD 38
2020-05-27 "Revenue" "Credits from Vendors" YTD 47.16
2020-05-27 "Revenue" "Sales - PayPal" MTD 0
2020-05-27 "Revenue" "Sales - PayPal" YTD 275
2020-05-27 "Revenue" "Sales Returns and Allowances" MTD -379.28
2020-05-27 "Revenue" "Sales Returns and Allowances" YTD -941.78
2020-05-27 "Less Cost of Sales" "Product Costs" MTD 9857.22
2020-05-27 "Less Cost of Sales" "Product Costs" YTD 31907.32
2020-05-27 "Less Cost of Sales" "Supplies" MTD 0
2020-05-27 "Less Cost of Sales" "Supplies" YTD 109.92
if what you mention in the first sentence as only wanting the above rows for "Revenue" make the results set a CTE also, and left join to your "report" and ON filter for revenue.
Related
I am needing to unnest a multidimensional array with multiple items.
My data looks like this (two rows):
Each order in this table has a fulfillments column which is a multidimensional array.
fulfilments has multiple line_items. Some orders only have 1 line_items, some orders have multiple line_items.
My goal is to get each product name and the quantity from each line_items and do a running sum/tally.
Here's a JSON export of the fulfillments column data:
"{
"fulfillments": [{
"value": {
"id": "6575674745",
"tracking_number": null,
"line_items": [{
"value": {
"properties": [{
"value": {
"name": "shipping_interval_unit_type",
"value": "Months"
}
}, {
"value": {
"name": "shipping_interval_frequency",
"value": "1"
}
}, {
"value": {
"name": "ch_item_id",
"value": "77321530"
}
}],
"product_id": "4790985097351",
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"sku": “10101”,
"name": “Product1”,
"variant_id": "33433213108359",
"quantity": "1",
"taxable": "true",
"total_discount": "0",
"title": "Product1 Title",
"price_set": {
"shop_money": {
"amount": "12.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "12.00",
"currency_code": "USD"
}
},
"product_exists": "true"
}
}],
"service": "manual",
"tracking_urls": []
}
}, {
"value": {
"tracking_url": null,
"id": "3555531128967",
"tracking_company": null,
"tracking_number": null,
"name": "#3129472402.2",
"tracking_numbers": [],
"line_items": [{
"value": {
"properties": [{
"value": {
"name": "shipping_interval_frequency",
"value": "1"
}
}, {
"value": {
"name": "shipping_interval_unit_type",
"value": "Months"
}
}, {
"value": {
"name": "ch_item_id",
"value": "77321529"
}
}],
"product_id": "5216409780359",
"total_discount_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"sku": "9005",
"name": “Product2”,
"quantity": "1",
"title": “Product2 Title”,
"price_set": {
"shop_money": {
"amount": "0.00",
"currency_code": "USD"
},
"presentment_money": {
"amount": "0.00",
"currency_code": "USD"
}
},
"product_exists": "true"
}
}],
"service": "manual",
"tracking_urls": []
}
}]
}"
SELECT
fulfillments[ safe_OFFSET (0)].value.line_items[ safe_OFFSET (0)].value.name AS name,
fulfillments[ safe_OFFSET (0)].value.line_items[ safe_OFFSET (0)].value.quantity AS quantity
FROM
`mydatabase`
isn't ideal in the event the order has more than one array in line_items
How can I unnest a multidimensional array when I don't know how large each array is?
SELECT
*
FROM
`mydatabase`,
UNNEST(fulfillments) as a
Only gives me another array to flatten
Given your scenario, you may try to use this query to unnest line_items with product name and the quantity:
SELECT
line_items.value.name,
line_items.value.quantity,
line_items.value.product_id
from `mydatabase`,
unnest(fulfillments) fulfillments,
unnest(fulfillments.value.line_items) line_items
Output:
I am trying to convert JSON into an SQL table. The source is the response from a REST API. I do not have the opportunity to change the response.
The response contains data on several projects. Projects are returned as individual members of a global projects object.
As the projectid is not at the same level with the other data and also does not have a name
SELECT * FROM OPENJSON (#JSON);
fails to parse it properly. I end up with one row for projects and the json object as the value. Also without the proper way to refer to the elements I could not figure out a way to use JSON_VALUE.
Below is a sample structure. Actual data has much more properties and variations between the projects. I prefer to solve this in SQL. But any way to sort out the JSON will be appreciated. This is my first exposure to JSON. I want to ask if I am missing something very obvious...
TIA
{
"projects": {
"project1id": {
"data": {
"customer": "Cust1",
"name": "Project Name 1"
},
"projectType": "type0"
},
"project2id": {
"data": {
"customer": "Customer 2",
"name": "Name 2",
"projectManager": "Man Ager"
},
"projectType": "type2"
},
"Project3id": {
"data": {
"customer": "Another Customer",
"name": "Another Project"
},
"projectType": "type1"
}
}
}
Expected Result
ProjectId
Project Name
Customer
Project Type
Project Manager
project1id
Project Name 1
Cust 1
type0
project2id
Customer 2
type2
Man Ager
project3id
Another Project
Another Customer
type1
Excerpt from original Json:
{
"projects": {
"10000eumbvqn76": {
"data": {
"inquiryNumber": "34635",
"customer": "C AS",
"name": "E W ",
"orderNumber": "1000",
"seller": "M A",
"projectManager": "B O V",
"phase": "fulfillment",
"exchange": {
"deadline": {
"time": [
24,
0
],
"timezone": [
1,
0
]
},
"settings": {
"client": {
"codes": [
{
"id": "1",
"label": "Code 1"
},
{
"id": "4",
"label": "Code 4"
},
{
"id": "5",
"label": "Code 5"
},
{
"id": "2",
"label": "Code 2"
},
{
"id": "3",
"label": "Code 3"
}
],
"approvedCodes": [
"1"
],
"cycles": {
"producer": 21,
"consumer": 21
}
},
"clientForInformation": {
"cycles": {
"producer": 21
}
},
"supplier": {
"codes": [
{
"id": "1",
"label": "Code 1"
},
{
"id": "4",
"label": "Code 4"
},
{
"id": "5",
"label": "Code 5"
},
{
"id": "2",
"label": "Code 2"
},
{
"id": "3",
"label": "Code 3"
}
],
"approvedCodes": [
"1"
],
"cycles": {
"producer": 14,
"consumer": 14
}
},
"supplierIsProducer": {
"supplierRole": "producer"
},
"supplierIsConsumer": {
"supplierRole": "consumer"
}
},
"sequences": {
"$salesPurchase": {
"label": "Client RFQ to OC",
"settings": "supplierIsProducer",
"group": "inquiry"
},
"$salesPurchaseSupplier": {
"label": "Supplier RFQ to OC",
"settings": "supplierIsConsumer",
"group": "inquiry"
},
"$salesClient": null,
"$salesClientFrom": null,
"$client": {
"label": "To client",
"group": "order-fulfillment",
"order": [
"IFR",
"IFI"
],
"stages": {
"IFR": {
"label": "Issued for Review",
"phase": "forApproval",
"settings": "client"
},
"IFI": {
"label": "Issued for Information",
"phase": "forInformation",
"settings": "clientForInformation"
}
},
"interpret": {
"type": "unordered"
}
},
"$supplier": {
"label": "From supplier",
"group": "order-fulfillment-supplier",
"settings": "supplier"
},
"$supplierTo": {
"label": "To supplier",
"group": "order-fulfillment-supplier",
"settings": "supplierIsConsumer"
},
"$internal": null
}
},
"officialMailIdFormat": "M-1000-0001",
"transmittalMailIdFormat": "TR-1000-0001",
"commercialMailIdFormat": "Bid-34635-0001",
"officialMailIdFormats": [
{
"label": "Official",
"format": "M-1000-0001"
},
{
"label": "Commercial",
"format": "Bid-34635-0001"
}
]
},
"projectType": "commercial"
},
"1000hf30ua": {
"data": {
"inquiryNumber": "100",
"customer": "S M I Y P L",
"name": "1000 FSPO ",
"seller": "L H",
"projectManager": "L H",
"phase": "inquiry",
"exchange": {
"deadline": {
"time": [
24,
0
],
"timezone": [
1,
0
]
},
"settings": {
"client": {
"codes": [
{
"id": "1",
"label": "Code 1"
},
{
"id": "4",
"label": "Code 4"
},
{
"id": "5",
"label": "Code 5"
},
{
"id": "2",
"label": "Code 2"
},
{
"id": "3",
"label": "Code 3"
}
],
"approvedCodes": [
"1"
],
"cycles": {
"producer": 21,
"consumer": 21
}
},
"clientForInformation": {
"cycles": {
"producer": 21
}
},
"supplier": {
"codes": [
{
"id": "1",
"label": "Code 1"
},
{
"id": "4",
"label": "Code 4"
},
{
"id": "5",
"label": "Code 5"
},
{
"id": "2",
"label": "Code 2"
},
{
"id": "3",
"label": "Code 3"
}
],
"approvedCodes": [
"1"
],
"cycles": {
"producer": 14,
"consumer": 14
}
},
"supplierIsProducer": {
"supplierRole": "producer"
},
"supplierIsConsumer": {
"supplierRole": "consumer"
}
},
"sequences": {
"$salesPurchase": {
"label": "Client RFQ to OC",
"settings": "supplierIsProducer",
"group": "inquiry"
},
"$salesPurchaseSupplier": {
"label": "Supplier RFQ to OC",
"settings": "supplierIsConsumer",
"group": "inquiry"
},
"$salesClient": null,
"$salesClientFrom": null,
"$client": {
"label": "To client",
"group": "order-fulfillment",
"order": [
"IFR",
"IFI"
],
"stages": {
"IFR": {
"label": "Issued for Review",
"phase": "forApproval",
"settings": "client"
},
"IFI": {
"label": "Issued for Information",
"phase": "forInformation",
"settings": "clientForInformation"
}
},
"interpret": {
"type": "unordered"
}
},
"$supplier": {
"label": "From supplier",
"group": "order-fulfillment-supplier",
"settings": "supplier"
},
"$supplierTo": {
"label": "To supplier",
"group": "order-fulfillment-supplier",
"settings": "supplierIsConsumer"
},
"$internal": null
}
},
"officialMailIdFormat": "M-100-0001",
"transmittalMailIdFormat": "TR-100-0001",
"commercialMailIdFormat": "Bid-100-0001",
"officialMailIdFormats": [
{
"label": "Official",
"format": "M-100-0001"
},
{
"label": "Commercial",
"format": "Bid-100-0001"
}
],
"orderNumber": "100"
},
"projectType": "commercial"
}
}
}
Possible options are: 1) Using OPENJSON() twice (with default and explicit schema) and an additional APPLY operator or 2) Using OPENJSON() (with default schema) and JSON_VALUE():
JSON:
DECLARE #json nvarchar(max) = N'{
"projects":{
"project1id":{
"data":{
"customer":"Cust1",
"name":"Project Name 1"
},
"projectType":"type0"
},
"project2id":{
"data":{
"customer":"Customer 2",
"name":"Name 2",
"projectManager":"Man Ager"
},
"projectType":"type2"
},
"Project3id":{
"data":{
"customer":"Another Customer",
"name":"Another Project"
},
"projectType":"type1"
}
}
}'
Statement with OPENJSON() and APPLY operator:
SELECT j1.[key] AS projectId, j2.*
FROM OPENJSON(#json, '$.projects') j1
CROSS APPLY OPENJSON(j1.[value], '$') WITH (
name nvarchar(100) '$.data.name',
customer nvarchar(100) '$.data.customer',
projectType nvarchar(100) '$.projectType',
projectManager nvarchar(100) '$.data.projectManager'
) j2
Statement with OPENJSON() and JSON_VALUE():
SELECT
projectId = [key],
name = JSON_VALUE([value], '$.data.name'),
customer = JSON_VALUE([value], '$.data.customer'),
projectType = JSON_VALUE([value], '$.projectType'),
projectManager = JSON_VALUE([value], '$.data.projectManager')
FROM OPENJSON(#json, '$.projects')
I am using bot framework v4. I have developed a chatbot using .Net Core. The bot is integrated with LUIS and Qna Maker. One issue I am facing is that the bot duplicates the message that comes from the user. Please look at the screenshot below:
The replies I get from the bot are perfectly fine. The flow of the bot is as intended. I just cannot figure out why the message from user is being duplicated. I am using DirectLine for this. I will share whatever code part is needed.
{
"activities": [
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000000",
"timestamp": "2019-12-02T19:41:57.1284328Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"content": {
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "Container",
"items": [
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "Image",
"size": "large",
"url": "https://i.imgur.com/ViaEUnA.png"
}
]
}
],
"horizontalAlignment": "Center"
},
{
"type": "ColumnSet",
"columns": [
{
"type": "Column",
"width": "auto",
"items": [
{
"type": "TextBlock",
"size": "large",
"weight": "bolder",
"color": "light",
"text": "Welcome to CIVIC Financial Services",
"wrap": true
},
{
"type": "TextBlock",
"size": "large",
"weight": "bolder",
"color": "light",
"text": "I am S.U.E",
"wrap": true
},
{
"type": "TextBlock",
"color": "light",
"text": "I can help you answer your questions. Familiarize yourself with CIVIC Financial Services.",
"wrap": true
},
{
"type": "TextBlock",
"color": "light",
"text": "If you want to talk to a Customer Service Agent, just type \"I want to talk to a Customer Service Agent\".",
"wrap": true
}
],
"separator": true,
"horizontalAlignment": "Left"
}
]
}
]
}
],
"actions": [
{
"type": "Action.Submit",
"data": {
"action": "aboutCivic"
},
"title": "About CIVIC"
},
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"actions": [
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "We are open from Monday through Friday from 8:00am to 6:00pm.",
"wrap": true
}
],
"style": "emphasis"
},
"title": "When are you open?"
},
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "Image",
"size": "stretch",
"url": "https://i.imgur.com/gBVgI25.png",
"horizontalAlignment": "center"
},
{
"type": "TextBlock",
"text": "AZ, CA, CO, FL, GA, HI, NC, NV, OR, SC, TN, TX, UT, VA & WA",
"wrap": true
}
],
"style": "emphasis"
},
"title": "Do you have an office near me? "
},
{
"type": "Action.ShowCard",
"card": {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "8 to 10 days, it all depends on how it takes to get access to the property.",
"wrap": true
}
],
"style": "emphasis"
},
"title": "How quickly can we close? "
}
],
"style": "emphasis"
},
"title": "FAQs"
}
]
}
}
],
"entities": [],
"replyToId": "8WGOnspSxN3"
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000001",
"timestamp": "2019-12-02T19:43:39.96502Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "r_1575315715",
"name": "",
"role": "user"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"entities": [
{
"type": "ClientCapabilities",
"requiresBotState": true,
"supportsListening": true,
"supportsTts": true
}
],
"channelData": {
"siteDomain": "https://websiteae1.stackblitz.io/"
}
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000002",
"timestamp": "2019-12-02T19:43:41.7278914Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"text": "Sorry, I didn't understand. Consider rephrasing your question or contacting a customer agent",
"attachments": [],
"entities": [],
"replyToId": "BR1wBZw7w2852JMLobk0EC-o|0000001"
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000003",
"timestamp": "2019-12-02T20:00:25.784598Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "r_1575315715",
"name": "",
"role": "user"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "helo",
"channelData": {
"siteDomain": "https://websiteae1.stackblitz.io/"
}
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000004",
"timestamp": "2019-12-02T20:00:26.5739342Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"text": "Sorry, I didn't understand. Consider rephrasing your question or contacting a customer agent",
"attachments": [],
"entities": [],
"replyToId": "BR1wBZw7w2852JMLobk0EC-o|0000003"
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000005",
"timestamp": "2019-12-02T20:00:27.3293896Z",
"serviceUrl": "https://directline.botframework.com/",
"channelId": "directline",
"from": {
"id": "r_1575315715",
"name": "",
"role": "user"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"textFormat": "plain",
"locale": "en-GB",
"text": "hello",
"channelData": {
"siteDomain": "https://websiteae1.stackblitz.io/"
}
},
{
"type": "message",
"id": "BR1wBZw7w2852JMLobk0EC-o|0000006",
"timestamp": "2019-12-02T20:00:27.6064185Z",
"channelId": "directline",
"from": {
"id": "CivicDevBot",
"name": "CivicChat"
},
"conversation": {
"id": "BR1wBZw7w2852JMLobk0EC-o"
},
"text": "Hello",
"inputHint": "acceptingInput",
"attachments": [],
"entities": [],
"replyToId": "BR1wBZw7w2852JMLobk0EC-o|0000005"
}
],
"watermark": "6"
}
I'm working with vega charts (parallel coordinates). How do I change the color of the lines with respect to scheme colors (w.r.t 'name' field).
Here is my code
I tried changing the stroke property with color scale but there is no effect on line stroke.
Can anyone point out what am I doing wrong.
I'm using Vega Version 4
Thanks
vikky
Because the colors need to be by column "name", transform the input dataset to have repeated name rows. In other words, input dataset must be of 3 columns (name, quarter, value)
Then, change "group" type mark to use facet dataset grouped by column "name"
"name": "marks_group_lines",
"type": "group",
"from": {
"facet": {
"name": "cars_by_name",
"data": "cars",
"groupby": "name"
}
},
Use the cars_by_name as dataset to render "line" type mark.
tip: Instead of defining quarter dataset for 4 axes for each qarter and scales for these axes, "line" type mark which has point scale for "x" property can be used.
Full code for reference:
{
"$schema": "https://vega.github.io/schema/vega/v4.json",
"width": 700,
"height": 400,
"padding": 5,
"config": {
"axisY": {
"titleX": -2,
"titleY": 410,
"titleAngle": 0,
"titleAlign": "right",
"titleBaseline": "top"
}
},
"data": [
{
"name": "cars",
"values": [
{
"name": "A",
"quarter": "Q1",
"value": 51
},
{
"name": "A",
"quarter": "Q2",
"value": 47
},
{
"name": "A",
"quarter": "Q3",
"value": 45
},
{
"name": "A",
"quarter": "Q4",
"value": 30
},
{
"name": "B",
"quarter": "Q1",
"value": 42
},
{
"name": "B",
"quarter": "Q2",
"value": 57
},
{
"name": "B",
"quarter": "Q3",
"value": 72
},
{
"name": "B",
"quarter": "Q4",
"value": 41
},
{
"name": "C",
"quarter": "Q1",
"value": 25
},
{
"name": "C",
"quarter": "Q2",
"value": 37
},
{
"name": "C",
"quarter": "Q3",
"value": 60
},
{
"name": "C",
"quarter": "Q4",
"value": 25
},
{
"name": "D",
"quarter": "Q1",
"value": 22
},
{
"name": "D",
"quarter": "Q2",
"value": 25
},
{
"name": "D",
"quarter": "Q3",
"value": 51
},
{
"name": "D",
"quarter": "Q4",
"value": 42
}
]
},
{
"name": "fields",
"values": [
"Q1",
"Q2",
"Q3",
"Q4"
]
}
],
"scales": [
{
"name": "name_to_xaxis",
"type": "point",
"domain": {
"data": "cars",
"field": "quarter"
},
"range": "width"
},
{
"name": "values_to_height",
"type": "linear",
"domain": {
"data": "cars",
"field": "value"
},
"range": "height"
},
{
"name": "quarter_to_color",
"type": "ordinal",
"domain": {
"data": "cars",
"field": "name"
},
"range": "category"
},
{
"name": "ord",
"type": "point",
"range": "width",
"round": true,
"domain": {
"data": "fields",
"field": "data"
}
},
{
"name": "Q1",
"type": "linear",
"range": "height",
"zero": false,
"nice": true,
"domain": {
"data": "cars",
"field": "Q1"
}
},
{
"name": "Q2",
"type": "linear",
"range": "height",
"zero": false,
"nice": true,
"domain": {
"data": "cars",
"field": "Q2"
}
},
{
"name": "Q3",
"type": "linear",
"range": "height",
"zero": false,
"nice": true,
"domain": {
"data": "cars",
"field": "Q3"
}
},
{
"name": "Q4",
"type": "linear",
"range": "height",
"zero": false,
"nice": true,
"domain": {
"data": "cars",
"field": "Q4"
}
}
],
"axes": [
{
"orient": "left",
"zindex": 1,
"scale": "Q1",
"title": "Q1",
"ticks": false,
"labels": false,
"offset": {
"scale": "ord",
"value": "Q1",
"mult": -1
}
},
{
"orient": "left",
"zindex": 1,
"scale": "Q2",
"title": "Q2",
"ticks": false,
"labels": false,
"offset": {
"scale": "ord",
"value": "Q2",
"mult": -1
}
},
{
"orient": "left",
"zindex": 1,
"scale": "Q3",
"title": "Q3",
"ticks": false,
"labels": false,
"offset": {
"scale": "ord",
"value": "Q3",
"mult": -1
}
},
{
"orient": "left",
"zindex": 1,
"scale": "Q4",
"title": "Q4",
"ticks": false,
"labels": false,
"offset": {
"scale": "ord",
"value": "Q4",
"mult": -1
}
}
],
"marks": [
{
"name": "marks_group_lines",
"type": "group",
"from": {
"facet": {
"name": "cars_by_name",
"data": "cars",
"groupby": "name"
}
},
"marks": [
{
"name": "marks_lines",
"type": "line",
"from": {
"data": "cars_by_name"
},
"encode": {
"update": {
"x": {
"scale": "name_to_xaxis",
"field": "quarter"
},
"y": {
"scale": "values_to_height",
"field": "value"
},
"stroke": {
"scale": "quarter_to_color",
"field": "name"
},
"strokeOpacity": {
"value": 1
}
},
"hover": {
"stroke": {
"value": "#7c7c7c"
},
"strokeOpacity": {
"value": 1
},
"zindex": 99
}
}
},
{
"name": "marks_symbols",
"type": "symbol",
"from": {
"data": "cars_by_name"
},
"encode": {
"enter": {
"stroke": {
"value": "#6D6D6D"
},
"strokeWidth": {
"value": 1
},
"shape": {
"value": "circle"
}
},
"update": {
"x": {
"scale": "name_to_xaxis",
"field": "quarter"
},
"y": {
"scale": "values_to_height",
"field": "value"
},
"fill": {
"scale": "quarter_to_color",
"field": "name"
},
"size": {
"value": 50
},
"stroke": {
"value": "#77AE80"
}
},
"hover": {
"fill": {
"value": "#AFD098"
}
}
}
}
]
}
]
}
I am using Extjs tree, i got problem with click on nested node ajax request to server, i know this kind of lazy load but my tree is not big, around 35 items so i want request to server time only to collect all tree node and items.
Any idea?
View:
Ext.define('CRM.view.role.RoleTree' ,{
extend: 'Ext.tree.Panel',
alias: 'widget.roleTreeList',
id:'tree-role-panel',
split: false,
autoScroll: true,
lines: true,
singleExpand: false,
store: 'RoleList'
})
Store:
Ext.define('CRM.store.RoleList', {
extend: 'Ext.data.TreeStore',
storeId: 'RoleTreeStoreId',
//model: 'CRM.model.RoleList',
autoLoad: false,
proxy: {
type : 'ajax',
url : 'index.php/role/getRoleList',
async : false,
reader: {
type : 'json',
method : 'POST'
}
},
root:{
expanded:true,
text:"Organization",
leaf:'false',
id : '/',
}
})
Json return:
{
"text": "Organization",
"id": "role-1",
"children": [
{
"text": "Admin",
"id": "role-12",
"expanded": "true",
"children": [
{
"text": "MSD",
"id": "role-23",
"children": [
{
"text": "Customer Care Manager",
"id": "role-4",
"children": [
{
"text": "Customer Care Adviser",
"id": "role-5"
}
]
},
{
"text": "Solution Adviser",
"id": "role-7"
},
{
"text": "Sales Manager",
"id": "role-31",
"children": [
{
"text": "Solution Sales",
"id": "role-6"
},
{
"text": "Teritory 01 - Safy",
"id": "role-9",
"children": [
{
"text": "Sales Person 01",
"id": "role-10"
},
{
"text": "Sales Trainee 01",
"id": "role-26"
}
]
},
{
"text": "Teritory 3 - Sambo",
"id": "role-11",
"children": [
{
"text": "Sales Person 3",
"id": "role-13"
}
]
},
{
"text": "Teritory 4 - Narong",
"id": "role-14",
"children": [
{
"text": "Sales Team 4",
"id": "role-15",
"children": [
{
"text": "Sales Person 4",
"id": "role-25"
}
]
}
]
},
{
"text": "branch shv",
"id": "role-16",
"children": [
{
"text": "sales shv",
"id": "role-19"
}
]
},
{
"text": "branch btb",
"id": "role-17",
"children": [
{
"text": "sales btb",
"id": "role-20"
}
]
},
{
"text": "branch srp",
"id": "role-18",
"children": [
{
"text": "sales srp",
"id": "role-21",
"children": [
{
"text": "sales person srp",
"id": "role-28"
}
]
}
]
},
{
"text": "Retention Program",
"id": "role-22",
"children": [
{
"text": "Retention Program Analysist",
"id": "role-24"
}
]
},
{
"text": "Sales Trainee",
"id": "role-27"
},
{
"text": "Enterprise Sales Engineer",
"id": "role-29"
},
{
"text": "Meas Test",
"id": "role-30"
},
{
"text": "Teritory 02 - Kol",
"id": "role-32",
"children": [
{
"text": "Sales Person 02",
"id": "role-8"
}
]
}
]
}
]
},
{
"text": "CTO",
"id": "role-35",
"children": [
{
"text": "Support Manager",
"id": "role-2",
"children": [
{
"text": "Technical Support Adviser",
"id": "role-3"
}
]
},
{
"text": "IT BIlling Product Manager",
"id": "role-33",
"children": [
{
"text": "IT Staff",
"id": "role-34"
}
]
}
]
},
{
"text": "Business Consultant",
"id": "role-36"
}
]
}
]
}
You can still use asynchronous call, but only once. To make sure only one call is made, return all children in first call. Extjs will load all children provided.
I found my mistake with JSON, i should add property "leaf = true/false" according has child or hasn't.