ctsit / redcapcustodian

Simplified, automated data management on REDCap systems
Other
12 stars 6 forks source link

Write a function `write_summary_metrics` #89

Closed pbchase closed 1 year ago

pbchase commented 1 year ago

Write a function write_summary_metrics and the MySQL Schema file to create the table to which it would write.

write_summary_metrics should accept these parameters:

reporting_period_start - e.g., 2022-11-01 00:00:00 EST
reporting_period_end - e.g., 2022-11-30 23:59:59 EST
metric_type - e.g., flux, state
metric_dataframe - A wide data frame of key-value pairs with a single row of data

write_summary_metrics should access the environment defined in https://github.com/ctsit/redcapcustodian/blob/master/R/logging.R to read the values script_run_time and script_name.

write_summary_metrics should pivot_longer metric_dataframe creating the columns key and value. It should then column_bind these facts to each row in that long dataframe:

script_name
script_run_time
reporting_period_start
reporting_period_end
metric_type

It should insert these data into a table with this schema:

id - integer autoincrementing primary key
reporting_period_start - datetime
reporting_period_end - datetime
key - varchar
value - double? or varchar?
metric_type - varchar
script_name - varchar
script_run_time - datetime

Make sure to include the schema file in the PR.

Please include at least one test to verify that a few rows of data can be written to an in-memory SQLite table with that specified schema. I don't think SQLite supports autoincrement fields, so this might be a bit hacky. See what you can do.

pbchase commented 1 year ago

Addressed by PR #95