forked from se-sic/coronet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util-bulk.R
251 lines (197 loc) · 8.87 KB
/
util-bulk.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
## This file is part of coronet, which is free software: you
## can redistribute it and/or modify it under the terms of the GNU General
## Public License as published by the Free Software Foundation, version 2.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
##
## Copyright 2016-2017 by Claus Hunsen <[email protected]>
## Copyright 2017 by Raphael Nömmer <[email protected]>
## Copyright 2017 by Christian Hechtl <[email protected]>
## Copyright 2019 by Thomas Bock <[email protected]>
## Copyright 2021 by Niklas Schneider <[email protected]>
## All Rights Reserved.
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Libraries ---------------------------------------------------------------
requireNamespace("parallel") # for parallel computation
requireNamespace("igraph") # networks
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Multi networks ----------------------------------------------------------
#' Collect the multi networks of the different Codeface ranges.
#'
#' @param project.conf the project configuration
#' @param network.conf the network configuration
#' @param step the step size of which ranges get processed (i.e., 2 means every second range)
#' [default: 1]
#'
#' @return the multi networks
collect.multi.networks = function(project.conf, network.conf, step = 1) {
## we need to iterate over all ranges
ranges = project.conf$get.value("ranges")
## subset according to given step size
ranges = ranges[seq(1, length(ranges), step)]
## collect the network objects for all the ranges
networks = lapply(ranges, function(range) {
## construct range data
range.data = RangeData$new(project.conf, range, built.from.range.data.read = TRUE)
## construct network builder
network.builder <- NetworkBuilder$new(range.data, network.conf)
## get the multi network
multi.network = network.builder$get.multi.network()
## set range attribute
multi.network = igraph::set.graph.attribute(multi.network, "range", range)
attr(multi.network, "range") = range
# add to global list
return(multi.network)
})
## set names of list to range values
names(networks) = ranges
return(networks)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Bipartite networks ------------------------------------------------------
#' Collect the bipartite networks of the different Codeface ranges.
#'
#' @param project.conf the project configuration
#' @param network.conf the network configuration
#' @param step the step size of which ranges get processed (i.e., 2 means every second range)
#' [default: 1]
#'
#' @return the bipartite networks
collect.bipartite.networks = function(project.conf, network.conf, step = 1) {
## we need to iterate over all ranges
ranges = project.conf$get.value("ranges")
## subset according to given step size
ranges = ranges[seq(1, length(ranges), step)]
## collect the network objects for all the ranges
networks = lapply(ranges, function(range) {
## construct range data
range.data = RangeData$new(project.conf, range, built.from.range.data.read = TRUE)
## construct network builder
network.builder <- NetworkBuilder$new(range.data, network.conf)
## get the bipartite network
bp.network = network.builder$get.bipartite.network()
## set range attribute
bp.network = igraph::set.graph.attribute(bp.network, "range", range)
attr(bp.network, "range") = range
# add to global list
return(bp.network)
})
## set names of list to range values
names(networks) = ranges
return(networks)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Author networks ---------------------------------------------------------
#' Collect the author networks of the different Codeface ranges.
#'
#' @param project.conf the project configuration
#' @param network.conf the network configuration
#' @param step the step size of which ranges get processed (i.e., 2 means every second range)
#' [default: 1]
#'
#' @return the author networks
collect.author.networks = function(project.conf, network.conf, step = 1) {
## we need to iterate over all ranges
ranges = project.conf$get.value("ranges")
## subset according to given step size
ranges = ranges[seq(1, length(ranges), step)]
## collect the network objects for all the ranges
networks = lapply(ranges, function(range) {
## construct range data
range.data = RangeData$new(project.conf, range, built.from.range.data.read = TRUE)
## construct network builder
network.builder <- NetworkBuilder$new(range.data, network.conf)
## get the author network
author.network = network.builder$get.author.network()
## set range attribute
author.network = igraph::set.graph.attribute(author.network, "range", range)
attr(author.network, "range") = range
# add to global list
return(author.network)
})
## set names of list to range values
names(networks) = ranges
return(networks)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Artifact networks -------------------------------------------------------
#' Collect the artifact networks of the different Codeface ranges.
#'
#' @param project.conf the project configuration
#' @param network.conf the network configuration
#' @param step the step size of which ranges get processed (i.e., 2 means every second range)
#' [default: 1]
#'
#' @return the artifact networks
collect.artifact.networks = function(project.conf, network.conf, step = 1) {
## we need to iterate over all ranges
ranges = project.conf$get.value("ranges")
## subset according to given step size
ranges = ranges[seq(1, length(ranges), step)]
## collect the network objects for all the ranges
networks = lapply(ranges, function(range) {
## construct range data
range.data = RangeData$new(project.conf, range, built.from.range.data.read = TRUE)
## construct network builder
network.builder <- NetworkBuilder$new(range.data, network.conf)
## get the artifact network
artifact.network = network.builder$get.artifact.network()
## set range attribute
artifact.network = igraph::set.graph.attribute(artifact.network, "range", range)
attr(artifact.network, "range") = range
# add to global list
return(artifact.network)
})
## set names of list to range values
names(networks) = ranges
return(networks)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Construct data ----------------------------------------------------------
#' Construct the range data for the Codeface ranges.
#'
#' @param project.conf the project configuration
#' @param callgraphs whether or not callgraph data is existing [default: FALSE]
#' @param step the step size of which ranges get processed (i.e., 2 means every second range)
#' [default: 1]
#'
#' @return the constructed data
construct.data = function(project.conf, callgraphs = FALSE, step = 1) {
## we need to iterate over all ranges
ranges = project.conf$get.value("ranges")
## subset according to given step size
ranges = ranges[seq(1, length(ranges), step)]
## collect the network objects for all the ranges
data = lapply(ranges, function(range) {
revision.callgraph = ifelse(callgraphs,
project.conf$get.callgraph.revision.from.range(range),
"")
## construct range data
range.data = RangeData$new(project.conf, range, revision.callgraph, built.from.range.data.read = TRUE)
attr(range.data, "range") = range
# add to global list
return(range.data)
})
## set names of list to range values
names(data) = ranges
return(data)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Run function on list of RangeData ---------------------------------------
#' Run a given function on the list of RangeData.
#'
#' @param data the given list of RangeData
#' @param fun the function to be run
#'
#' @return the result of the function
run.lapply = function(data, fun) {
res = parallel::mclapply(data, function(dat) dat[[fun]]())
return(res)
}