Great Expectations Row Based Dimensions - dbt

I have data like this:
[ {
"name": "Apple",
"price": 1,
"type": "Food"
},
{
"name": "Apple",
"price": 0.90,
"type": "Food"
},
{
"name": "Apple",
"price": 1000,
"type": "Computer"
},
{
"name": "Apple",
"price": 900,
"type": "Computer"
}
]
Using the Great Expectations automatic profile, a valid range for price would be 0.90 to 1,000. Is it possible to have it slice on the type dimension, so food would be 0.90 to 1 and computer would be 900 to 1000? Or would I need to transform the data first using dbt? I know the column that will create the dimension, but I don't know the particular values.
Also, same question on differences between rows. Like if they had a timestamp, instead of 900 to 1000, it validates -100 for the change in value.

I used this approach to first load the data in a pandas data frame:
https://discuss.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/2

Related

Double Discounted Lines in Shopify Order API

I came across a situation that I hope someone else has seen.
The order looks like this in shopify:
The Discounted Line Item JSON looks like this:
{
"id": XXXXX,
"name": "NAME",
"price": "19.10",
"product_exists": true,
"quantity": 1,
"sku": "SKU",
"total_discount": "9.55",
"discount_allocations": [
{
"amount": "9.55",
"amount_set": {
"shop_money": {
"amount": "9.55",
"currency_code": "USD"
},
"presentment_money": {
"amount": "9.55",
"currency_code": "USD"
}
},
"discount_application_index": 0
}
]
},
An Automatic Discount as a "BOGO at 50% off" was applied to this order, but I cant quite get the discounting right for a net unit price, without also causing issues elsewhere in this particular Shopify Tenant.
Previously I would
line_unit_price = price - (TotalDiscount/Quantity) - SumOfDiscountApplications
But in this case, that would just double discount it to zero, which is not correct. In other cases with this Shopify Tenant, I do need to use the Discount Applications as TotalDiscount would be 0. I cant quite figure out when/where/why to do the math differently for an effective Line Net Unit Price.
Very odd. Any help would be great.

Django rest_framework dynamic selecting other objects

i want to create an Api for an order system. I have Ingredients and Products, both have categories which have to match if you want to combine them. So if a user selects a Pizza how can I only load in the ingredients which are available for Pizza, so the user cant select pasta as a Topping on his Pizza.
So if the User selects a Product pizza in extra and extraWo only the ingredients should show up, which are available for pizza
Thank you for your help
Depending on the API structure.
For example:
[
{
"Crust": "NORMAL",
"Flavor": "BEEF-NORMAL",
"Order_ID": 1,
"Size": "M",
"Table_No": 1,
"Timestamp": "2018-12-12T13:42:13.704148+00:00"
},
{
"Crust": "THIN",
"Flavor": "CHEESE",
"Order_ID": 2,
"Size": "S",
"Table_No": 5,
"Timestamp": "2018-12-12T13:42:13.704148+00:00"
},
{
"Crust": "NORMAL",
"Flavor": "CHICKEN-FAJITA",
"Order_ID": 3,
"Size": "L",
"Table_No": 3,
"Timestamp": "2018-12-12T13:42:13.720690+00:00"
}
]
Each pizza would be unique so foo[1]["Crust"] will give you "Normal". Add logic like checking the availability. Have a look at https://docs.djangoproject.com/en/3.1/topics/db/queries/#querying-jsonfield
For example do:
object.filter(pizza__normal='available')

Capturing Choice set values from the adaptive card

I was wondering how can I capture the selected choice sets values in the adaptive card. Is there a way to capture the response after hitting the Action.submit button?
Below you can see, the selection is an array that shows the titles based on the initial logic and creates a Choices array
"body": [{
"type": "TextBlock",
"text": "select the recordings you want to delete"
},
{
"type": "Input.ChoiceSet",
"isMultiSelect": true,
"id": "myColor",
"style": "compact",
"value": "1",
"choices": vars.selection
}
]

Append to Specific Array Index from another table dynamically SQL Server

