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

Move data-proc code from server to global.R #39

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions R/data_processing.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,31 @@ compute_aquatroll <- function(aquatroll, ddt) {
names_to = "variable", values_to = "value") ->
aquatroll_600_long

aquatroll_200_long %>%
arrange(Timestamp) %>%
group_by(Well_Name, variable) %>%
slice_tail(n = 10) %>%
ungroup() %>%
select(Timestamp, Well_Name, Instrument, variable, value, Logger_ID, Plot) ->
aq200_long

aquatroll_600_long %>%
arrange(Timestamp) %>%
group_by(Well_Name, variable) %>%
slice_tail(n = 10) %>%
ungroup() %>%
select(Timestamp, Well_Name, Instrument, variable, value, Logger_ID, Plot) %>%
bind_rows(aq200_long) %>%
# at this point we have the full trolls dataset in long form
pivot_wider(id_cols = c("Well_Name", "variable", "Plot", "Instrument"),
names_from = "Timestamp", values_from = "value") ->
aquatroll_table_data

list(aquatroll_600 = aquatroll$aquatroll_600,
aquatroll_200 = aquatroll$aquatroll_200,
aquatroll_600_long = aquatroll_600_long,
aquatroll_200_long = aquatroll_200_long,
aquatroll_table_data = aquatroll_table_data,
aquatroll_bad_sensors = aquatroll_bad_sensors,
aquatroll_bdg = aquatroll_bdg)
}
Expand Down
2 changes: 1 addition & 1 deletion global.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ FLAG_TIME_WINDOW <- 1 # hours back from the dashboard datetime

