Skip to content

Commit

Permalink
WIP for Issue se-sic#119
Browse files Browse the repository at this point in the history
Signed-off-by: Claus Hunsen <[email protected]>
  • Loading branch information
clhunsen committed Feb 21, 2020
1 parent 75ae4a5 commit bb0d9c8
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions util-networks.R
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",

## * * network caching ---------------------------------------------

authors.network.mail = NULL, # igraph
authors.network.cochange = NULL, # igraph
authors.network.issue = NULL, #igraph
authors.network.data.mail = NULL, # igraph
authors.network.data.cochange = NULL, # igraph
authors.network.data.issue = NULL, #igraph
artifacts.network.cochange = NULL, # igraph
artifacts.network.callgraph = NULL, # igraph
artifacts.network.mail = NULL, # igraph
Expand Down Expand Up @@ -160,13 +160,13 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
#' If it does not already exist build it first.
#'
#' @return the author network with cochange relation
get.author.network.cochange = function() {
logging::logdebug("get.author.network.cochange: starting.")
get.author.network.data.cochange = function() {
logging::logdebug("get.author.network.data.cochange: starting.")

## do not compute anything more than once
if (!is.null(private$authors.network.cochange)) {
logging::logdebug("get.author.network.cochange: finished. (already existing)")
return(private$authors.network.cochange)
if (!is.null(private$authors.network.data.cochange)) {
logging::logdebug("get.author.network.data.cochange: finished. (already existing)")
return(private$authors.network.data.cochange)
}

## Get a list of all artifacts extracted from the commit data. Each artifact in this group is again a list
Expand Down Expand Up @@ -204,7 +204,7 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
author.net.data[["vertices"]] = authors

## construct network from obtained data
author.net = construct.network.from.edge.list(
author.net.data = list(
author.net.data[["vertices"]],
author.net.data[["edges"]],
network.conf = private$network.conf,
Expand All @@ -213,24 +213,24 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
)

## store network
private$authors.network.cochange = author.net
logging::logdebug("get.author.network.cochange: finished.")
private$authors.network.data.cochange = author.net.data
logging::logdebug("get.author.network.data.cochange: finished.")

return(author.net)
return(author.net.data)
},

#' Get the thread-based author relation as network.
#' If it does not already exist build it first.
#'
#' @return the author network with mail relation
get.author.network.mail = function() {
get.author.network.data.mail = function() {

logging::logdebug("get.author.network.mail: starting.")
logging::logdebug("get.author.network.data.mail: starting.")

## do not compute anything more than once
if (!is.null(private$authors.network.mail)) {
logging::logdebug("get.author.network.mail: finished. (already existing)")
return(private$authors.network.mail)
if (!is.null(private$authors.network.data.mail)) {
logging::logdebug("get.author.network.data.mail: finished. (already existing)")
return(private$authors.network.data.mail)
}

## construct edge list based on thread2author data
Expand All @@ -242,7 +242,8 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
)

## construct network from obtained data
author.net = construct.network.from.edge.list(
## FIXME rename this variable somehow. analogously for the other relations!
author.net.data = list(
author.net.data[["vertices"]],
author.net.data[["edges"]],
network.conf = private$network.conf,
Expand All @@ -251,19 +252,19 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
)

## store network
private$authors.network.mail = author.net
logging::logdebug("get.author.network.mail: finished.")
private$authors.network.data.mail = author.net.data
logging::logdebug("get.author.network.data.mail: finished.")

return(author.net)
return(author.net.data)
},

##get the issue based author relation as network
get.author.network.issue = function() {
logging::logdebug("get.author.network.issue: starting.")
get.author.network.data.issue = function() {
logging::logdebug("get.author.network.data.issue: starting.")

if (!is.null(private$authors.network.issue)) {
logging::logdebug("get.author.network.issue: finished. (already existing)")
return(private$authors.network.issue)
if (!is.null(private$authors.network.data.issue)) {
logging::logdebug("get.author.network.data.issue: finished. (already existing)")
return(private$authors.network.data.issue)
}

## construct edge list based on issue2author data
Expand All @@ -275,18 +276,18 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
)

## construct network from obtained data
author.net = construct.network.from.edge.list(
author.net.data = list(
author.net.data[["vertices"]],
author.net.data[["edges"]],
network.conf = private$network.conf,
directed = private$network.conf$get.value("author.directed"),
available.edge.attributes = private$proj.data$get.data.columns.for.data.source("issues")
)

private$authors.network.issue = author.net
logging::logdebug("get.author.network.issue: finished.")
private$authors.network.data.issue = author.net.data
logging::logdebug("get.author.network.data.issue: finished.")

return(author.net)
return(author.net.data)
},

## * * artifact networks -------------------------------------------
Expand Down Expand Up @@ -553,9 +554,9 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
#' Reset the current environment in order to rebuild it.
#' Has to be called whenever the data or configuration get changed.
reset.environment = function() {
private$authors.network.mail = NULL
private$authors.network.cochange = NULL
private$authors.network.issue = NULL
private$authors.network.data.mail = NULL
private$authors.network.data.cochange = NULL
private$authors.network.data.issue = NULL
private$artifacts.network.cochange = NULL
private$artifacts.network.callgraph = NULL
private$proj.data = private$proj.data.original
Expand Down Expand Up @@ -626,15 +627,16 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
## construct network
relations = private$network.conf$get.value("author.relation")
networks = lapply(relations, function(relation) {
network = switch(
network.data = switch(
relation,
cochange = private$get.author.network.cochange(),
mail = private$get.author.network.mail(),
issue = private$get.author.network.issue(),
cochange = private$get.author.network.data.cochange(),
mail = private$get.author.network.data.mail(),
issue = private$get.author.network.data.issue(),
stop(sprintf("The author relation '%s' does not exist.", rel))
## TODO construct edge lists here and merge those (inline the private methods)
)

network = do.call(construct.network.from.edge.list, network.data)

## set edge attributes on all edges
igraph::E(network)$type = TYPE.EDGES.INTRA
igraph::E(network)$relation = relation
Expand Down

0 comments on commit bb0d9c8

Please sign in to comment.