Skip to content
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

form schema constructor based on data.frame/Excel/CSV input #65

Closed
Ryo-N7 opened this issue Feb 8, 2023 · 3 comments
Closed

form schema constructor based on data.frame/Excel/CSV input #65

Ryo-N7 opened this issue Feb 8, 2023 · 3 comments

Comments

@Ryo-N7
Copy link
Collaborator

Ryo-N7 commented Feb 8, 2023

based off of the work done in #44 #32 >> next step would be to let users have a data.frame, imported CSV/Excel file in R be transformed into an activityinfo form by using the various form schema helper functions

the difficult part would be stuff like single-select/multiple select since those would all be simple 'text' fields in a data.frame when checked with str() or dplyr::glimpse(). so i imagine for special fields, the user would need to specify certain columns/fields in their data.frame to be a certain field type so that the constructor function will handle it properly when creating the form schema based off the data.frame

@nickdickinson
Copy link
Collaborator

  1. First draft: implement without automatic identification of multi-select. Single select as an option (like with factors in data.frame, e.g. if there are < 10 different values). Mostly text as narrative values. Dates as accepted innocently or with minimal checking --> otherwise short text column. --> creates formSchema & data frame
  2. migrateField for converting narrative fields into multi-select or anything else
  3. Second draft: Improvement of import and conversion function
  4. Vignette on dealing with multi-select fields and dates with custom functions and/or specifications

@nickdickinson
Copy link
Collaborator

So the branch for v4.33 has formSchemaFromData(x, databaseId, label, folderId = databaseId, keyColumns = character(), logicalAsSingleSelect = TRUE, logicalText = c("True","False")) which will build a formSchema from a data.frame.

formSchemaFromData(x = tibble(a = 1:5, b = factor(paste0(1:5, "_stuff")), a_logical_column = 1:5==4, date_col = (seq(as.Date("2021-07-06"),as.Date("2021-07-10"),by = 1))), databaseId = "Some database", label = "My new form schema!!", keyColumns = "b", logicalAsSingleSelect = FALSE)

I have left more to the user in terms of dealing with dates but it will create a formSchema with a date form field if there is a date column. A date-time column is converted to a character column for now since I didn't find an equivalent type and it would be up to the user to split it into two columns with date and time if necessary.

Would it could be useful to have a way to select existing columns from existing forms to duplicate into a new schema? This might be a more natural way of dealing with data that may have sub-forms and reference fields and/or multiple select.

@Ryo-N7
Copy link
Collaborator Author

Ryo-N7 commented Mar 13, 2023

Would it could be useful to have a way to select existing columns from existing forms to duplicate into a new schema? This might be a more natural way of dealing with data that may have sub-forms and reference fields and/or multiple select.

yeah i think this would be nice, because there are times we may want to create sub-forms or similar form-subform relationships more than once

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants