Skip to content

Commit

Permalink
Correctly setting zero voltages to NaN in DB cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
exfletch committed Jun 9, 2022
1 parent a70aa07 commit 23fba2b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions BDInterface/data_cleaning_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ voltages_in_bounds <- function(v) {
remove_outlying_voltages <- function(time_series) {
voltage_cols <- c("v", "vmin", "vmax", "vmean")
time_series[, voltage_cols] <- sapply(time_series[, voltage_cols], as.numeric)
old_time_series <- time_series

voltage_extremes <- time_series %>%
select(c("c_id"), voltage_cols) %>%
Expand All @@ -213,5 +214,8 @@ remove_outlying_voltages <- function(time_series) {
time_series[, voltage_cols] *
voltage_extremes[match(time_series$c_id, voltage_extremes$c_id), voltage_cols]
)
time_series['v_changed'] <- rowSums(
is.na(time_series[, voltage_cols]) & !is.na(old_time_series[, voltage_cols])
) > 0
return(time_series)
}
6 changes: 5 additions & 1 deletion BDInterface/interface.R
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,13 @@ DBInterface <- R6::R6Class("DBInterface",

while (length(circuits$c_id) > 0){
time_series <- self$get_time_series_data_by_c_id_full_row(circuits)
time_series <- remove_outlying_voltages(time_series)
records_to_update <- filter(time_series, v_changed)
records_to_update <- within(time_series, rm(v_changed))
self$update_timeseries_table_in_database(records_to_update)

time_series <- mutate(time_series, d = as.numeric(d))
time_series <- mutate(time_series, time = fastPOSIXct(ts, tz="Australia/Brisbane"))
time_series <- remove_outlying_voltages(time_series)
time_series_5s_and_unknown_durations <- filter(time_series, (!d %in% c(30, 60)))
time_series_30s_and_60s_data <- filter(time_series, (d %in% c(30, 60)))
time_series_5s_and_unknown_durations <- self$clean_duration_values(time_series_5s_and_unknown_durations)
Expand Down

0 comments on commit 23fba2b

Please sign in to comment.