How can I use "hints" in runtime optimization? - osrm

The OSRM Routing engine returns "hints" in many of its outputs, and you are able to pass these back into a new request, which saves on lookup time and thereby optimizes the query.
My question is how do I pass these "hints" back into the
/table/v1/car
API call as per the example below?
EXAMPLE:
An OSRM API request of
/table/v1/car/-0.693000,52.078000;-0.724000,52.040000
gives back (snippet) :
"sources": [
{
"hint": "uImugOqJroBBAAAAAAAAALoBAAAAAAAA7WvYQQAAAACaUzhDAAAAAEEAAAAAAAAAugEAAAAAAAAXCgAAmXb1__mxGgP4bPX_sKUaAwYALwrjJ41R",
"distance": 388.619802,
"location": [
-0.690535,
52.081145
],
"name": ""
},
The original coordinates:
-0.693000, 52.078000
have been fixed up to:
-0.690535, 52.081145
(snapped to a nearby road and the hint is as above).
So I would like to utilise these "hints" in a new API query for the same LAT/LNG location, which should optimize the query.
The manual says about hints:
This can be used on subsequent request to significantly speed up the query and to connect multiple services.
I've tried various combinations and looking at the manual, but so far nothing has worked.
Has anybody successfully passed "hint" data into the /table/v1/car
API for OSRM Routing?
If so, please would you let me know what you did

I tried your request:
/table/v1/car/-0.693000,52.078000;-0.724000,52.040000
and got response:
{"code":"Ok",
"durations":[[0,596.2],[615.9,0]],"destinations":[
{"hint":"teJ0h-fidIdBAAAAAAAAALoBAAAAAAAA7WvYQQAAAACaUzhDAAAAAEEAAAAAAAAAugEAAAAAAACrkAAAmXb1__mxGgP4bPX_sKUaAwYALwr88AjE",
"distance":388.619802,"name":"","location":[-0.690535,52.081145]},{"hint":"dbcDgLevA4BpAAAAAAAAAAQGAAAwCAAA4-dpQQAAAACIYVZDGSCSQzQAAAAAAAAAAgMAABwEAACrkAAATvb0_48VGgPg8_T_QBEaAw4Afwf88AjE",
"distance":129.943557,"name":"","location":[-0.723378,52.041103]}],
"sources":[
{"hint":"teJ0h-fidIdBAAAAAAAAALoBAAAAAAAA7WvYQQAAAACaUzhDAAAAAEEAAAAAAAAAugEAAAAAAACrkAAAmXb1__mxGgP4bPX_sKUaAwYALwr88AjE",
"distance":388.619802,"name":"","location":[-0.690535,52.081145]},{"hint":"dbcDgLevA4BpAAAAAAAAAAQGAAAwCAAA4-dpQQAAAACIYVZDGSCSQzQAAAAAAAAAAgMAABwEAACrkAAATvb0_48VGgPg8_T_QBEaAw4Afwf88AjE",
"distance":129.943557,"name":"","location":[-0.723378,52.041103]}]}
Your request has 2 points, so you have to add 2 hints, one for each point.
So, the request with hints is:
/table/v1/car/-0.693000,52.078000;-0.724000,52.040000?hints=teJ0h-fidIdBAAAAAAAAALoBAAAAAAAA7WvYQQAAAACaUzhDAAAAAEEAAAAAAAAAugEAAAAAAACrkAAAmXb1__mxGgP4bPX_sKUaAwYALwr88AjE;dbcDgLevA4BpAAAAAAAAAAQGAAAwCAAA4-dpQQAAAACIYVZDGSCSQzQAAAAAAAAAAgMAABwEAACrkAAATvb0_48VGgPg8_T_QBEaAw4Afwf88AjE
where hints are separated by semicolon.

Related

Should you change reference data in an API end point

We've recently started creating API endpoints. One of these end points is hardcoded to change 2 of our reference type codes (i.e. code: "P" for mobile is being changed to "M") from their system value to a custom value (out of a configurable list that has approximately 12 records at the moment. I'm trying to convince them it's bad practice and a terrible idea to change this reference data because of all of the issues it can cause for systems that use the api, however they believe it increases the "independence" of the API from the system of truth. We work in an enterprise environment and currently only our systems hit the api.
Is there any other data or information (Copious amounts of google searching hasn't revealed anyone discussing this sort of issue specifically) that suggests this is a bad idea? Or am I wrong in thinking so?
Edit:
For reference here's some examples:
What the data would look like in the source system the api pulls from
{
"phone_type": "P",
"phone_number": "1234567890",
"user_id":"username"
}
What that same data would look like coming from our API now
{
"phone_type": "M",
"phone_number": "1234567890",
"user_id":"username"
}
What the reference data would look like coming from our reference codes end point
[
{
"code": "P",
"description": "Mobile Number",
"active":"true"
}
]

Smartsheet API response codes with python SDK?

I am using the Smartsheet python SDK to do bulk operations (deletes, updates, etc.) on a Smartsheet. As my process becomes more complex, I've realized that I need to include some internal checks to make sure I am not encountering errors when sending multiple calls per minute as Smartsheet suggests in their API Best Practices.
My question is this: How do I access and parse the API responses while using SDK functions such as Sheets.delete_rows()? For instance, some of my requests using this function can trigger status: 500 Internal Server Error which mean the request was properly formatted but the operation failed on the Smartsheet end.
I can view these responses in my log file (or in terminal while running interactively) but how do I access them from within my script so I can, for example, sleep() my process for xx seconds if encountering such a response?
If you are looking to know the results of a request you can store the response in a variable and inspect that for determining the next steps your process should take. In the case of the DELETE Rows request a Result object is returned.
deleteRows = smartsheet_client.Sheets.delete_rows({{sheetId}}, [ {{rowId1}}, {{rowId2}}, {{rowId3}}])
print(deleteRows)
If the request was successful the response would look like this:
{"data": [7411278123689860], "message": "SUCCESS", "result": [7411278123689860], "resultCode": 0}
If there was an issue, rows weren't found for example, the response would look like this:
{"result": {"code": 1006, "errorCode": 1006, "message": "Not Found", "name": "ApiError", "recommendation": "Do not retry without fixing the problem. ", "refId": "jv6o8uyrya2s", "shouldRetry": false, "statusCode": 404}}
All of the Smartsheet SDKs will backoff and retry by default. Other errors will be thrown as exceptions.
There is a way to increase the default timeout (to allow more retries) when creating the client. However, the Python-specific way to do it doesn't seem to be documented yet. I'll add it to the queue. In the meantime, I think the Ruby example below will be the closest to how Python probably does it, but you might want to read through the various ways to do this.
C#: https://github.com/smartsheet-platform/smartsheet-csharp-sdk/blob/master/ADVANCED.md#sample-retryhttpclient
Java: https://github.com/smartsheet-platform/smartsheet-java-sdk/blob/master/ADVANCED.md#sample-retryhttpclient
Node.js: https://github.com/smartsheet-platform/smartsheet-javascript-sdk#retry-configuration
Ruby: https://github.com/smartsheet-platform/smartsheet-ruby-sdk#retry-configuration

Google Fit REST API "Unable to fetch DataSource for Dataset: xyz"

I'm testing out a few things in the OAuth 2.0 Playground and trying to get data in and out of Google Fit using their REST API
I have done this previously with success, I just didn't write down what I did.. now I've come back to make it a proper thing and can't get it working again.
I have access to Google Fit datasources via the dashboard. I can get a list of the dataSources that exist from:
https://www.googleapis.com/fitness/v1/users/me/dataSources
And that is successful. I have also created my own stream which has a single floating point weight value on it called
raw:com.google.weight:b6ac18c0:dten.sync
It already has data in it, I put it there last time I used it. I can select all that data by requesting a GET on the following
https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.weight:b6ac18c0:dten.sync/datasets/0-1432193482000000000
It returns me all the data points I entered last time as JSON
I then try to PATCH the data adding my own data to the folliwng URL
https://www.googleapis.com/fitness/v1/users/me/dataSources/raw:com.google.weight:b6ac18c0:dten.sync/datasets/1432193482000000000-1432193482000000000
With this as a the request body
{
"minStartTimeNs": "1421912895000000000",
"maxEndTimeNs": "1432193482000000000",
"dataSourceId": "raw:com.google.weight:b6ac18c0:dten.sync",
"point": [
{
"startTimeNanos": "1421912895000000000",
"modifiedTimeMillis": "1421912895000",
"endTimeNanos": "1421912895000000000",
"value": [
{
"fPVal": 89.1
}
],
"dataTypeName": "com.google.weight"
}
]
}
But I get back
{
"error": {
"code": 400,
"message": "Unable to fetch DataSource for Dataset: raw:com.google.weight:b6ac18c0:dten.sync",
"errors": [
{
"domain": "global",
"message": "Unable to fetch DataSource for Dataset: raw:com.google.weight:b6ac18c0:dten.sync",
"reason": "invalidArgument"
}
]
}
}
I can't find any one referencing a similar anywhere soo I'm here
Also note if I miss spell my source it tells me off because they don't match the URL, if i include an empty list of data points I get the same error. I'm quite lost so I'm throwing it out there to see if anyone knows what that means
Thanks in advance
edit: i tried changing the hex code for my project's integer code and got an error about untrusted source. so i tried making a new test data source which works as expected. Slightly annoyed but guess I'll just start over..
OK I was stupid and didn't set up my own credentials in the OAuth settings in top right of the dashboard as it said to here. I forgot that bit -_- now I can access my own stream again and it shows my integer project id in the stream id not the hex one
https://developers.google.com/fit/rest/v1/get-started
Now I get invalid argument, but.. whatever >_<
edit 2:
invalid argument was because I have fPVal instead of fpVal and modifiedTimeMillis mills is not supposed to be submitted, obviously

Bing Maps REST Service

I am sending a request to Bing Maps REST service to get the location information such as coordinates etc, I entered this request (http://dev.virtualearth.net/REST/v1/Locations/query=rsa/gauteng/2001/johannesburg/melville?o=xml&key="mykey") in my web browser (as a test) and it returns the wrong location information.
The returned xml suggests that I'm in the states somewhere in NY.
Can anyone help me understand why this is?
I have read Microsoft's documentation on the web service and I'm following the proper structure to construct a request. I have Googled in a quest of getting a solution but no luck
You're not issuing the request correctly. Bing provides two methods: structured query and non-structured. You're mixing both.
Structured ("REST" like):
http://dev.virtualearth.net/REST/v1/Locations/CA/BC/V6G/Vancouver/Stanley%20Park%20Causeway?key=BingMapsKey
Non-structured (with query-string):
http://dev.virtualearth.net/REST/v1/Locations?locality=London&postalCode=SW1A&key=BingMapsKey
As specified on the reference page (http://msdn.microsoft.com/en-us/library/ff701714.aspx) a request similar to yours would need to be done like this:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion={country}&adminDistrict={district}&locality={locality}&key={key}
Also, you should use the 2-letter ISO code. Thus, South-Africa would be "ZA".
Your complete request will be:
http://dev.virtualearth.net/REST/v1/Locations?countryRegion=za&adminDistrict=johannesburg&locality=melville&key=key
It returns something like this:
address: {
adminDistrict: "Gauteng",
adminDistrict2: "Johannesburg",
countryRegion: "South Africa",
formattedAddress: "Melville, South Africa",
locality: "Melville"
},
confidence: "High",
entityType: "Neighborhood",
geocodePoints: [{
type: "Point",
coordinates: [
-26.17535972595215,
28.008920669555664
],
calculationMethod: "Rooftop",
usageTypes: ["Display"]
}]

finding both "Shopping_mall" and "food" within single URL for google places API

I tried following URLs to get both "shopping_mall" and "food" within a single request.
https://maps.googleapis.com/maps/api/place/search/json?location=%#,%#&radius=1500&sensor=true&key=%#&types=shopping_mall|food
This gives me response with only "food" type of places.
But,
https://maps.googleapis.com/maps/api/place/search/json?location=%#,%#&radius=1500&sensor=true&key=%#&types=shopping_mall
Gives the result with "shopping_mall" only. Also, The same URL with "food" only give the result same as "shopping_mall|food".
Has anyone faced this issue. I have searched across but cannot find any useful answer to that.
P.S. I have gone through this link and this link , too.
If you are getting only food in the first request, and you're getting 20 results, then it is likely Google believes the most relevant results are food. You may have to do 2 requests. You can try adding keyword=shopping, but that may limit your food results.