forked from se-sic/coronet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util-core-peripheral.R
1386 lines (1198 loc) · 77.9 KB
/
util-core-peripheral.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
## 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 2017 by Mitchell Joblin <[email protected]>
## Copyright 2017 by Ferdinand Frank <[email protected]>
## Copyright 2017 by Sofie Kemper <[email protected]>
## Copyright 2017-2020 by Claus Hunsen <[email protected]>
## Copyright 2017 by Felix Prasse <[email protected]>
## Copyright 2018-2019 by Christian Hechtl <[email protected]>
## Copyright 2021 by Christian Hechtl <[email protected]>
## Copyright 2018 by Klara Schlüter <[email protected]>
## Copyright 2019 by Thomas Bock <[email protected]>
## Copyright 2019 by Jakob Kronawitter <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## All Rights Reserved.
##
## This file is derived from following Codeface script:
## https://github.com/siemens/codeface/blob/master/codeface/R/developer_classification.r
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Libraries ---------------------------------------------------------------
requireNamespace("sqldf") # for SQL-selections on data.frames
requireNamespace("igraph") # for calculation of network metrics (degree, eigen-centrality)
requireNamespace("markovchain") # for role stability analysis
requireNamespace("logging") # for logging
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Thresholds --------------------------------------------------------------
## Defines at which percentage of the work load authors will
## be classified as core
CORE.THRESHOLD = 0.8
## Defines the percentage of version development ranges in which
## an author has to be classified as core to be stated as a
## longterm core author
LONGTERM.CORE.THRESHOLD = 0.5
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Classification Type Categories ----------------------------------------
## Mapping of the classification type to its category which can either
## be 'network' or 'count' based categories
CLASSIFICATION.TYPE.TO.CATEGORY = list(
"network.degree" = "network",
"network.eigen" = "network",
"network.hierarchy" = "network",
"commit.count" = "count",
"loc.count" = "count",
"mail.count" = "count",
"mail.thread.count" = "count",
"issue.count" = "count",
"issue.comment.count" = "count",
"issue.commented.in.count" = "count",
"issue.created.count" = "count"
)
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Author-class wrappers and overviews -------------------------------------
#' Classify authors into the classes "core" and "peripheral".
#'
#' The classification algorithm works by considering a numerical value for each author that denotes their centrality
#' and can be imagined to work in the following way:
#' 1. Order the authors by their centrality value and put them into a stack in which the most central authors reside
#' on the top
#' 2. Initialize an empty set of "core" authors
#' 3. Pop the author residing at the very top of the stack and add them to the set of "core" authors
#' 4. Check if the combined centrality of the set of "core" authors is greater than or equal to \code{CORE.THRESHOLD}
#' times the total centrality value (sum over the centrality values of all authors)
#' - If so, terminate. Consider everyone in the set of "core" authors as "core" and everyone else as "peripheral".
#' - If not, go to step 3
#'
#' @param network the network containing the authors to classify (parameter is required if the parameter \code{type}
#' specifies a network-based classification metric) [default: NULL]
#' @param proj.data the \code{ProjectData} containing the authors to classify (parameter is required if the parameter
#' \code{type} specifies a count-based classification metric) [default: NULL]
#' @param type a character string declaring the classification metric. The classification metric determines which
#' numerical characteristic of authors is chosen as their centrality value.
#' The parameter currently supports the following eleven options:
#' Network-based options/metrics (parameter \code{network} has to be specified):
#' - "network.degree"
#' - "network.eigen"
#' - "network.hierarchy"
#' Count-based options/metrics (parameter \code{proj.data} has to be specified):
#' - "commit.count"
#' - "loc.count"
#' - "mail.count"
#' - "mail.thread.count"
#' - "issue.count"
#' - "issue.comment.count"
#' - "issue.commented.in.count"
#' - "issue.created.count"
#' [default: "network.degree"]
#' @param issue.type which issue type to consider for count-based metrics using issues
#' (see \code{preprocess.issue.data}). One of \code{"issues"},
#' \code{"pull.requests"} or \code{"all"}. This parameter is ignored for
#' non-issue-related classification metrics. [default: "all"]
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are data frames containing the authors' names in the
#' first column and their centrality values in the second column.
get.author.class.by.type = function(network = NULL,
proj.data = NULL,
type = c("network.degree", "network.eigen", "network.hierarchy",
"commit.count", "loc.count", "mail.count", "mail.thread.count",
"issue.count", "issue.comment.count", "issue.commented.in.count",
"issue.created.count"),
issue.type = c("all", "issues", "pull.requests"),
result.limit = NULL,
restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.by.type: starting.")
type = match.arg(type)
issue.type = match.arg(issue.type)
## Get a reasonable metric name for each classification type
metric.name = switch(type,
"network.degree" = "vertex.degree",
"network.eigen" = "eigen.centrality",
"network.hierarchy" = "hierarchy",
"commit.count" = "commit.count",
"loc.count" = "loc.count",
"mail.count" = "mail.count",
"mail.thread.count" = "mail.thread.count",
"issue.count" = "issue.count",
"issue.comment.count" = "issue.comment.count",
"issue.commented.in.count" = "issue.commented.in.count",
"issue.created.count" = "issue.created.count")
if (CLASSIFICATION.TYPE.TO.CATEGORY[[type]] == "network") {
if (is.null(network)) {
logging::logerror("For network-based classifications the parameter 'network' must not be null.")
stop("For network-based classifications the parameter 'network' must not be null.")
}
## Ensure that the parameter 'network' is of type 'igraph'
verify.argument.for.parameter(network, "igraph", "get.author.class.by.type")
if (igraph::vcount(network) == 0) {
logging::logwarn("The specified network is empty. Returning an empty classification.")
return(list("core" = create.empty.data.frame(c("author.name", metric.name), c("character", "numeric")),
"peripheral" = create.empty.data.frame(c("author.name", metric.name),
c("character", "numeric"))))
}
} else {
if (is.null(proj.data)) {
logging::logerror("For count-based classifications the parameter 'proj.data' must not be null.")
stop("For count-based classifications the parameter 'proj.data' must not be null.")
}
## Ensure that the parameter 'proj.data' is of type 'ProjectData'
verify.argument.for.parameter(proj.data, "ProjectData", "get.author.class.by.type")
}
## The centrality dataframe has two columns:
## 1. a column of author names
## 2. a column for the centrality type (which is given by the parameter 'type'),
## e.g. the vertex degree when type == network.degree or the commit count when type == commit.count
centrality.dataframe = NULL
if (type == "network.degree") {
## Get vertex degrees for all authors
vertex.degree.vec = igraph::degree(network)
## Construct centrality dataframe
centrality.dataframe = data.frame(author.name = names(vertex.degree.vec),
centrality = as.vector(vertex.degree.vec))
} else if (type == "network.eigen") {
## Get eigenvectors for all authors
## The method ignores the directed parameter if the given network is undirected
eigen.centrality.vec = tryCatch(
igraph::eigen_centrality(network, directed = TRUE),
error = function(e) {
logging::logwarn(e)
logging::logwarn("As of the error above, adjust ARPACK options 'maxiter' and 'tol'...")
adjusted.options = list(maxiter = 5000, tol = 0.1)
adjusted.computation = igraph::eigen_centrality(network, directed = TRUE,
options = adjusted.options)
logging::loginfo("eigen_centrality with adjusted ARPACK options finished successfully.")
return(adjusted.computation)
}
)
eigen.centrality.vec = eigen.centrality.vec[["vector"]]
## In case no collaboration occured, all centrality values are set to 0
if (igraph::ecount(network) == 0) {
eigen.centrality.vec[] = 0
}
## Construct centrality dataframe
centrality.dataframe = data.frame(author.name = names(eigen.centrality.vec),
centrality = as.vector(eigen.centrality.vec))
} else if (type == "network.hierarchy") {
hierarchy.base.df = metrics.hierarchy(network)
hierarchy.calculated = hierarchy.base.df[["deg"]] / hierarchy.base.df[["cc"]]
## fix all authors whose clustering coefficient is '0', since their hierarchy value
## is 'Inf'. We do not get any complications here because there are no authors with
## degree == 0 and a CC > 0 (i.e., the hierarchy value would really be 0). Authors with
## a CC == NaN (degree < 2) will stay with their hierarchy value of NaN, accordingly.
hierarchy.calculated[is.infinite(hierarchy.calculated)] = 0
## Construct centrality dataframe
centrality.dataframe = data.frame(author.name = row.names(hierarchy.base.df),
centrality = hierarchy.calculated)
} else if (type == "commit.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.commit.count(proj.data)
} else if (type == "loc.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.loc.count(proj.data)
} else if (type == "mail.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.mail.count(proj.data)
} else if (type == "mail.thread.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.mail.thread.count(proj.data)
}else if (type == "issue.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.issue.count(proj.data, issue.type)
} else if (type == "issue.comment.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.issue.comment.count(proj.data, issue.type)
} else if (type == "issue.commented.in.count") {
## Construct centrality dataframe
centrality.dataframe = get.author.issues.commented.in.count(proj.data, issue.type)
} else { # type == 'issue.created.count'
## Construct centrality dataframe
centrality.dataframe = get.author.issues.created.count(proj.data, issue.type)
}
# rename the second column of the centrality data frame to the correct name with respect to the classification type
names(centrality.dataframe)[2] = metric.name
## If the parameter 'restrict.classification.to.authors' is 'NULL', no restriction is made.
## Therefore, the restriction is defined as to include all authors (i.e., there is no restriction in the next step)
if (is.null(restrict.classification.to.authors)) {
restrict.classification.to.authors = centrality.dataframe[["author.name"]]
}
## Restrict authors as given by the parameter 'restrict.classification.to.authors' before classification
centrality.dataframe = centrality.dataframe[centrality.dataframe[["author.name"]] %in%
restrict.classification.to.authors, ]
## Retrieve classification results
classification = get.author.class(centrality.dataframe, metric.name, result.limit = result.limit,
classification.category = CLASSIFICATION.TYPE.TO.CATEGORY[[type]])
## Authors who are specified in the parameter 'restrict.classification.to.authors' but were not considered in the
## classification will be appended with a value of 'NA' to the classification as peripheral authors:
## 1) Prepare a list of author names who are specified in the parameter 'restrict.classification.to.authors' but
## are not part of the classification
remaining.authors = setdiff(restrict.classification.to.authors, centrality.dataframe[["author.name"]])
## 2) Create a dataframe for those authors, all of which getting 'NA' as centrality value
remaining.authors.df = data.frame(author.name = remaining.authors, temp = rep(NA, length(remaining.authors)))
## 3) In preparition to the coming 'rbind', adjust the column names to be the same for both dataframes
names(remaining.authors.df) = c("author.name", metric.name)
## 4) Append the newly created dataframe of authors to the classification as peripheral authors
classification[["peripheral"]] = rbind(classification[["peripheral"]], remaining.authors.df)
logging::logdebug("get.author.class.by.type: finished.")
return(classification)
}
#' Classify authors into "core" and "peripheral" independently for a list of networks or \code{ProjectData} objects.
#'
#' @param network.list a list of networks, each of which containing the authors to classify (parameter is required if
#' the parameter \code{type} specifies a network-based classification metric) [default: NULL]
#' @param range.data.list a list of \code{ProjectData} and/or \code{RangeData} objects, each of which containing the
#' authors to classify (parameter is required if the parameter \code{type} specifies a
#' count-based classification metric) [default: NULL]
#'@param type a character string declaring the classification metric. The classification metric determines which
#' numerical characteristic of authors is chosen as their centrality value.
#' The parameter currently supports the following eleven options:
#' Network-based options/metrics (parameter \code{network} has to be specified):
#' - "network.degree"
#' - "network.eigen"
#' - "network.hierarchy"
#' Count-based options/metrics (parameter \code{proj.data} has to be specified):
#' - "commit.count"
#' - "loc.count"
#' - "mail.count"
#' - "mail.thread.count"
#' - "issue.count"
#' - "issue.comment.count"
#' - "issue.commented.in.count"
#' - "issue.created.count"
#' [default: "network.degree"]
#' @param issue.type which issue type to consider for count-based metrics using issues
#' (see \code{preprocess.issue.data}). One of \code{"issues"},
#' \code{"pull.requests"} or \code{"all"}. This parameter is ignored for
#' non-issue-related classification metrics. [default: "all"]
#' @param restrict.classification.to.authors a vector of author names or a list of vectors of author names.
#' When choosing the first option (i.e., when passing a vector of author
#' names), only authors that are contained within this vector are to be
#' classified. Authors that appear in the vector but are not part of the
#' classification result (i.e., they are not present in the underlying data)
#' will be added to it afterwards (with a centrality value of \code{NA}).
#' Alternatively, a list containing vectors of author names can be passed.
#' The list must have the same length as the list of networks specified in
#' the parameter \code{network.list} or the list of \code{RangeData} objects
#' specified in the parameter \code{range.data.list}, respectively. For each
#' range, the corresponding author group in the list will then be used for
#' restriction instead of using the same group for all ranges. \code{NULL}
#' means that no restriction is made. [default: NULL]
#'
#' @return a list of classification results. Each classification result is a list containing two named list members
#' \code{core} and \code{peripheral}, each of which holding the authors classified as core or peripheral,
#' respectively. Both entries in this list (\code{core} and \code{peripheral}) are dataframes containing the
#' authors' names in the first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.overview = function(network.list = NULL, range.data.list = NULL,
type = c("network.degree", "network.eigen", "network.hierarchy",
"commit.count", "loc.count", "mail.count", "mail.thread.count",
"issue.count", "issue.comment.count", "issue.commented.in.count",
"issue.created.count"),
issue.type = c("all", "issues", "pull.requests"),
restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.overview: starting.")
type = match.arg(type)
issue.type = match.arg(issue.type)
if (CLASSIFICATION.TYPE.TO.CATEGORY[[type]] == "network") {
if (is.null(network.list)) {
logging::logerror("For network-based classifications the parameter 'network.list' must not be null.")
stop("For network-based classifications the parameter 'network.list' must not be null.")
}
data.list = network.list
} else {
if (is.null(range.data.list)) {
logging::logerror("For commit-based classifications the parameter 'range.data.list' must not be null.")
stop("For commit-based classifications the parameter 'range.data.list' must not be null.")
}
data.list = range.data.list
}
## If the parameter 'restrict.classification.to.authors' is no list but simply a vector of authors, this vector is
## replicated for each range so that each range is restricted to same group of authors
if (!is.list(restrict.classification.to.authors)) {
restrict.classification.to.authors = rep(list(restrict.classification.to.authors), length(data.list))
} else if (length(restrict.classification.to.authors) != length(data.list)) {
stop("If a list is specified in the parameter 'restrict.classification.to.authors', its length must match the
length of either the parameter 'network.list' or 'range.data.list', depending on the classification type
specified in the parameter 'type'.")
}
result = mapply(data.list, restrict.classification.to.authors, SIMPLIFY = FALSE,
FUN = function(data, restrict.classification.to.authors) {
if (CLASSIFICATION.TYPE.TO.CATEGORY[[type]] == "network") {
return(get.author.class.by.type(network = data, type = type,
restrict.classification.to.authors = restrict.classification.to.authors))
} else {
return(get.author.class.by.type(proj.data = data, type = type, issue.type = issue.type,
restrict.classification.to.authors = restrict.classification.to.authors))
}
})
logging::logdebug("get.author.class.overview: finished.")
return(result)
}
#' Get the author turnover values measured as the proportion of authors in the
#' specified range classes which were not active, i.e. do not exist,
#' in the previous range classes (saturation).
#'
#' @param author.class.overview the list of author classifications
#' @param saturation the number of ranges to look in the past [default: 1]
#'
#' @return a data.frame with information about developer turnover
get.class.turnover.overview = function(author.class.overview, saturation = 1) {
logging::logdebug("get.class.turnover.overview: starting.")
if (!is.null(names(author.class.overview))) {
versions = names(author.class.overview)
} else {
versions = seq_along(author.class.overview)
}
## Set up the data.frame for the analysis results
turnover.overview = data.frame(
versions = versions,
row.names = 1,
turnover = 0,
turnover.core = 0,
turnover.peripheral = 0,
dev.count = 0,
dev.count.core = 0,
dev.count.peripheral = 0
)
## Get all active authors for each range in the different classes (and both)
devs = sapply(author.class.overview, function(author.class) {
return(c(author.class[["core"]][["author.name"]], author.class[["peripheral"]][["author.name"]]))
})
devs.core = sapply(author.class.overview, function(author.class) {
return(author.class[["core"]][["author.name"]])
})
devs.peripheral = sapply(author.class.overview, function(author.class) {
return(author.class[["peripheral"]][["author.name"]])
})
## The author turnover measured as the proportion of devs in the current version
## range which were not active in the previous range
devs.new = devs[[1]]
devs.core.new = devs.core[[1]]
devs.peripheral.new = devs.peripheral[[1]]
turnover.overview[["dev.count"]][1] = length(devs.new)
turnover.overview[["dev.count.core"]][1] = length(devs.core.new)
turnover.overview[["dev.count.peripheral"]][1] = length(devs.peripheral.new)
for (i in 2:length(author.class.overview)) {
devs.old = devs.new
devs.core.old = devs.core.new
devs.peripheral.old = devs.peripheral.new
j = 1
while (j <= saturation) {
if ((i-j) > 0) {
devs.old = igraph::union(devs.old, devs[[i-j]])
devs.core.old = igraph::union(devs.core.old, devs.core[[i-j]])
devs.peripheral.old = igraph::union(devs.peripheral.old, devs.peripheral[[i-j]])
}
j = j + 1
}
## Find the authors which are active in the current period
devs.new = devs[[i]]
devs.core.new = devs.core[[i]]
devs.peripheral.new = devs.peripheral[[i]]
## Calculate the turnover values
turnover.overview[["turnover"]][i] = sum(!(devs.new %in% devs.old)) / length(devs.new)
turnover.overview[["turnover.core"]][i] = sum(!(devs.core.new %in% devs.core.old)) / length(devs.core.new)
turnover.overview[["turnover.peripheral"]][i] = sum(!(devs.peripheral.new %in% devs.peripheral.old)) /
length(devs.peripheral.new)
turnover.overview[["dev.count"]][i] = length(devs.new)
turnover.overview[["dev.count.core"]][i] = length(devs.core.new)
turnover.overview[["dev.count.peripheral"]][i] = length(devs.peripheral.new)
}
logging::logdebug("get.class.turnover.overview: finished.")
return(turnover.overview)
}
#' Gets a data frame to show the proportion of
#' the authors which are either only active in the current range but not in the previous ones (new) or
#' which are only active in the previous ranges (as specified in saturation) but not in the current one (gone) in
#' relation to all authors of the current and the previous ranges.
#'
#' @param author.class.overview the list of author classifications
#' @param saturation the number of ranges to look in the past [default: 1]
#'
#' @return a data.frame with information about author stability
get.unstable.authors.overview = function(author.class.overview, saturation = 1) {
logging::logdebug("get.unstable.authors.overview: starting.")
if (!is.null(names(author.class.overview))) {
versions = names(author.class.overview)
} else {
versions = seq_along(author.class.overview)
}
## Set up the data.frame for the analysis results
turnover.overview = data.frame(
versions = versions,
row.names = 1,
unstable = 0,
unstable.core = 0,
unstable.peripheral = 0
)
## Get all active authors for each range in the different classes (and both)
devs = sapply(author.class.overview, function(author.class) {
return(c(author.class[["core"]][["author.name"]], author.class[["peripheral"]][["author.name"]]))
})
devs.core = sapply(author.class.overview, function(author.class) {
return(author.class[["core"]][["author.name"]])
})
devs.peripheral = sapply(author.class.overview, function(author.class) {
return(author.class[["peripheral"]][["author.name"]])
})
devs.current = devs[[1]]
devs.core.current = devs.core[[1]]
devs.peripheral.current = devs.peripheral[[1]]
for (i in 2:length(author.class.overview)) {
devs.prev = devs.current
devs.core.prev = devs.core.current
devs.peripheral.prev = devs.peripheral.current
j = 1
while (j <= saturation) {
if ((i-j) > 0) {
devs.prev = igraph::union(devs.prev, devs[[i-j]])
devs.core.prev = igraph::union(devs.core.prev, devs.core[[i-j]])
devs.peripheral.prev = igraph::union(devs.peripheral.prev, devs.peripheral[[i-j]])
}
j = j + 1
}
## Find the authors which are active in the current period
devs.current = devs[[i]]
devs.core.current = devs.core[[i]]
devs.peripheral.current = devs.peripheral[[i]]
## Find the union of the devs which are active in the current period and in the prev periods
devs.union = igraph::union(devs.current, devs.prev)
devs.core.union = igraph::union(devs.core.current, devs.core.prev)
devs.peripheral.union = igraph::union(devs.peripheral.current, devs.peripheral.prev)
## Find the devs which are only active in the current range but not in the previous ones
devs.new = sum(!(devs.current %in% devs.prev))
devs.core.new = sum(!(devs.core.current %in% devs.core.prev))
devs.peripheral.new = sum(!(devs.peripheral.current %in% devs.peripheral.prev))
## Find the devs which are only active in the previous ranges but not in the current one
devs.gone = sum(!(devs.prev %in% devs.current))
devs.core.gone = sum(!(devs.core.prev %in% devs.core.current))
devs.peripheral.gone = sum(!(devs.peripheral.prev %in% devs.peripheral.current))
## Calculate the ratio values
turnover.overview[["unstable"]][i] = (devs.new + devs.gone) / length(devs.union)
turnover.overview[["unstable.core"]][i] = (devs.core.new + devs.core.gone) / length(devs.core.union)
turnover.overview[["unstable.peripheral"]][i] =
(devs.peripheral.new + devs.peripheral.gone) / length(devs.peripheral.union)
}
logging::logdebug("get.unstable.authors.overview: finished.")
return(turnover.overview)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Network-based classification --------------------------------------------
## * Degree-based classification -------------------------------------------
#' Classify authors into "core" and "peripheral" based on the vertex degree of author vertices in the network and
#' return the classification result.
#'
#' The details of the classification algorithm is explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param network the network containing the authors to classify
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.network.degree = function(network, result.limit = NULL, restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.network.degree: starting.")
result = get.author.class.by.type(network = network, type = "network.degree", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.network.degree: finished.")
return(result)
}
## * Eigenvector-based classification --------------------------------------
#' Classify authors into "core" and "peripheral" based on the eigenvector-centrality of author vertices in the network
#' and return the classification result.
#'
#' The details of the classification algorithm is explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param network the network containing the authors to classify
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.network.eigen = function(network, result.limit = NULL, restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.network.eigen: starting.")
result = get.author.class.by.type(network = network, type = "network.eigen", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.network.eigen: finished.")
return(result)
}
## * Hierarchy-based classification ----------------------------------------
#' Classify authors into "core" and "peripheral" based on the hierarchy value of author vertices in the network and
#' return the classification result.
#'
#' The details of the classification algorithm is explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param network the network containing the authors to classify
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.network.hierarchy = function(network, result.limit = NULL,
restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.network.hierarchy: starting.")
result = get.author.class.by.type(network = network, type = "network.hierarchy", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.network.hierarchy: finished.")
return(result)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Count-based classification ---------------------------------------------
## * Commit-based classification --------------------------------------------
#' Classify authors into "core" and "peripheral" based on authors' commit-counts and return the classification result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' commit data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.commit.count = function(proj.data, result.limit = NULL, restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.commit.count: starting.")
result = get.author.class.by.type(proj.data = proj.data, type = "commit.count", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.commit.count: finished.")
return(result)
}
## * LOC-based classification ----------------------------------------------
#' Classify authors into "core" and "peripheral" based on authors' lines of code (LOC) and return the classification
#' result. LOC are calculated independently for each author by looking at the sum of added and deleted lines of code in
#' all their commits.
#'
#' The details of the classification algorithm is explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' commit data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.loc.count = function(proj.data, result.limit = NULL, restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.loc.count: starting.")
result = get.author.class.by.type(proj.data = proj.data, type = "loc.count", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.loc.count: finished.")
return(result)
}
## * Mail-based classification --------------------------------------------
#' Classify authors into "core" and "peripheral" based on authors' mail-counts and return the classification result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' mail data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.mail.count = function(proj.data, result.limit = NULL, restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.mail.count: starting.")
result = get.author.class.by.type(proj.data = proj.data, type = "mail.count", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.mail.count: finished.")
return(result)
}
#' Classify authors into "core" and "peripheral" based on authors' mail-thread counts and return the
#' classification result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' mail data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.mail.thread.count = function(proj.data, result.limit = NULL,
restrict.classification.to.authors = NULL) {
logging::logdebug("get.author.class.mail.thread.count: starting.")
result = get.author.class.by.type(proj.data = proj.data, type = "mail.thread.count", result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.mail.thread.count: finished.")
return(result)
}
## * Issue-based classification --------------------------------------------
#' Classify authors into "core" and "peripheral" based on authors' issue-counts and return the classification result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' issue data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#' @param issue.type which issue type to consider for count-based metrics using issues
#' (see \code{preprocess.issue.data}). One of \code{"issues"},
#' \code{"pull.requests"} or \code{"all"}.
#' [default: "all"]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.issue.count = function(proj.data, result.limit = NULL, restrict.classification.to.authors = NULL,
issue.type = c("all", "issues", "pull.requests")) {
logging::logdebug("get.author.class.issue.count: starting.")
issue.type = match.arg(issue.type)
result = get.author.class.by.type(proj.data = proj.data, type = "issue.count", issue.type = issue.type,
result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.issue.count: finished.")
return(result)
}
#' Classify authors into "core" and "peripheral" based on authors' issue-comment counts and return the classification
#' result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' issue data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#' @param issue.type which issue type to consider for count-based metrics using issues
#' (see \code{preprocess.issue.data}). One of \code{"issues"},
#' \code{"pull.requests"} or \code{"all"}.
#' [default: "all"]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.issue.comment.count = function(proj.data, result.limit = NULL,
restrict.classification.to.authors = NULL,
issue.type = c("all", "issues", "pull.requests")) {
logging::logdebug("get.author.class.issue.comment.count: starting.")
issue.type = match.arg(issue.type)
result = get.author.class.by.type(proj.data = proj.data, type = "issue.comment.count", issue.type = issue.type,
result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.issue.comment.count: finished.")
return(result)
}
#' Classify authors into "core" and "peripheral" based on authors' issue-commented-in counts and return the
#' classification result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' issue data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#' @param issue.type which issue type to consider for count-based metrics using issues
#' (see \code{preprocess.issue.data}). One of \code{"issues"},
#' \code{"pull.requests"} or \code{"all"}.
#' [default: "all"]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.issue.commented.in.count = function(proj.data, result.limit = NULL,
restrict.classification.to.authors = NULL,
issue.type = c("all", "issues", "pull.requests")) {
logging::logdebug("get.author.class.issue.commented.in.count: starting.")
issue.type = match.arg(issue.type)
result = get.author.class.by.type(proj.data = proj.data, type = "issue.commented.in.count",
issue.type = issue.type,
result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.issue.commented.in.count: finished.")
return(result)
}
#' Classify authors into "core" and "peripheral" based on authors' issue-created counts and return the classification
#' result.
#'
#' The details of the classification algorithm are explained in the documentation of \code{get.author.class.by.type}.
#'
#' @param proj.data the \code{ProjectData} containing the authors' issue data
#' @param result.limit the maximum number of authors contained in the classification result. Only the top
#' \code{result.limit} authors of the classification stack will be contained within the returned
#' classification result. \code{NULL} means that all authors will be returned. [default: NULL]
#' @param restrict.classification.to.authors a vector of author names. Only authors that are contained within this
#' vector are to be classified. Authors that appear in the vector but are not
#' part of the classification result (i.e., they are not present in the
#' underlying data) will be added to it afterwards (with a centrality value
#' of \code{NA}). \code{NULL} means that no restriction is made.
#' [default: NULL]
#' @param issue.type which issue type to consider for count-based metrics using issues
#' (see \code{preprocess.issue.data}). One of \code{"issues"},
#' \code{"pull.requests"} or \code{"all"}.
#' [default: "all"]
#'
#' @return the classification result, that is, a list containing two named list members \code{core} and
#' \code{peripheral}, each of which holding the authors classified as core or peripheral, respectively. Both
#' entries in this list (\code{core} and \code{peripheral) are dataframes containing the authors' names in the
#' first column and their centrality values in the second column.
#'
#' @seealso get.author.class.by.type
get.author.class.issue.created.count = function(proj.data, result.limit = NULL,
restrict.classification.to.authors = NULL,
issue.type = c("all", "issues", "pull.requests")) {
logging::logdebug("get.author.class.issue.created.count: starting.")
issue.type = match.arg(issue.type)
result = get.author.class.by.type(proj.data = proj.data, type = "issue.created.count", issue.type = issue.type,
result.limit = result.limit,
restrict.classification.to.authors = restrict.classification.to.authors)
logging::logdebug("get.author.class.issue.created.count: finished.")
return(result)
}
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Role stability ----------------------------------------------
#' Get a data frame with the authors and their occurence count in the specified class for
#' the specified author classification list.
#'
#' @param author.class.overview the list of classifications in which to find the number
#' of occurences
#' @param class the type of class to look for. Can either be \code{"both"}, \code{"core},
#' or \code{"peripheral}. [default: "both"]
#'
#' @return a data frame with the authors and their occurence count in the specified class
get.recurring.authors = function(author.class.overview, class = c("both", "core", "peripheral")) {
logging::logdebug("get.recurring.authors: starting.")
class = match.arg(class)
authors = c()
freq = c()
## Iterate over each version development range
for (i in seq_along(author.class.overview)) {