0

I have vertices people, usertype, and location. People has outgoing edges people_location and people_usertype. People has property 'name', usertype has property 'activationStatus', and location has property 'name'.

I want to create a list that looks like this:

[[1]: https://i.stack.imgur.com/lKzZL.png]

I want the count of people, by location, for activationStatus "active" and "inactive" where the location has "US" in it.

This is all I have only for count of people by location where the location 'name' begins with US:

g.V()hasLabel('people').out('people_publicisofficelocation')
.filter(has('name',between('US','UT')))
.groupCount().by('name')

It is running but not yielding results.

Veronica
  • 145
  • 12
  • Do you have any code you could show that you've attempted solving this problem? – Tristan Mar 22 '19 at 15:12
  • I updated the question with all I have been able to come up with (I am very new to gremlin) – Veronica Mar 22 '19 at 15:25
  • Just pointing out the obvious: `UK` is not `US`. – Daniel Kuppitz Mar 22 '19 at 18:02
  • It is always best when asking Gremlin questions to provide a sample data script so that you can get a fully tested answer - here is an example https://stackoverflow.com/questions/51388315/gremlin-choose-one-item-at-random – stephen mallette Mar 22 '19 at 19:45
  • Daniel- yep you’re right my bad, however I did run the same code with US and it wasn’t working. I basically just need to be able to filter by whatever I want – Veronica Mar 23 '19 at 19:12

2 Answers2

1

You can simulate 'starts with' behavior in versions of TinkerPop prior to 3.4 using something like has('name',between('US','UT')) so you could replace the filter line above with that. If the graph implementation you are using supports TinkerPop 3.4 there are additional text predicates you can use for begins with, ends with and contains.

As others have said if you can post some sample addV() and addE() steps that build part of your graph it will be easier to give a more precise answer.

Kelvin Lawrence
  • 14,674
  • 2
  • 16
  • 38
  • 1
    Hi Kelvin, that worked! Thanks. Unfortunately I do not have access to the addV() and addE() steps. Is my description unclear? – Veronica Mar 25 '19 at 13:46
  • Glad it worked. Would be great if you could accept the answer please so others can see it is answered. Many thanks. Was only asking about the `addV()` and `addE()` in case there was more to your questions. Cheers. – Kelvin Lawrence Mar 25 '19 at 18:34
1

This worked for me!

g.V().hasLabel('Location').filter(has('name',between('US','UT'))) .project('Name','Active', 'Inactive', 'Total')  .by('name')  .by(__.both('people_location').out('people_usertype') .where(values('activationStatus').is(eq('Active'))).count())  .by(__.both('people_location').out('people_usertype') .where(values('activationStatus').is(eq('Inactive'))).count())  .by(__.both('people_location').out('people_usertype').count())

Veronica
  • 145
  • 12