Skip to content

Commit

Permalink
Remove the empty artifact from all types of networks
Browse files Browse the repository at this point in the history
Augmenting the changes from PR se-sic#149, the empty artifact, which results
from untracked files, is not a part of any network type anymore.

This is change is based on commit d9f527c
and fixes se-sic#153.

This is a preliminary implementation with regard to issue se-sic#154.

Signed-off-by: Claus Hunsen <[email protected]>
  • Loading branch information
clhunsen authored and fehnkera committed Sep 23, 2020
1 parent 68c4715 commit 034bc76
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 36 deletions.
65 changes: 47 additions & 18 deletions tests/test-networks-artifact.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,13 @@ if (!dir.exists(CF.DATA)) CF.DATA = file.path(".", "tests", "codeface-data")

test_that("Network construction of the undirected artifact-cochange network", {

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(artifact.relation = "cochange"))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## build network
network.built = network.builder$get.artifact.network()

## vertex attributes
## build expected network:
## 1) vertices
vertices = data.frame(name = c("Base_Feature", "foo", "A"),
kind = "Feature",
type = TYPE.ARTIFACT)

data = data.frame(
## 2) edges
edges = data.frame(
from = c("Base_Feature", "Base_Feature"),
to = c("foo", "foo"),
date = get.date.from.string(c("2016-07-12 16:06:32", "2016-07-12 16:06:32")),
Expand All @@ -65,9 +53,50 @@ test_that("Network construction of the undirected artifact-cochange network", {
type = TYPE.EDGES.INTRA,
relation = "cochange"
)
## 3) build expected network
network.expected = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices)


## build expected network
network.expected = igraph::graph.data.frame(data, directed = FALSE, vertices = vertices)
##
## without untracked files
##

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", TRUE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(artifact.relation = "cochange"))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## build network
network.built = network.builder$get.artifact.network()

## test
expect_true(igraph::identical_graphs(network.built, network.expected))


##
## with untracked files
##

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(artifact.relation = "cochange"))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## build network
network.built = network.builder$get.artifact.network()

## test
expect_true(igraph::identical_graphs(network.built, network.expected))
})
97 changes: 80 additions & 17 deletions tests/test-networks-author.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ test_that("Amount of authors (author.all.authors, author.only.committers).", {
## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", TRUE)
net.conf = NetworkConf$new()

## update network configuration
Expand Down Expand Up @@ -198,25 +199,13 @@ test_that("Amount of authors (author.all.authors, author.only.committers).", {

test_that("Network construction of the undirected author-cochange network", {

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(author.relation = "cochange"))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## build network
network.built = network.builder$get.author.network()

## vertex attributes
## build expected network:
## 1) vertices
authors = data.frame(name = c("Björn", "Olaf", "Karl", "Thomas"),
kind = TYPE.AUTHOR,
type = TYPE.AUTHOR)

## edge attributes
## 2) edges
data = data.frame(comb.1. = c("Björn", "Björn", "Olaf", "Olaf", "Olaf", "Olaf", "Karl", "Karl"),
comb.2. = c("Olaf", "Olaf", "Karl", "Karl", "Thomas", "Thomas", "Thomas", "Thomas"),
date = get.date.from.string(c("2016-07-12 15:58:59", "2016-07-12 16:00:45", "2016-07-12 16:05:41",
Expand All @@ -234,10 +223,51 @@ test_that("Network construction of the undirected author-cochange network", {
type = TYPE.EDGES.INTRA,
relation = "cochange"
)

## build expected network
## 3) build expected network
network.expected = igraph::graph.data.frame(data, directed = FALSE, vertices = authors)


##
## without untracked files
##

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(author.relation = "cochange"))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## build network
network.built = network.builder$get.author.network()

## test
expect_true(igraph::identical_graphs(network.built, network.expected))


##
## with untracked files
##

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", TRUE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(author.relation = "cochange"))

## construct objects
proj.data = ProjectData$new(project.conf = proj.conf)
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)

## build network
network.built = network.builder$get.author.network()

## test
expect_true(igraph::identical_graphs(network.built, network.expected))
})

Expand Down Expand Up @@ -557,3 +587,36 @@ test_that("Network construction of the undirected author-issue network with just

expect_true(igraph::identical_graphs(network.built, network.expected))
})


test_that("Network construction with only untracked files (no edges expected)", {

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(author.relation = "cochange"))
net.conf$clear.edge.attributes()

## construct objects and keep just commits on untracked files
proj.data = ProjectData$new(project.conf = proj.conf)
commit.data = subset(proj.data$get.commits(), artifact == UNTRACKED.FILE.EMPTY.ARTIFACT)
proj.data$set.commits(commit.data)

## build network
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)
network.built = network.builder$get.author.network()

## build expected network (two vertices, no edges)
vertices = data.frame(name = c("Karl", "Thomas"), kind = TYPE.AUTHOR, type = TYPE.AUTHOR)
edges = create.empty.edge.list()
network.expected = igraph::graph.data.frame(edges, directed = FALSE, vertices = vertices)
## add missing edge attributes
network.expected = igraph::set.edge.attribute(network.expected, "weight", value = as.numeric(NA))
network.expected = igraph::set.edge.attribute(network.expected, "type", value = as.character(NA))
network.expected = igraph::set.edge.attribute(network.expected, "relation", value = as.character(NA))

## test
expect_true(igraph::identical_graphs(network.built, network.expected))
})
44 changes: 44 additions & 0 deletions tests/test-networks-bipartite.R
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,47 @@ test_that("Construction of the directed bipartite network for the featureexpress

expect_true(igraph::identical_graphs(network.built, network.expected))
})


test_that("Network construction with only untracked files (no edges and artifacts expected)", {

## configurations
proj.conf = ProjectConf$new(CF.DATA, CF.SELECTION.PROCESS, CASESTUDY, ARTIFACT)
proj.conf$update.value("commits.filter.base.artifact", FALSE)
proj.conf$update.value("commits.filter.untracked.files", FALSE)
net.conf = NetworkConf$new()
net.conf$update.values(updated.values = list(author.relation = "cochange"))
net.conf$clear.edge.attributes()

## construct objects and keep just commits on untracked files
proj.data = ProjectData$new(project.conf = proj.conf)
commit.data = subset(proj.data$get.commits(), artifact == UNTRACKED.FILE.EMPTY.ARTIFACT)
proj.data$set.commits(commit.data)

## build network
network.builder = NetworkBuilder$new(project.data = proj.data, network.conf = net.conf)
network.built = network.builder$get.bipartite.network()

## build expected network (two vertices, no edges):
## 1) construct vertices
vertices = data.frame(name = c("Karl", "Thomas"), kind = TYPE.AUTHOR, type = TYPE.AUTHOR)
## 2) add edge first to obtain edge attributes
edges = network.expected.data = data.frame(
from = c("Karl"),
to = c("Thomas"),
date = get.date.from.unix.timestamp(0),
artifact.type = "",
weight = 0,
type = TYPE.EDGES.INTRA,
relation = "cochange"
)
## 3) construct network
network.expected = construct.network.from.edge.list(vertices = vertices, edge.list = edges, network.conf = net.conf,
directed = net.conf$get.value("author.directed"))
## 4) remove edge again
network.expected = igraph::delete.edges(network.expected, 1)

## test
expect_true(igraph::identical_graphs(network.built, network.expected))
})

20 changes: 19 additions & 1 deletion util-networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,13 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
directed = FALSE
)

