-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve expansion of reference records, parent records and sub-form records #136
Comments
@jamiewhths Forgot to mention this. I worked out a couple of options for an implementation of what we discussed. Option 1 would be easy to implement BUT only if we stick to our existing varNames() implementation which then limits the expansion in cycles. For example, [supervisor].[employee].[supervisor] would not work because we do not revisit forms during the variable expansion. If we parse the variable names and perhaps do a little re-write on varNames() then we could expand arbitrarily into cycles and would require more effort initially to code. Is there a way for us to do this with the help of the server? For example, send the '[Inhabitant].[Mother].[Full name]' to the server and get back the field id if it is correct? For a whole list of columns? Option 2 would allow arbitrary expansion into cycles. A bit more effort as we'll be implementing the dplyr verbs but more standardized from an R / data science perspective. Want to place this in a 4.39 milestone? |
I think what makes most sense here is to add an argument to getRecords to leverage the ability to specify columns in inhabitantForm %>% getRecords(columns = c(
'Household ID' = '@parent.[ID]',
'Inhabitant name' = '[Inhabitant].[Full name]',
'Mother name' = '[Inhabitant].[Mother].[Full name]',
'Father name' = '[Inhabitant].[Father].[Full name]',
'HH head gender' = '@parent.[Head of household].[Gender]')
'HH head age' = '@parent.[Head of household].[Age]'))
It looks like, in order to do this, the following line in -->
A more sophisticated approach is to additionally modify This would allow the following approach: inhabitantForm %>% getRecords() %>% select(
`mother_name` = `[Inhabitant].[Mother].[Full name]`
) |
I think I cracked the nut by the way @jamiewhths. I can now do: # create an officer column using an ActivityInfo variable expression in select()
x %>% select(`_lastEditTime`, officer = `ce8xfhgm3x4xtgr5.[Office administrator].[Field Office].[Office administrator].[Field Office].[Office administrator].[Field Office].[c1r6xktm49zvh2l2].field_office.c1r6xktm49zvh2l2.Name`) %>% filter(officer == "Person 1") or even # filter rows that only contain _id and _lastEditTime with a filter that uses an ActivityInfo variable expression
x %>% select(starts_with('_')) %>% filter(`ce8xfhgm3x4xtgr5.[Office administrator].[Field Office].[Office administrator].[Field Office].[Office administrator].[Field Office].[c1r6xktm49zvh2l2].field_office.c1r6xktm49zvh2l2.Name` == "Person 1") It will error if the expression is incorrect before calling the API by checking the formTree. With this, we can also simply use the select statements to add variables when fetching from a form and avoid all recursive styles. We can also implement the |
The implementation is on the |
The This is now supported: x %>% mutate(a = 1) %>% mutate(b = a + a) %>% mutate(c = IF(CONCAT((2*2)+1)==TEXT(4), "It does!", "Nope")) A limited number of R functions are automatically translated including:
Allowing also: x %>% mutate(a = 1) %>% mutate(b = a + a) %>% mutate(c = paste0("Name: ", `[Field.Office].[Office administrator].Name`)) This is great because it means specific columns and 'views' can be generated before collecting the data frame. |
For the convenience of the user and to reduce the load on the server, provide an explicit grammar to allow the user to expand reference fields, parent records and sub-form records. The current automatic expansion would be used to implement these but reduce the load on the server by only showing what users explicitly want to see.
There are two potential approaches that can be implemented.
Approach 1: ActivityInfo label/code based selection of columns.
This would be easiest for ActivityInfo users who dabble in scripts. It would be a wrapper for
getRecords()
andselect()
andrename()
to allow immediately selecting variables in activityInfo style with the label and/or the code or id of each column and choose the resulting names.In pseudo R to get all inhabitants of households with a reference to a Person form for all person fields:
Approach 2: Tidyverse verbs
This is the best from an R developer / data science perspective. We would implement
unnest
verbs. These verbs includeunnest_wider()
for reference fields and parent records andunnest_longer()
for sub-form records and potentiallyunnest_auto()
to automatically choose the most appropriate and potentiallyhoist()
to be more specific in selection. The example below shows how one can use the tidy select functions to powerfully select exactly which variables are needed.In pseudo R to get all inhabitants of households with a reference to a Person form for all person fields:
Principles:
Combined
Both approaches are compatible and could be chained. It is mainly about exposing the most useful API.
The text was updated successfully, but these errors were encountered: