0

please find the image here you can find what i really needi want group severity value in the following range 0-250,251-500,501-750 and 751-1000. Please can anyone help.

{
"id": "", "model": "", "name": "", "properties": { "functions": { "boolcheck": { "triggers": { "time": { "value": "" } }, "inhibit": { "referenceValue": { "value": false }, "actualValue": { "$ref": "" } }, "endpoint": { "value": "" }, "inputs": { "inputs": { "signal": { "$ref": "" } }, "parameters": { "normalValue": { "value": "False" } }, "conditions": { "State": { "subConditions": { "Normal": { "description": { "value": "" }, "severity": { "value": 1 },
"logic": { "value": "" } }, "Alarm": { "description": { "value": "" }, "severity": { "value": 1000 } } } } } } } } }, "version": 2 },

sanju m
  • 1
  • 1

1 Answers1

1

I'm going to demonstrate this using TinkerPop's Grateful Dead dataset:

gremlin> g = TinkerFactory.createGratefulDead().traversal()
==>graphtraversalsource[tinkergraph[vertices:808 edges:8049], standard]

The basic approach simply involves using coalesce() in your by() modulator to group() which basically creates an if-then like flow of control:

gremlin> g.V().hasLabel('song').
......1>   group().
......2>     by(values('performances').
......3>        coalesce(is(lt(5)).constant("x<5"),
......4>                 is(lt(10)).constant("5=>x<10"),
......5>                 constant(">=10"))).
......6>     by(count())
==>[x<5:319,>=10:227,5=>x<10:38]

Note that the by(count()) was just added to make the results easier to look at. Obviously, if you need the actual vertices in the grouping you can just remove that line 6.

Note that greater explanation can be found for this approach in Gremlin Recipes.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Hi Stephen, i have added the image to the original question for more details. please can you suggest me how to do it. I am completely new to gremlin query not sure how to find dynamically for severity value and group them into the range. – sanju m Oct 29 '18 at 04:00
  • If you need a highly specific answer to your question then I suggest you please provide a Gremlin script that creates some sample data - here is an example https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Oct 29 '18 at 10:48
  • g.V().has('model','*').valueMap('properties.*.*.*.severity')... Please can you suggest how to find the matching property for severity.... If the property has matching "severity" string then i want to fetch the value. Please can you suggest – sanju m Oct 30 '18 at 05:17