bedatadriven / activityinfo-R

ActivityInfo R Language Client
https://www.activityinfo.org/support/docs/R/
17 stars 12 forks source link

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

Closed Ryo-N7 closed 1 year ago

Ryo-N7 commented 1 year ago

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 commented 1 year ago
  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 commented 1 year ago

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 commented 1 year ago

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