I have a json string that I need to modify
{"RecordCount":3,"Top":10,"Skip":0,"SelectedSort":"Seed asc","value":[{"AccountProductListId":22091612871138,"Name":"April 4th 2018","AccountId":256813438078643,"IsPublic":false,"Comment":"Test order sheet","Quantity":3},{"AccountProductListId":166305848801939,"Name":"test","AccountId":256813438078643,"IsPublic":false,"Comment":"","Quantity":1},{"AccountProductListId":21177711287586,"Name":"Test Order sheet","AccountId":256813438078643,"IsPublic":true,"Comment":"the very first sheet","Quantity":2}]}
Inside value the array looks like this:
"value": [{
"AccountProductListId": 22091612871138,
"Name": "April 4th 2018",
"IsPublic": false,
"Comment": "Test order sheet",
"Quantity": 3
}, {
"AccountProductListId": 166305848801939,
"Name": "test",
"IsPublic": false,
"Comment": "",
"Quantity": 1
}, {
"AccountProductListId": 21177711287586,
"Name": "Test Order sheet",
"IsPublic": true,
"Comment": "the very first sheet",
"Quantity": 2
}],
What I need to do is append some data from another table:
AccountProductListId ProductID
21177711287586 97096131867163|32721319938943
22091612871138 97096131867163|145461009584740|130005306921282
166305848801939 8744071222157
As you can see the AccountProductListId is already in the JSON result so I should know which array it should go to. The only problem is I don't know the syntax to merge the ProductID data into its specific array index. The JSON array could have more than 3 items.
Essentially ending up with something like this:
"value": [{
"AccountProductListId": 22091612871138,
"Name": "April 4th 2018",
"IsPublic": false,
"Comment": "Test order sheet",
"Quantity": 3,
"ProductID": "97096131867163|145461009584740|130005306921282"
}, {
"AccountProductListId": 166305848801939,
"Name": "test",
"IsPublic": false,
"Comment": "",
"Quantity": 1,
"ProductID": "8744071222157"
}, {
"AccountProductListId": 21177711287586,
"Name": "Test Order sheet",
"IsPublic": true,
"Comment": "the very first sheet",
"Quantity": 2,
"ProductID": "97096131867163|32721319938943"
}],
Any information would be greatly appreciated. Thanks.
Process with SQL Server
Prior to SQL Server 2016, there is not in-built support to read or write JSON.
Starting SQL Server 2016, you can use OPENJSON rowset function to read JSON and FOR JSON clause to write JSON.
See https://learn.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server
The approach would be to use OPENJSON to read the JSON string as a rowset, join it with the table to pickup ProductID and use FOR JSON to convert back to JSON.
Process outside SQL Server
Depending on your situation, it might be simpler to parse JSON outside SQL Server. If going that route, then you could
Collect all the AccountProductListIDs from the parsed JSON
Send the collected id to SQL Server via a stored procedure that takes a TVP input and outputs the AccountProductListID -> ProductID mapping
Inject the ProductIDs into JSON object and serialize back to string

BigCommerce Stencil - Retrieve Product Custom Fields in Product Card

I'm trying to retrieve each product's custom_fields data on the category list pages in BigCommerce Stencil. This documentation here, and the JSON product representation below, would suggest this is not possible.
It is hard for me to believe this functionality would be left out of Stencil, considering it was available in Blueprint.
{
"id": 691,
"name": "Archipelago Botanicals - Pomegranate Lip Gloss",
"url": "http://******.mybigcommerce.com/archipelago-botanicals-pomegranate-lip-gloss/",
"brand": {
"name": "Archipelago Botanicals"
},
"rating": 0,
"availability": "",
"summary": "Pomegranate lip gloss leaves lips hydrated, shiny and smooth. Apply liberally.Net Weight: 0.42 oz. / 12 g Mineral Oil, Polybutene, Octyidodecanol, Butylene, Ethylene, Styrene Copolymer, Ethylene, Propylene, Styrene Copolymer, C18-36 Acid Triglycerides, Fr",
"image": {
"data": "https://cdn3.bigcommerce.com/*****/images/stencil/{:size}/products/691/41439/arbopolipgl__77026.1464267682.jpg?c=2",
"alt": "Archipelago Botanicals - Pomegranate Lip Gloss"
},
"date_added": "Apr 7th 2016",
"qty_in_cart": 0,
"pre_order": false,
"has_options": false,
"show_cart_action": false,
"price": {
"without_tax": {
"formatted": "$5.00",
"value": 5
},
"rrp_without_tax": {
"formatted": "$12.50",
"value": 12.5
},
"saved": {
"formatted": "$7.50",
"value": 7.5
},
"tax_label": "Tax"
}
},
Am I missing something, or is this functionality not available on Stencil at this time?
Has anyone come up with a creative solution to retrieve this data inside each product card?
Thanks
The product card now allows this to be exposed. It provides an array of all custom fields associated with a product. Information on the product card object is here.
It was a change that had to be made in the BC core app and the fix was released on Sept 20th