I want to get speed limits for points in a car track. But instead of one value, I got two: FROM_REF_SPEED_LIMIT and TO_REF_SPEED_LIMIT. What is the meaning of these ones? Where is no documentation about these attributes. How can I use them to get speed limit? Actually speed limit in this place is 40km/h.
import requests
t = [(55.662026, 37.773537),
(55.661813, 37.774049)]
s = ""
for x in t:
s += ' <trkpt lat="' + str(x[0]) + '" lon="' + str(x[1]) + '"/> '
s1 = '<?xml version="1.0"?> <gpx version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/0" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd"> <trk> <trkseg> ' + s +'</trkseg></trk></gpx>'
resp = requests.post('http://rme.cit.api.here.com/2/matchroute.json?routemode=carHOV&attributes=SPEED_LIMITS_FCn%28FROM_REF_SPEED_LIMIT,TO_REF_SPEED_LIMIT%29&app_id=iqZ08RnLQHOCQUYqwZ&app_code=oWWPJv9pVx9Y2DdIBBOA', data=s1)
print(resp.text)
Response:
{
"MapVersion": "LATEST",
"RouteLinks": [
{
"attributes": {
"SPEED_LIMITS_FCN": [
{
"FROM_REF_SPEED_LIMIT": "20",
"TO_REF_SPEED_LIMIT": "60"
}
]
},
"confidence": 0.94,
"functionalClass": 3,
"linkId": -1154810237,
"linkLength": 50.75,
"mSecToReachLinkFromStart": 3501,
"offset": 0.42156,
"shape": "55.66226 37.77328 55.66212 37.77352 55.66195 37.77387"
},
{
"attributes": {
"SPEED_LIMITS_FCN": [
{
"FROM_REF_SPEED_LIMIT": "20",
"TO_REF_SPEED_LIMIT": "60"
}
]
},
"confidence": 0.95,
"functionalClass": 3,
"linkId": -1154810236,
"linkLength": 58.13,
"mSecToReachLinkFromStart": 6403,
"offset": 0.69481,
"shape": "55.66195 37.77387 55.66179 37.77431 55.66168 37.77466"
}
],
"TracePoints": [
{
"confidenceValue": 0.5,
"elevation": 0.0,
"headingDegreeNorthClockwise": 10000.0,
"headingMatched": 131.0,
"lat": 55.662026,
"latMatched": 55.66208,
"linkIdMatched": -1154810237,
"lon": 37.773537,
"lonMatched": 37.77361,
"matchDistance": 10.0,
"matchOffsetOnLink": 0.42156269739402924,
"minError": 7.0,
"routeLinkSeqNrMatched": 0,
"speedMps": 0.0,
"timestamp": 0
},
{
"confidenceValue": 0.58,
"elevation": 0.0,
"headingDegreeNorthClockwise": 10000.0,
"headingMatched": 123.0,
"lat": 55.661813,
"latMatched": 55.66186,
"linkIdMatched": -1154810236,
"lon": 37.774049,
"lonMatched": 37.77411,
"matchDistance": 8.59,
"matchOffsetOnLink": 0.69481133508979,
"minError": 7.0,
"routeLinkSeqNrMatched": 1,
"speedMps": 0.0,
"timestamp": 0
}
],
"Warnings": []
}
The link has two different speed limits for each direction in its map data.
If the published speed limit is wrong, you can report it to https://mapcreator.here.com. Right now we will take a look at it.
Please check the attached image.
Thank you!
Related
[
{
"_id": "",
"at": IsoDate(2022-11-19 10:00:00),
"areaId": 3,
"data": [
{
"name": "a",
"sec": 34,
"x": 10.3,
"y": 23.3
},
{
"name": "a",
"sec": 36,
"x": 10.3,
"y": 23.3
},
{
"name": "b",
"sec": 37,
"x": 10.3,
"y": 23.3
}
]
},
{
"_id": "",
"at": IsoDate(2022-11-19 10:00:00),
"areaId": 3,
"data": [
{
"name": "a",
"sec": 10,
"x": 10.3,
"y": 23.3
},
{
"name": "b",
"sec": 12,
"x": 10.3,
"y": 23.3
}
]
}
]
I have a table that indicates in what seconds people are in which area in packets of minutes. My goal here is to find the date the person with the specified name was last in the field with the most performance.
Can you help me for this?
Example output: Last date 'a' was found in polygon=3
2022-11-19 10:01:10 (with sec)
One option is:
Use the first 3 steps to find the matching document
The 4th step is to add the seconds to to the at date
db.collection.aggregate([
{$match: {data: {$elemMatch: {name: inputName}}}},
{$sort: {at: -1}},
{$limit: 1},
{$project: {
res: {
$dateAdd: {
startDate: "$at",
unit: "second",
amount: {$reduce: {
input: "$data",
initialValue: 0,
in: {$cond: [
{$eq: ["$$this.name", inputName]},
{$max: ["$$this.sec", "$$value"]},
"$$value"
]}
}}
}
}
}}
])
See how it works on the playground example
I have a dictionary dct with two sets set1 and set2 of different lengths.
dct ={
"id": "1234",
"set1": [
{
"sub_id": "1234a",
"details": [
{
"sum": "10",
"label": "pattern1"
}
],
},
{
"sub_id": "1234b",
"details": [
{
"sum": "10",
"label": "pattern3"
}
],
}
],
"set2": [
{
"sub_id": "3463a",
"details": [
{
"sum": "20",
"label": "pattern1"
}
],
},
{
"sub_id": "3463b",
"details": [
{
"sum": "100",
"label": "pattern2"
}
],
},
{
"sub_id": "3463c",
"details": [
{
"sum": "100",
"label": "pattern3"
}
],
}
]
}
I need to check for each label if the corresponding sum has changed, and if yes, subtract these.
pairs1=[]
pairs2=[]
for d in dct['set1']:
for dd in d['details']:
pairs1.append((dd['label'],dd['sum']))
for d in dct['set2']:
for dd in d['details']:
pairs2.append((dd['label'],dd['sum']))
result={}
for p in pairs1:
for pp in pairs2:
if p[0] == pp[0]:
result[p[0]]= int(pp[1])-int(p[1])
result
Output something like:
{'pattern1': 10, 'pattern3': 90}
Is there a better way to iterate through the nested dictionary?
I've been using Forms Recognizer for some days now and can't get it to recognize the keys in my forms.
I want to use it to extract the answers given by students in a test...here is an example.
I can't change the structure of the sheet students fill because it is a national exam and I don't have access to who organizes it.
So I trained a model as recommended on Microsoft documentation and used it to "read" the forms and it gets most of the answers, but it all comes as values of a key "Tokens"
{
"key": [
{
"text": "__Tokens__",
"boundingBox": [
0,
0,
0,
0,
0,
0,
0,
0
]
}
],
"value": [
{
"text": "01",
"boundingBox": [
110.1,
826.6,
125.6,
826.6,
125.6,
816.8,
110.1,
816.8
],
"confidence": 1
},
{
"text": "A",
"boundingBox": [
148.2,
834.4,
160.6,
834.4,
160.6,
816.8,
148.2,
816.8
],
"confidence": 1
},
{
"text": "26",
"boundingBox": [
229.4,
828.6,
246,
828.6,
246,
816.8,
229.4,
816.8
],
"confidence": 1
},
{
"text": "B",
"boundingBox": [
268.6,
834.4,
277.8,
834.4,
277.8,
816.8,
268.6,
816.8
],
"confidence": 1
}
Then I recreated the structure on excel but with : after the numbers and trained another model. I also printed some copies of it and filled in to test and Form Recognizer understood the numbers as keys.
{
"key": [
{
"text": "01:",
"boundingBox": [
270.4,
1625.4,
313,
1625.4,
313,
1600.5,
270.4,
1600.5
]
}
],
"value": [
{
"text": "A",
"boundingBox": [
350.7,
1620.9,
368.8,
1620.9,
368.8,
1587,
350.7,
1587
],
"confidence": 1
}
]
},
{
"key": [
{
"text": "26:",
"boundingBox": [
520.2,
1624.2,
552.8,
1624.2,
552.8,
1600.5,
520.2,
1600.5
]
}
],
"value": [
{
"text": "E",
"boundingBox": [
604.6,
1618.8,
625.8,
1618.8,
625.8,
1587,
604.6,
1587
],
"confidence": 1
}
]
}
Does anyone know some way to recognize the number fields as keys without the : ?
Form Recognizer will not consider the row numbers as keys unless specifically marked as keys, hence it currently does not discover them as keys.
I have a JSON document that looks as follows:
{
"Region": "Main",
"MarketLocations": [
{
"MarketName": "Central",
"MarketId": 1,
"SalesCategories": {
"Produce": [
{
"Type": "Apple",
"Name": "Granny Smith",
"DatePicked": "2016-11-08T14:14:33.712Z",
"ShelfLifeInDays": 24,
"Calories": 45,
"Price": 0.29
}
],
"BakedGoods": [
{
"DateMade": "2016-11-08T14:14:33.712Z",
"Name": "Apple Pie",
"Price": 14.25
}
],
"RestaurantItems": [
{
"Name": "Turkey Sandwich",
"Price": 4.85,
"PreparationTimeInMinutes": 20
}
],
"NonPerishable": [
{
"Name": "Honey Mustard",
"Type": "Condiments"
}
]
}
},
{
"MarketName": "Southern",
"MarketId": 2,
"SalesCategories": {
"Produce": [
{
"Type": "Apple",
"Name": "Granny Smith",
"DatePicked": "2016-11-08T14:14:33.712Z",
"ShelfLifeInDays": 24,
"Calories": 45,
"Price": 0.29
},
{
"Type": "Plums",
"Name": "Red Plums",
"DatePicked": "2016-11-08T14:14:33.712Z",
"ShelfLifeInDays": 12,
"Calories": 21,
"Price": 0.33
},
{
"Type": "Pears",
"Name": "Golden Nature",
"DatePicked": "2016-11-08T14:14:33.712Z",
"ShelfLifeInDays": 20,
"Calories": 40,
"Price": 0.45
}
],
"BakedGoods": [
{
"DateMade": "2016-11-08T14:14:33.712Z",
"Name": "Apple Pie",
"Price": 14.25
}
],
"RestaurantItems": [
{
"Name": "Turkey Sandwich",
"Price": 4.85,
"PreparationTimeInMinutes": 20
}
],
"NonPerishable": [
{
"Name": "Honey Mustard",
"Type": "Condiments"
}
]
}
},
{
"MarketName": "Western",
"MarketId": 3,
"SalesCategories": {
"Produce": [
{
"Type": "Plums",
"Name": "Red Plums",
"DatePicked": "2016-11-08T14:14:33.712Z",
"ShelfLifeInDays": 12,
"Calories": 21,
"Price": 0.33
},
{
"Type": "Pears",
"Name": "Golden Nature",
"DatePicked": "2016-11-08T14:14:33.712Z",
"ShelfLifeInDays": 20,
"Calories": 40,
"Price": 0.45
}
],
"BakedGoods": [
{
"DateMade": "2016-11-08T14:14:33.712Z",
"Name": "Plum Pie",
"Price": 18.25
}
],
"RestaurantItems": [
{
"Name": "Ham Sandwich",
"Price": 4.85,
"PreparationTimeInMinutes": 20
},
{
"Name": "Chicken Soup",
"Price": 2.25,
"PreparationTimeInMinutes": 5
}
],
"NonPerishable": [
{
"Name": "Mayo",
"Type": "Condiments"
},
{
"Name": "Syrup",
"Type": "Condiments"
},
{
"Name": "Ginger",
"Type": "Spices"
}
]
}
}
]
}
I have the following U-SQL, that processes this JSON file, running inside Visual Studio:
DECLARE #in string=#"/JsonDoc2.json";
DECLARE #out string=#"Output/JsonDoc2.csv";
#produce =
EXTRACT Name string,
DatePicked DateTime,
ShelfLifeInDays int,
Calories int,
Price decimal,
MarketId string,
MarketName string
FROM #in
USING new MultiLevelJsonExtractor("MarketLocations[*].SalesCategories.Produce[*]",
false,
"Name",
"DatePicked",
"ShelfLifeInDays",
"Calories",
"Price",
"MarketId",
"MarketName");
OUTPUT #produce
TO #out
USING Outputters.Csv(outputHeader : true);
This executes without error. The problem is that I am specifically specifying what sales category I want ('produce'). I'd like to change this query so that that all sales categories are included (produce, baked goods etc.) with the category name included. I've not been able to figure out a way to do this.
The JsonType method of the NewtonSoft JsonFunctions class, returns a MAP value which is a key-value pair. You can then reference the key to get the JSON property / object / array names, at least after a few other manipulations with CROSS APPLY and EXPLODE.
For your example, I got the following to work:
REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
USING Microsoft.Analytics.Samples.Formats.Json;
DECLARE #input string = #"/input/myinputfile.json";
DECLARE #output string = #"output/output.csv";
#json =
EXTRACT Region string,
MarketName string,
SalesCategories string // get the SalesCategories as JSON
FROM #input
USING new MultiLevelJsonExtractor("MarketLocations[*].SalesCategories",
true,
"Region",
"MarketName",
"SalesCategories"
);
// Convert the json string to tuple/MAP
#working =
SELECT Region,
MarketName,
JsonFunctions.JsonTuple(SalesCategories) AS x
FROM #json;
// Explode the tuple as key-value pair;
#working =
SELECT Region,
MarketName,
key,
value
FROM #working
CROSS APPLY
EXPLODE(x) AS y(key, value);
// Explode the value which is JSON
#working =
SELECT Region,
MarketName,
key,
JsonFunctions.JsonTuple(y) AS z
FROM #working
CROSS APPLY
EXPLODE(JsonFunctions.JsonTuple(value).Values) AS x(y);
// Prep the result, naming the items you want
#result =
SELECT Region,
MarketName,
key,
z["Type"] AS Type,
z["Name"] AS Name,
z["DatePicked"] AS DatePicked,
z["ShelfLifeInDays"] AS ShelfLifeInDays,
z["Calories"] AS Calories,
z["Price"] AS Price,
z["DateMade"] AS DateMade,
z["PreparationTimeInMinutes"] AS PreparationTimeInMinutes
FROM #working;
OUTPUT #result
TO #output
USING Outputters.Csv(quoting:false);
My results:
It feels like it could be simplified, but see how you get on. The samples for shredding JSON are in short supply but try here and here.
I have assigned level to each node. Now on each level, I want nodes to appear in same order in which it is inserted. That's what even documentation says. I have seen many examples where it happens and only difference with my case is: there are edges on X axis too.
Here's a snippet:
function main() {
var graph = {
nodes: new vis.DataSet([
{ "id": "M1", "label": "M1", "level": 0 },
{ "id": "R1", "label": "R1", "level": 0 },
{ "id": "W1", "label": "W1", "level": 0 },
{ "id": "C1R1", "label": "C1R1", "level": 1 },
{ "id": "C2R1", "label": "C2R1", "level": 1 },
{ "id": "R2R1", "label": "R2R1", "level": 1 },
{ "id": "W2R1", "label": "W2R1", "level": 1 },
{ "id": "C3R1", "label": "C3R1", "level": 1 }
]),
edges: new vis.DataSet([
{ "from": "M1", "to": "R1" },
{ "from": "W1", "to": "R1" },
{ "from": "M2", "to": "R2" },
{ "from": "W2", "to": "R2" },
{ "from": "R1", "to": "C1R1" },
{ "from": "R1", "to": "C2R1" },
{ "from": "C2R1", "to": "R2R1" },
{ "from": "W2R1", "to": "R2R1" },
{ "from": "R1", "to": "C3R1" }
])
};
var options = {
nodes: {
borderWidth: 1,
borderWidthSelected: 1,
shape: "box",
color: {
border: 'lightgray',
background: 'white',
highlight: {
border: 'lightgray',
background: 'lightblue'
},
hover: {
border: 'lightgray',
background: 'lightblue'
}
}
},
edges: {
smooth: {
type: 'cubicBezier',
forceDirection: 'vertical',
roundness: 1
},
color: 'lightgray'
},
layout: {
hierarchical: {
direction: 'UD',
nodeSpacing: 150
}
},
interaction: {
dragNodes: true
},
physics: false,
edgeMinimization: false,
blockShifting: false
};
var network = new vis.Network(document.getElementById("network"), graph, options);
}
#network {
width: 100%;
height: 180px;
}
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.min.js"></script>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.16.1/vis.min.css" />
</head>
<body onload="main();">
<div id="network"></div>
</body>
The main bit is:
var nodes = new vis.DataSet([
{"id": "M1", "label": "M1", "level": 0},
{"id": "R1", "label": "R1", "level": 0},
{"id": "W1", "label": "W1", "level": 0},
{"id": "C1R1", "label": "C1R1", "level": 1},
{"id": "C2R1", "label": "C2R1", "level": 1},
{"id": "R2R1", "label": "R2R1", "level": 1},
{"id": "W2R1", "label": "W2R1", "level": 1},
{"id": "C3R1", "label": "C3R1", "level": 1}
]);
It's a family tree so I want that husband, wife and marriage node stay together.
This is what I am getting:
This is what I am looking for:
Basically on X axis, nodes should be shown in same order as they are inserted (thus no crossing or overlapping).
I have tried by keeping edge minimization as false, blockShifting as false. Tried even by giving x position, but it will still adjust itself.
Do let me know if there is any way to get it or there is no way.
I finally decided to solve it by calculating positions of each node and fixing it.
Decide shape and corresponding size, spacing required by each node.
Level is already defined so that will give you 'y' co-ordinate of each node.
And for 'x' co-ordinate, say each node require space of 30 px and you want to keep margin of 5px on each side, so total 40 px.
At each level, for each node, you calculate how much x space (width) is required to draw all its child node and go on recursively.
In above example, R1 would need 200 (40*5) px width for x, so M1 and W1 can be drawn after or before that only. R1 can be drawn at center of 200 px width and we can get positions for C1R1, C2R1,R2R2, W2R1 and C3R1 by utilizing 40px for each.
If we start drawing at let's say: -200, 0
Then
M1 => x : -180, y : 0 (occupying space from -200 to -160)
R1 => x : -60, y : 0 (occupying space from -160 to 40)
W1 => x : 60, y: 0 (occupying space from 40 to 80)
C1R1 => -140, y: 40 (occupying space from -160 to -120)
C2R1 => -100, y: 40 (occupying space from -120 to -80)
R2R2 => -60, y: 40 (occupying space from -80 to -40)
W2R1 => -20, y: 40 (occupying space from -40 to 0)
C3R1 => 20, y: 40 (occupying space from 0 to 40)
Let me know if you want me to write exact code. It was very different for me, as I had different sizes of node and some other relationships etc