From b00ae9147217593b53730b7ba2e57b044caf11d2 Mon Sep 17 00:00:00 2001 From: Mike Holmes Date: Mon, 8 May 2017 09:13:08 -0400 Subject: Initial commit --- .gitignore | 1 + README | 1 + member_heatmaps.R | 227 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 .gitignore create mode 100644 README create mode 100644 member_heatmaps.R diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..caa9612 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.R diff --git a/README b/README new file mode 100644 index 0000000..52ff45a --- /dev/null +++ b/README @@ -0,0 +1 @@ +Very ugly fast POC diff --git a/member_heatmaps.R b/member_heatmaps.R new file mode 100644 index 0000000..3d1c59a --- /dev/null +++ b/member_heatmaps.R @@ -0,0 +1,227 @@ +library(RCurl) +library(curl) +library(jsonlite) +library(gsubfn) +library(gplots) +library(RColorBrewer) + +#functions +companies <- function (names) +{ + companys = list() + for (name in names) { + for (n in name) { + companys[[length(companys) + 1]] <- + strapplyc(n, "@(.*)", simplify = TRUE) + } + } + company <- unique(companys) + + return (company) +} + +display_hetmap <- function(report, m, suffix) { + report_name <- paste(report["name"], suffix, ".pdf",sep = "") + pdf(file=report_name, title = report["name"],paper="us") + + #display raw data + print(m) + cat("Generating", report_name) + + # following code limits the lowest and highest color to 5%, and 95% of your range, respectively + quantile.range <- quantile(m, probs = seq(0, 1, 0.01)) + palette.breaks <- + seq(quantile.range["5%"], quantile.range["95%"], 0.1) + + # use http://colorbrewer2.org/ to find optimal divergent color palette (or set own) + color.palette <- + colorRampPalette(c("#FC8D59", "#FFFFBF", "#91CF60"))(length(palette.breaks) - 1) + + watcher_heatmap <- + heatmap.2( + m, + dendrogram = 'row', + Rowv = TRUE, + Colv = FALSE, + trace = "none", + margins = c(12, 12), + col = color.palette, + breaks = palette.breaks, + ylab = "company", + xlab = "project" + ) + dev.off() +} + +watcher_heatmap <- function(report) { + baseurl <- "https://projects.linaro.org/rest/api/2/" + fields <- "&fields=watches,key,project" + + type <- "search?" + jql <- paste ("jql=project+in+(",report["team"],")+AND+issuetype+in+(Initiative,Epic)&maxResults=2000", sep = "") + + url <- paste(baseurl, type, jql, fields, sep = "") + cat (url,"\n") + webpage <- curl (url, handle = h) + + #get data it into R + jira_raw <- fromJSON(webpage, simplifyDataFrame = TRUE) + # extract the data node + keys <- jira_raw$issues$key + + #x axis the number of projects + projects <- unique(jira_raw$issues$fields$project$key) + num_projects <- length(projects) + + #projects + #from the website now get watchers names with another query for all keys found previously + fields <- "/watchers" + type <- "issue/" + + names = list() + for (key in keys) { + url <- paste(baseurl, type, key, fields, sep = "") + webpage <- curl (url, handle = h) + jira_raw_names <- fromJSON(webpage, simplifyDataFrame = TRUE) + + names[[length(names) + 1]] <- + as.list(jira_raw_names$watchers$name) + } + + #create empty matrix + comp <- companies(names) + num_comp <- length(comp) + m <- matrix(NA, nrow = num_comp, ncol = num_projects) + colnames(m) <- projects + rownames(m) <- comp + m[] <- 0L + + #from the website now get watchers names with another query for all keys found previously + fields <- "/watchers" + type <- "issue/" + + for (key in keys) { + #y + mike <- match (key, keys) + team <- jira_raw$issues$fields$project$key[mike] + y <- match (team, projects) + + #x + names = list() + url <- paste(baseurl, type, key, fields, sep = "") + webpage <- curl (url, handle = h) + jira_raw_names <- fromJSON(webpage, simplifyDataFrame = TRUE) + + names[[length(names) + 1]] <- as.list(jira_raw_names$watchers$name) + interested = companies(names) + for (c in interested) + { + x <- match (c, comp) + m[x, y] <- m[x, y] + 1 + } + } + + #remove companies + rows.to.delete <- c('linaro.org', 'broadcom.com', 'character') + for (d in rows.to.delete) { + m <- as.matrix(m[!grepl(d, rownames(m)),]) + } + + display_hetmap(report, m,"_wt") +} + + +sponsor_heatmap <- function (report) { + baseurl <- "https://projects.linaro.org/rest/api/2/" + fields <- "&fields=customfield_10101,key,project" + type <- "search?" + + jql <- + paste( + "jql=project+in+(", + report["team"], + ")+AND+issuetype+in+(Initiative,Epic)&maxResults=1000", + sep = "" + ) + url <- paste(baseurl, type, jql, fields, sep = "") + cat (url,"\n") + + webpage <- curl (url, handle = h) + + #get data it into R + jira_raw <- fromJSON(webpage, simplifyDataFrame = TRUE) + #list of every issue + keys <- jira_raw$issues$key + + #x axis the number of projects + projects <- unique(jira_raw$issues$fields$project$key) + num_projects <- length(projects) + + #y axis the companies or sponsors + sponsor <- jira_raw$issues$fields$customfield_10101 + + names = list() + for (key in keys) { + s <- sponsor[[match (key, keys)]][[2]] + for (n in s) { + names[[length(names) + 1]] <- n + } + } + + #create empty matrix + comp <- unique(names) + num_comp <- length(comp) + m <- matrix(NA, nrow = num_comp, ncol = num_projects) + colnames(m) <- projects + rownames(m) <- comp + m[] <- 0L + + # count companies per project by looking at every key and update matrix + + for (key in keys) { + #y + mike <- match (key, keys) + team <- jira_raw$issues$fields$project$key[mike] + y <- match (team, projects) + + #x + s <- sponsor[[match (key, keys)]][[2]] + for (c in s) + { + x <- match (c, comp) + m[x, y] <- m[x, y] + 1 + } + } + + #remove companies we don't like ;) + rows.to.delete <- c('Linaro') + for (d in rows.to.delete) { + m <- as.matrix(m[!grepl(d, rownames(m)),]) + } + + display_hetmap(report, m, "_sp") +} + +#from the website get the initiatives list for the four teams +user_password <- ":" + +h <- new_handle(failonerror = TRUE) +handle_setopt(h, verbose = 0) +handle_setopt(h, userpwd = user_password) +handle_setopt(h, httpauth = 1) + +report_name <- c("coredev", "segment", "ct_t") +team_list <- + c( + "Security,Kernel,'Power',Virtualization,LSK", + "LHG,LEG,LNG,LITE,LMG", + "CTT,BB,LAVA,LAB,QA,SYS,TCWG" + ) +reports <- + data.frame(name = report_name , + team = team_list, + stringsAsFactors = FALSE) +apply(reports, 1, sponsor_heatmap) +apply(reports, 1, watcher_heatmap) + + -- cgit v1.2.3