# The 'no data' graph that's shown if no rows are selected, etc.
NO_DATA_GRAPH <- ggplot() +
annotate("text", x = 1, y = 1, label = "(No data)", size = 12) +
annotate("text", x = 1, y = 1, label = "(No selection)", size = 12) +
theme(axis.title = element_blank(),
axis.text = element_blank(),
)
101 changes: 43 additions & 58 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,25 @@ server <- function(input, output, session) {
trees_selected

dropbox_data()[["sapflow"]] %>%
filter(Sapflow_ID %in% trees_selected) %>%
ggplot(aes(Timestamp, Value, group = Sapflow_ID, color = Plot)) +
shaded_flood_rect(ymin = min(SAPFLOW_RANGE), ymax = max(SAPFLOW_RANGE)) +
filter(Sapflow_ID %in% trees_selected) ->
selected_data

b <- ggplot(selected_data,
aes(Timestamp, Value, group = Sapflow_ID)) +
shaded_flood_rect(ymin = min(SAPFLOW_RANGE),
ymax = max(SAPFLOW_RANGE)) +
geom_line() +
xlab("") +
xlim(c(ddt - GRAPH_TIME_WINDOW * 60 * 60, ddt)) +
geom_hline(yintercept = SAPFLOW_RANGE, color = "grey", linetype = 2) ->
b
geom_hline(yintercept = SAPFLOW_RANGE, color = "grey", linetype = 2)
# Try to assign color intelligently. If different plots are selected,
# have that be the color; otherwise by ID
if(length(unique(selected_data$Plot)) > 1) {
b <- b + aes(color = Plot)
} else {
b <- b + aes(color = Sapflow_ID)
}

} else {
b <- NO_DATA_GRAPH
}
Expand All @@ -331,33 +342,28 @@ server <- function(input, output, session) {
ddt <- reactive({ DASHBOARD_DATETIME() })()

dropbox_data()[["teros_table_data"]] %>%
slice(input$teros_table_rows_selected) %>%
select(variable, ID) ->
slice(input$teros_table_rows_selected) ->
tsensor_selected

dropbox_data()[["teros"]] %>%
filter(ID %in% tsensor_selected$ID,
variable %in% tsensor_selected$variable) -> selected_data

b <- ggplot(selected_data,
aes(Timestamp, value, group = interaction(ID, variable))) +
geom_line() +
xlab("") +
xlim(c(ddt - GRAPH_TIME_WINDOW * 60 * 60, ddt))
# Try to assign color intelligently. If different plots are selected,
# have that be the color; otherwise by depth; otherwise by ID
if(length(unique(selected_data$Plot)) > 1) {
b <- ggplot(selected_data,
aes(Timestamp, value, group = interaction(ID, variable),
color = Plot))
b <- b + aes(color = Plot)
} else if(length(unique(selected_data$Depth)) > 1) {
b <- ggplot(selected_data,
aes(Timestamp, value, group = interaction(ID, variable),
color = Depth))
b <- b + aes(color = Depth)
} else {
b <- ggplot(selected_data,
aes(Timestamp, value, group = interaction(ID, variable),
color = ID))
b <- b + aes(color = ID)
}

b <- b + geom_line() +
xlab("") +
xlim(c(ddt - GRAPH_TIME_WINDOW * 60 * 60, ddt))
} else {
b <- NO_DATA_GRAPH
}
Expand All @@ -369,48 +375,15 @@ server <- function(input, output, session) {

output$troll_table <- DT::renderDataTable({
dataInvalidate()

dropbox_data()[["aquatroll_200_long"]] %>%
group_by(Well_Name, variable) %>%
slice_tail(n = 10) %>%
ungroup() %>%
select(Timestamp, Well_Name, Instrument, variable, value, Logger_ID, Plot) ->
aq200_long

dropbox_data()[["aquatroll_600_long"]] %>%
group_by(Well_Name, variable) %>%
slice_tail(n = 10) %>%
ungroup() %>%
select(Timestamp, Well_Name, Instrument, variable, value, Logger_ID, Plot) %>%
bind_rows(aq200_long) %>%
# at this point we have the full trolls dataset in long form
arrange(Timestamp) %>%
pivot_wider(id_cols = c("Well_Name", "variable", "Plot", "Instrument"),
names_from = "Timestamp", values_from = "value")
dropbox_data()[["aquatroll_table_data"]]
})

output$troll_detail_graph <- renderPlotly({
if(length(input$troll_table_rows_selected)) {

ddt <- reactive({ DASHBOARD_DATETIME() })()

dropbox_data()[["aquatroll_200_long"]] %>%
group_by(Well_Name, variable) %>%
slice_tail(n = 10) %>%
ungroup() %>%
select(Timestamp, Well_Name, Instrument, variable, value, Logger_ID, Plot) ->
aq200_long

dropbox_data()[["aquatroll_600_long"]] %>%
group_by(Well_Name, variable) %>%
slice_tail(n = 10) %>%
ungroup() %>%
select(Timestamp, Well_Name, Instrument, variable, value, Logger_ID, Plot) %>%
bind_rows(aq200_long) -> trolls

trolls %>%
pivot_wider(id_cols = c("Well_Name", "variable", "Plot", "Instrument"),
names_from = "Timestamp", values_from = "value") %>%
dropbox_data()[["aquatroll_table_data"]] %>%
slice(input$troll_table_rows_selected) %>%
select(variable, Well_Name) ->
aqsensor_selected
Expand All @@ -420,13 +393,25 @@ server <- function(input, output, session) {
dropbox_data()[["aquatroll_200_long"]] %>%
bind_rows(dropbox_data()[["aquatroll_600_long"]]) %>%
filter(Well_Name %in% aqsensor_selected$Well_Name,
variable %in% aqsensor_selected$variable) %>%
ggplot(aes(Timestamp, value, group = interaction(Well_Name, variable), color = Well_Name)) +
variable %in% aqsensor_selected$variable) -> selected_data

b <- ggplot(selected_data,
aes(Timestamp, value,
group = interaction(Well_Name, variable))) +
geom_line() +
xlab("") +
labs(color = "Well Name") +
xlim(c(ddt - GRAPH_TIME_WINDOW * 60 * 60, ddt)) ->
b
xlim(c(ddt - GRAPH_TIME_WINDOW * 60 * 60, ddt))
# Try to assign color intelligently. If different plots are selected,
# have that be the color; otherwise by variable; otherwise by name
if(length(unique(selected_data$Plot)) > 1) {
b <- b + aes(color = Plot)
} else if(length(unique(selected_data$variable)) > 1) {
b <- b + aes(color = variable)
} else {
b <- b + aes(color = Well_Name)
}

} else {
b <- NO_DATA_GRAPH
}
Expand Down
Loading