Page 1 of 1
A little help on dealing with Map
Posted: 03 Apr 2017 15:58
by husky
Hello,
"Basic Research is what I do when I don't know what I'm doing".
So in my Basic Research i'm using the getFlowStatisticsDuration(). As per Help, it looks to me that the return from the function is a Map.
How do I get the key/value pair from the function.
I know how to add pairs manually to a Map but can't figure out how to get hold of the existing ones in the function.
I tried many variations before posting but all ended up nowhere.
Thank You
Husky
Re: A little help on dealing with Map
Posted: 03 Apr 2017 21:36
by Scotty
Let's say that your current script is:
HuskyFlowStats=getFlowStatisticsDuration();
The variable HuskyFlowStats is a comma-separated map of every key/value pair (example: {FlowName1=45665, FlowName2=7534, FlowName3=....} )
The next lines in your script are determined by exactly what you want to extract. Say you want to extract the name of the longest-duration flow, and its actual duration. You could get that by adding the following lines to the script:
start=indexOf(HuskyFlowStats, "{", + 1);// sets the start point at the position after the squiggly bracket
end=indexOf(HuskyFlowStats, ",", start);// sets the end point at the first comma after "start"
LongestFlow = substring(HuskyFlowStats, start, end);//extracts, as a string, the characters delimited above
Assuming we're starting with the values (in HuskyFlowStats) that I provided above, then the variable LongestFlow will contain the key/value pair FlowName1=45665
Re: A little help on dealing with Map
Posted: 04 Apr 2017 15:21
by Martin
Hi,
You can get the keys and values of a map with functions
getMapKeys and
getMapValues.
Please also check out the script example page:
Script examples (scroll down to the Maps section).
You could use following script to get the flow with the longest duration:
stats = getFlowStatisticsDuration();
key = getMapKeys(stats)[0];//the first key
value = stats[key];//get the value for the key
Regards,
Martin
Re: A little help on dealing with Map
Posted: 04 Apr 2017 15:30
by Scotty
Thanks Martin - I knew how to get all keys (or all values) using the getMapKeys (or getMapValues), and I knew that you could find the value of a key whose name you already know, using "KeyName"; but I didn't know that you could get the name / value of a key (without knowing its name) by its zero-based index position in the map. Very useful, and a good deal simpler than what I posted.
Re: A little help on dealing with Map
Posted: 04 Apr 2017 18:50
by husky
To Martin and Scotty and all of you who had the patience to bear with me.
Thanks both for the information given in your reply. Both are useful for what I have in my plans for the Flow I'm developing. So far only 86 of them and learning.
The problem is that I'm running out of new ideas. WIll keep trying though.
Best Regards
Husky