Chelsyx has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/374924 )
Change subject: Order legends according to the last observed values ...................................................................... Order legends according to the last observed values Bug: T172452 Change-Id: I1552b8f5adf8dde941b567154b08f9d9c674eb5d --- M modules/api.R M modules/key_performance_metrics/api_usage.R 2 files changed, 49 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/discovery/rainbow refs/changes/24/374924/1 diff --git a/modules/api.R b/modules/api.R index 5fd6cd1..6ec9d1d 100644 --- a/modules/api.R +++ b/modules/api.R @@ -1,6 +1,11 @@ output$cirrus_aggregate <- renderDygraph({ split_dataset$cirrus %>% tidyr::spread(referrer, calls) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_fulltext_search)) %>% polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily Full-text search API usage by referrer", legend_name = "Searches") %>% dyLegend(width = 1000, show = "always") %>% @@ -12,6 +17,11 @@ output$morelike_aggregate <- renderDygraph({ split_dataset$`cirrus (more like)` %>% tidyr::spread(referrer, calls) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_morelike_search)) %>% polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily Morelike search API usage by referrer", legend_name = "Searches") %>% dyLegend(width = 1000, show = "always") %>% @@ -21,6 +31,11 @@ output$open_aggregate <- renderDygraph({ split_dataset$open %>% tidyr::spread(referrer, calls) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_open_search)) %>% polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily OpenSearch API usage by referrer", legend_name = "Searches") %>% dyLegend(width = 1000, show = "always") %>% @@ -31,7 +46,13 @@ output$geo_aggregate <- renderDygraph({ split_dataset$geo %>% - tidyr::spread(referrer, calls) %>%polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_geo_search)) %>% + tidyr::spread(referrer, calls) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% + polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_geo_search)) %>% polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily Geo Search API usage by referrer", legend_name = "Searches") %>% dyLegend(width = 1000, show = "always") %>% dyRangeSelector %>% @@ -41,7 +62,13 @@ output$language_aggregate <- renderDygraph({ split_dataset$language %>% - tidyr::spread(referrer, calls) %>%polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_language_search)) %>% + tidyr::spread(referrer, calls) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% + polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_language_search)) %>% polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily Language search API usage by referrer", legend_name = "Searches") %>% dyLegend(width = 1000, show = "always") %>% dyRangeSelector %>% @@ -52,6 +79,11 @@ output$prefix_aggregate <- renderDygraph({ split_dataset$prefix %>% tidyr::spread(referrer, calls) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_prefix_search)) %>% polloi::make_dygraph(xlab = "Date", ylab = "Searches", title = "Daily Prefix search API usage by referrer", legend_name = "Searches") %>% dyLegend(width = 1000, show = "always") %>% @@ -71,6 +103,11 @@ temp <- cbind(temp$date, purrr::map_df(temp[, -c(1, 2)], function(x) round(100 * x / temp$All, 2))) } temp %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% polloi::smoother(smooth_level = polloi::smooth_switch(input$smoothing_global, input$smoothing_referer_breakdown)) %>% polloi::make_dygraph(xlab = "Date", ylab = ifelse(input$referer_breakdown_prop, "API Calls Share (%)", "API Calls"), diff --git a/modules/key_performance_metrics/api_usage.R b/modules/key_performance_metrics/api_usage.R index 1980dda..d8c7271 100644 --- a/modules/key_performance_metrics/api_usage.R +++ b/modules/key_performance_metrics/api_usage.R @@ -17,16 +17,20 @@ } %>% dplyr::bind_rows(.id = "api") %>% tidyr::spread("api", "calls") - api_usage <- dplyr::mutate(api_usage, all = cirrus + dplyr::if_else(is.na(`cirrus (more like)`), 0, `cirrus (more like)`) + geo + language + prefix) + api_usage <- dplyr::mutate(api_usage, all = cirrus + dplyr::if_else(is.na(`cirrus (more like)`), 0, `cirrus (more like)`) + geo + language + prefix) %>% + { + # Reorder columns according to the last observed values: + cols <- unlist(polloi::safe_tail(., 1)[, -1]) + .[, c(1, order(cols, decreasing = TRUE) + 1)] + } %>% + dplyr::rename("full-text via API" = cirrus, "morelike via API" = `cirrus (more like)`) if ( input$kpi_api_usage_series_data == "raw" ) { api_usage %<>% polloi::smoother(ifelse(smooth_level == "global", input$smoothing_global, smooth_level), rename = FALSE) %>% { xts::xts(.[, -1], order.by = .$date) } return(dygraph(api_usage, main = "Calls over time", xlab = "Date", ylab = ifelse(input$kpi_api_usage_series_log_scale, "Calls (log10 scale)", "Calls")) %>% - dySeries("cirrus", label = "full-text via API") %>% - dySeries("cirrus (more like)", label = "morelike via API") %>% - dyLegend(width = 1000, show = "always") %>% + dyLegend(width = 1000, show = "always") %>% dyOptions( strokeWidth = 3, colors = RColorBrewer::brewer.pal(7, "Set2")[7:1], drawPoints = FALSE, pointSize = 3, labelsKMB = TRUE, @@ -40,8 +44,8 @@ } else { api_usage_change <- api_usage %>% dplyr::mutate( - cirrus = polloi::percent_change(cirrus), - `cirrus (more like)` = polloi::percent_change(`cirrus (more like)`), + `full-text via API` = polloi::percent_change(`full-text via API`), + `morelike via API` = polloi::percent_change(`morelike via API`), geo = polloi::percent_change(geo), language = polloi::percent_change(language), open = polloi::percent_change(open), -- To view, visit https://gerrit.wikimedia.org/r/374924 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1552b8f5adf8dde941b567154b08f9d9c674eb5d Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/discovery/rainbow Gerrit-Branch: develop Gerrit-Owner: Chelsyx <c...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits