From the docs at https://redis.io/docs/stack/json/path/#legacy-path-syntax:
The time complexity of searching (navigating to) an element in the path is calculated from:
Child level - every level along the path adds an additional search
Key search - O(N)†, where N is the number of keys in the parent object
Array search - O(1)
If I have json like:
{
"inventory": {
"headphones": [
{
"id": 12345,
"name": "Noise-cancelling Bluetooth headphones",
"description": "Wireless Bluetooth headphones with noise-cancelling technology",
"wireless": true,
"connection": "Bluetooth",
"price": 99.98,
"stock": 25,
"free-shipping": false,
"colors": ["black", "silver"]
},
{
"id": 12346,
"name": "Wireless earbuds",
"description": "Wireless Bluetooth in-ear headphones",
"wireless": true,
"connection": "Bluetooth",
"price": 64.99,
"stock": 17,
"free-shipping": false,
"colors": ["black", "white"]
},
{
"id": 12347,
"name": "Mic headset",
"description": "Headset with built-in microphone",
"wireless": false,
"connection": "USB",
"price": 35.01,
"stock": 28,
"free-shipping": false
}
],
"keyboards": [
{
"id": 22345,
"name": "Wireless keyboard",
"description": "Wireless Bluetooth keyboard",
"wireless": true,
"connection": "Bluetooth",
"price": 44.99,
"stock": 23,
"free-shipping": false,
"colors": ["black", "silver"]
},
{
"id": 22346,
"name": "USB-C keyboard",
"description": "Wired USB-C keyboard",
"wireless": false,
"connection": "USB-C",
"price": 29.99,
"stock": 30,
"free-shipping": false
}
]
}
}
and do
JSON.GET obj $.inventory.headphones
what is the time complexity of this?
Is it O(1) to access .inventory, O(1) to access headphones, and then O(1) to return value here (the entire array of headphone objects)? which would sum to O(1)?
Or is it O(N1) to search through all the keys of the parent (N1=1), another O(N2) to search through the first child (in this case N2=2 for headphone and keyboard), and then O(M * N3) where N3=9 to search through all the keys in the object and M=3 for the number of objects in the array? which would sum to O(N1 + N2 + M*N3)?
Related
So i started to log all queries of my spring boot application via a proxy data source and came across some queries i couldn't explain to myself.
This is the json log of said queries:
[
{
"name": "TOXI",
"connection": 3,
"isolation": "READ_COMMITTED",
"time": 2,
"success": true,
"type": "Prepared",
"batch": false,
"querySize": 1,
"batchSize": 0,
"query": [
"select * from information_schema.sequences"
],
"params": [
[]
]
},
{
"name": "TOXI",
"connection": 3,
"isolation": "READ_COMMITTED",
"time": 2,
"success": true,
"type": "Prepared",
"batch": false,
"querySize": 1,
"batchSize": 0,
"query": [
"select * from \"public\".\"toxi_image\" where 1=0"
],
"params": [
[]
]
},
{
"name": "TOXI",
"connection": 3,
"isolation": "READ_COMMITTED",
"time": 0,
"success": true,
"type": "Prepared",
"batch": false,
"querySize": 1,
"batchSize": 0,
"query": [
"select * from \"public\".\"toxi_tag\" where 1=0"
],
"params": [
[]
]
},
]
The first one still makes sense to me, but the second and third one is where my question start.
Why are they needed? Shouldn't the information schema hold all the table information thats needed? And why is making this statement only for 2 tables and not for the rest of the application?
One last thing to mention, the two tables/entities have a many to many correlation, if that has something to do with it.
Thank you in advance
I am checking the Amadeus about flight tickets and a little confused about the prices that I get. I expected to see prices from Amadeus closer to airline website prices or a little cheaper. But, I see that prices are incredibly high. For example, I made the following request:
https://api.amadeus.com/v2/shopping/flight-offers?originLocationCode=SGN&destinationLocationCode=DAD&departureDate=2020-05-29&adults=1&nonStop=true¤cyCode=VND
Flight at Amadeus Price In USD Airline price in USD
11:45 ~70.41 ~38.72
13:50 ~70.41 ~34.43
18:00 ~70.41 ~42.93
Prices are higher significantly. Moreover, prices from Amadeus are the same for a lot of flights for the same air company.
Do I do something wrong or I skipped something?
PS: Response for first flight:
{
"type": "flight-offer",
"id": "1",
"source": "GDS",
"instantTicketingRequired": false,
"nonHomogeneous": false,
"oneWay": false,
"lastTicketingDate": "2020-05-29",
"numberOfBookableSeats": 4,
"itineraries": [{
"duration": "PT1H20M",
"segments": [{
"departure": {
"iataCode": "SGN",
"terminal": "1",
"at": "2020-05-29T11:15:00"
},
"arrival": {
"iataCode": "DAD",
"terminal": "1",
"at": "2020-05-29T12:35:00"
},
"carrierCode": "VJ",
"number": "628",
"aircraft": {
"code": "321"
},
"operating": {
"carrierCode": "VJ"
},
"duration": "PT1H20M",
"id": "9",
"numberOfStops": 0,
"blacklistedInEU": false
}]
}],
"price": {
"currency": "VND",
"total": "1640000.00",
"base": "1381000.00",
"fees": [{
"amount": "0.00",
"type": "SUPPLIER"
},
{
"amount": "0.00",
"type": "TICKETING"
}
],
"grandTotal": "1640000.00"
},
"pricingOptions": {
"fareType": [
"PUBLISHED"
],
"includedCheckedBagsOnly": true
},
"validatingAirlineCodes": [],
"travelerPricings": [{
"travelerId": "1",
"fareOption": "STANDARD",
"travelerType": "ADULT",
"price": {
"currency": "VND",
"total": "1640000.00",
"base": "1381000.00"
},
"fareDetailsBySegment": [{
"segmentId": "9",
"cabin": "ECONOMY",
"fareBasis": "JSP",
"class": "J",
"includedCheckedBags": {
"weight": 20,
"weightUnit": "KG"
}
}]
}]
},
Keep in mind that right now the only source for prices in the API is GDS. Many LCCs don't / only load their more expensive fares into GDS, as it costs them money.
Lately, many "normal" airlines have also added fees when booking from a GDS compared to directly on their website / or other direct distribution methods.
I assume VietJet is one of those carriers, as it is a low-cost airline.
Regarding your second question: That is because of the fare system in the airline industry. Airlines load so called "fares", which specifies the price of a ticket for a given route within a date window.
An example: VietJet offers SGN-DAD for a base fare of 55EUR ( without taxes& fees ). You can choose any flight by VJ on any date within the window of the fare, and the price will be the same, as long as there is availability in the booking class J , which the fare is for.
I want to get the details of the person who created the repository using Github API. I got the repositories in my organization using:
https://github.example.com/api/v3/search/repositories?q=org:<name>
I got a list of 30 repositories within the organization with details in the following manner:
{
"total_count": 40,
"incomplete_results": false,
"items": [
{
"id": 3081286,
"node_id": "MDEwOlJlcG9zaXRvcnkzMDgxMjg2",
"name": "Tetris",
"full_name": "dtrupenn/Tetris",
"owner": {
"login": "dtrupenn",
"id": 872147,
"node_id": "MDQ6VXNlcjg3MjE0Nw==",
"avatar_url": "https://secure.gravatar.com/avatar/e7956084e75f239de85d3a31bc172ace?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png",
"gravatar_id": "",
"url": "https://api.github.com/users/dtrupenn",
"received_events_url": "https://api.github.com/users/dtrupenn/received_events",
"type": "User"
},
"private": false,
"html_url": "https://github.com/dtrupenn/Tetris",
"description": "A C implementation of Tetris using Pennsim through LC4",
"fork": false,
"url": "https://api.github.com/repos/dtrupenn/Tetris",
"created_at": "2012-01-01T00:31:50Z",
"updated_at": "2013-01-05T17:58:47Z",
"pushed_at": "2012-01-01T00:37:02Z",
"homepage": "",
"size": 524,
"stargazers_count": 1,
"watchers_count": 1,
"language": "Assembly",
"forks_count": 0,
"open_issues_count": 0,
"master_branch": "master",
"default_branch": "master",
"score": 10.309712
}
]
}
The problem I have right now is that the owner's id is always the same and it's equal to the organization name. I want the details of the creators. Is there any way I could do that? I tried searching everywhere, but I couldn't find any solution.
In a Zapier Zap I am using an an API GET call to Tsheets to grab a list of Timesheets. I would like to split out each time sheet into line items like line items in a Xero invoice because I would like to save item data from each timesheet to its own row in a Google sheet. (Ideally I would like to save the line data directly to a MySQL database but I see that Zapier currently only support Google sheets saving multiple lines at a time.) However I am having no joy.
I suspect one of two issues:
Zapier expects the word lineitems in the response or
The format of the response is not correct - I seem to have two "results" categories
In my step to Set up Google Sheets Spreadsheet Row I don't get a selection of comma separated items as shown in the example shown on the picture here:
Add an action app that supports line items, and each item will be saved individually
The image is from this page: https://zapier.com/blog/formatter-line-item-automation/ with the caption "Add an action app that supports line items, and each item will be saved individually" For what I get see photo https://cdn.zapier.com/storage/photos/f055dcf11a4b11b86f912f9032780429.png
In the step that returns the data from the API the text response is shown in https://cdn.zapier.com/storage/photos/33129fb7425cfae44be4a81533d6e892.png
and if I return json data it is like this: https://cdn.zapier.com/storage/photos/34da1b98f8941324c35befef8efe350d.png
Can anyone confirm that my suspicions are correct and whether 1 or 2 is the likely culprit.
Is it possible this link Zapier - Catch Hook - JSON Array - Loop over each item in array will lead me to the solution? It looks like it may but I don't see exactly how the writer incorporated it in to his Zap.
Edit: My data returned from the API looks like this:
{
"results": {
"timesheets": {
"11515534": {
"id": 11515534,
"user_id": 1260679,
"jobcode_id": 11974818,
"start": "2018-07-13T14:58:00+10:00",
"end": "2018-07-13T14:58:00+10:00",
"duration": 0,
"date": "2018-07-13",
"tz": 10,
"tz_str": "Australia\/Brisbane",
"type": "regular",
"location": "(Brisbane, Queensland, AU?)",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"118516": "",
"121680": "",
"118530": "",
"118518": "Field supplies, materials"
},
"last_modified": "2018-07-13T04:59:27+00:00",
"attached_files": [
]
},
"11515652": {
"id": 11515652,
"user_id": 1260679,
"jobcode_id": 11974830,
"start": "2018-07-13T14:59:00+10:00",
"end": "2018-07-13T14:59:00+10:00",
"duration": 0,
"date": "2018-07-13",
"tz": 10,
"tz_str": "Australia\/Brisbane",
"type": "regular",
"location": "(Brisbane, Queensland, AU?)",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"118516": "",
"121680": "",
"118530": ""
},
"last_modified": "2018-07-13T05:00:30+00:00",
"attached_files": [
]
},
"39799840": {
"id": 39799840,
"user_id": 1260679,
"jobcode_id": 19280104,
"start": "2018-10-24T11:45:00+11:00",
"end": "2018-10-24T12:00:00+11:00",
"duration": 900,
"date": "2018-10-24",
"tz": 11,
"tz_str": "Australia\/Brisbane",
"type": "regular",
"location": "(Sydney, New South Wales, AU?)",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"118516": "",
"121680": "FP - Field plant Installation",
"118530": "Site cleanup"
},
"last_modified": "2018-10-24T05:56:27+00:00",
"attached_files": [
]
},
"39801850": {
"id": 39801850,
"user_id": 1260679,
"jobcode_id": 19280204,
"start": "2018-10-24T12:00:00+11:00",
"end": "2018-10-24T13:45:00+11:00",
"duration": 6300,
"date": "2018-10-24",
"tz": 11,
"tz_str": "Australia\/Brisbane",
"type": "regular",
"location": "(Sydney, New South Wales, AU?)",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"118516": "",
"121680": "OP - Plant, Vehicles",
"118530": "Load\/Unload"
},
"last_modified": "2018-10-24T05:57:04+00:00",
"attached_files": [
]
},
"40192757": {
"id": 40192757,
"user_id": 1260679,
"jobcode_id": 19280110,
"start": "2018-10-25T08:00:00+11:00",
"end": "2018-10-25T10:00:00+11:00",
"duration": 7200,
"date": "2018-10-25",
"tz": 11,
"tz_str": "Australia\/Brisbane",
"type": "regular",
"location": "TSheets Android App",
"on_the_clock": false,
"locked": 0,
"notes": "From my mobile",
"customfields": {
"118516": "",
"121680": "FW - Plant Assembly",
"118530": "Panels"
},
"last_modified": "2018-10-24T23:02:56+00:00",
"attached_files": [
]
},
"40193033": {
"id": 40193033,
"user_id": 1260679,
"jobcode_id": 19280108,
"start": "2018-10-25T10:00:00+11:00",
"end": "2018-10-25T10:00:00+11:00",
"duration": 0,
"date": "2018-10-25",
"tz": 11,
"tz_str": "Australia\/Brisbane",
"type": "regular",
"location": "TSheets Android App",
"on_the_clock": false,
"locked": 0,
"notes": "",
"customfields": {
"118516": "",
"121680": "FW - Plant Assembly",
"118530": "Panels"
},
"last_modified": "2018-10-24T23:06:05+00:00",
"attached_files": [
]
}
}
},
"more": false
}
And this is my Python code: https://imgur.com/a/8W1X1em
Alright so I think I've worked something out for you. The example you provided Zapier - Catch Hook - JSON Array - Loop over each item in array is definitely on the right track, but, because it relies on webhooks, it probably won't work for you unless you can POST the data from your invoicing application.
Note: I code in Python so my examples will be in Python, that said these examples are pretty much code agnostic and can be replicated in Javascript as well.
I setup a dummy Zap to replicate what is happening with your zap currently
# results = requests.get(url, headers=header)
# results = results.json()
# Dummy result data converted to JSON object after API GET request:
results = {
"results" : {
"timesheets" : {
"timesheet_id_1" : {
"data_1" : "data",
"data_2" : "data",
"data_3" : "data"
},
"timesheet_id_2" : {
"data_1" : "data",
"data_2" : "data",
"data_3" : "data"
},
"timesheet_id_3" : {
"data_1" : "data",
"data_2" : "data",
"data_3" : "data"
}
}
}
}
return results
Reading a bit further here in order for Zapier to map line items it needs to receive the data in an array. The above output is a dictionary object, Zapier does map the values in this dictionary to data that can be accessed later, however it maps the entire dictionary which is why you are seeing the output as multiple fields and as is replicated in my output. What you are looking to do is map a subset of the dictionary AND provide each subset as separate outputs.
What you will want to do is loop through the inner fields of the results dictionary object and execute zaps on the nested "timesheet_id_n". To do so we will have to return a list of line items, as stated above line items must be placed into an array. And so my code to achieve this looks like:
# results = requests.get(url, headers=header)
# results = results.json()
# Dummy result data converted to JSON object after API GET request:
results = {
"results" : {
"timesheets" : {
"timesheet_id_1" : {
"data_1" : "data",
"data_2" : "data",
"data_3" : "data"
},
"timesheet_id_2" : {
"data_1" : "data",
"data_2" : "data",
"data_3" : "data"
},
"timesheet_id_3" : {
"data_1" : "data",
"data_2" : "data",
"data_3" : "data"
}
}
}
}
# Container for my line items. Each element in this list will be executed on separately
return_results = []
results = results.get("results")
results = results.get("timesheets")
for item in results:
return_results.append({"sheet_id" : item, "sheet_data" : results.get(item)})
return return_results
The output of return_results will be an array of dictionary objects. As these dictionary objects are in array Zapier will treat them as line items, additionally because each line item is a dictionary object Zapier will automatically map each value so that they can be independently be used in later action steps. You can see this demonstrated in the output of my trigger zap in the following screenshots:
output 1
output 2
output 3
Hope this helped!
According to the documentation, there is a has_options attribute on the Common Product Card Model that should return a boolean showing whether or not the product has options.
However, this value is returning false for all of my products, even though they have options. For example, if I access the homepage in debug mode via this url:
http://localhost:3000/?debug=context
One of the products under the featured products section is:
{
"id": 114,
"name": "Product Name",
"url": "http://www.example.com/product-url",
"brand": null,
"rating": 5,
"availability": "Usually ships the next business day",
"summary": "Product summary goes here",
"image": {
"data": "https://cdn2.bigcommerce.com/server2100/abcdef/images/stencil/{:size}/products/114/8086/product_image.jpg?c=2",
"alt": ""
},
"date_added": "January 6, 2014",
"qty_in_cart": 0,
"pre_order": false,
"has_options": false,
"show_cart_action": false,
"add_to_wishlist_url": "/wishlist.php?action=add&product_id=114",
"price": {
"without_tax": {
"formatted": "$19.99",
"value": 19.99
},
"rrp_without_tax": {
"formatted": "$24.99",
"value": 24.99
},
"saved": {
"formatted": "$5.00",
"value": 5
},
"tax_label": "Tax"
}
}
As you can see has_options is false. However, this product does have options. Via the control panel, I can see that it has a color swatch option. I can also see this by navigating to the products page in debug mode at http://localhost:3000/product-url?debug=context. As you can see, part of the output contains the options information for that product:
"options": [
{
"id": 498,
"type": "Configurable_PickList_Swatch",
"display_name": "Color",
"required": true,
"condition": true,
"values": [
{
"label": "Powder Coat Black",
"id": 390,
"data": [
"000000"
],
"selected": false
},
{
"label": "Anodized Aluminum",
"id": 391,
"data": [
"D9D9D9"
],
"selected": false
}
],
"partial": "swatch"
}
],
As you can see, the product does in fact have options, yet the Common Product Card Model for this product shows has_options as false.
Is there some other setting that is effecting the output of has_options? Why would it be showing false for a product that has options?
has_options is used to denote something is purchasable (true) or not (false). This is misleading and documentation will be revised to reflect this.