I need to find the percentage of recipients who picked at least one call for a given program.
I have this schema. Calls are made to the users as part of certain programs, which fall under a unit of an organization.
My goal is: Of the total number of users who received calls (connected = yes) as part of program X, how many of them picked at least one call (picked = yes) (I need to find the %)
To find the list of recipients who received at least 1 call:
g.V().hasLabel("User").filter(inE().has("connected","yes").filter(outV().in().has("Program","name","X")).count().is(gte(1))).count()
Similarly, to find the list of recipients who picked at least 1 call:
g.V().hasLabel("User").filter(inE().has("picked","yes").filter(outV().in().has("Program","name","X")).count().is(gte(1))).count()
I know I need to take the ratio of these values. I did my research and realized that I need to make two parallel traversals and use math() to find the percentage. I tried the following query:
g.V().hasLabel("User").as("a","b").
math("a/b * 100").
by(filter(inE().has("picked","yes").
filter(outV().in().has("program","name","X")).count().is(gte(1)))
.count()).
by(filter(inE().has("connected","yes").
filter(outV().in().has("program","name","X")).count().is(gte(1)))
.count())
But I get the following error:
Division by zero!
Type ':help' or ':h' for help.
Display stack trace? [yN]
What I think is happening is that this query is generating the percentage for each user (not what I intended) and for users who never received any call under program 'X', the denominator is understandably 0.
How can I write a query that gives me the intended ratio? How can I make the right traversals?