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 pivot_longer metric_dataframe creating the columns key and value. It should then column_bind these facts to each row in that long dataframe:
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.
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:write_summary_metrics
should access the environment defined in https://github.com/ctsit/redcapcustodian/blob/master/R/logging.R to read the valuesscript_run_time
andscript_name
.write_summary_metrics
should pivot_longermetric_dataframe
creating the columnskey
andvalue
. It should then column_bind these facts to each row in that long dataframe:It should insert these data into a table with this schema:
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.