## remove the artifact vertices stemming from untracked files if existing
if ("name" %in% igraph::list.vertex.attributes(artifacts.net) &&
length(igraph::V(artifacts.net)[name == UNTRACKED.FILE.EMPTY.ARTIFACT]) > 0) {

artifacts.net = igraph::delete.vertices(artifacts.net, UNTRACKED.FILE.EMPTY.ARTIFACT)
}

## store network
private$artifacts.network.cochange = artifacts.net
logging::logdebug("get.artifact.network.cochange: finished.")
Expand Down Expand Up @@ -728,8 +735,14 @@ NetworkBuilder = R6::R6Class("NetworkBuilder",
return(vertices)
})

## Merge network data and construct a vertex-only network for now
## Merge network data and construct a vertex-only network for now:
## 1) construct vertex data (without edges)
vertex.data = merge.network.data(vertex.data = vertex.data, edge.data = NULL)[["vertices"]]
## 2) remove empty artifact, if names are available
if ("name" %in% colnames(vertex.data)) {
vertex.data = subset(vertex.data, !(name == UNTRACKED.FILE.EMPTY.ARTIFACT & type == TYPE.ARTIFACT))
}
## 3) construct network without edges
vertex.network = igraph::graph.data.frame(
d = create.empty.edge.list(),
vertices = vertex.data,
Expand Down Expand Up @@ -1177,7 +1190,12 @@ add.edges.for.bipartite.relation = function(net, bipartite.relations, network.co

## construct edges (i.e., a vertex sequence with c(source, target, source, target, ...))
vertex.sequence.for.edges = parallel::mcmapply(function(d, a.df) {
## get list of artifacts from edge list
a = a.df[["data.vertices"]]

## remove empty artifact
a = a[a != UNTRACKED.FILE.EMPTY.ARTIFACT]

new.edges = lapply(a, function(vert) {
igraph::V(net)[d, vert] # get two vertices from source network: c(author, artifact)
})
Expand Down

0 comments on commit 034bc76

Please sign in to comment.