forked from se-sic/coronet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util-conf.R
1035 lines (900 loc) · 41 KB
/
util-conf.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 2016-2019 by Claus Hunsen <[email protected]>
## Copyright 2016 by Wolfgang Mauerer <[email protected]>
## Copyright 2017 by Raphael Nömmer <[email protected]>
## Copyright 2017-2018 by Christian Hechtl <[email protected]>
## Copyright 2020-2021 by Christian Hechtl <[email protected]>
## Copyright 2017 by Felix Prasse <[email protected]>
## Copyright 2017-2019 by Thomas Bock <[email protected]>
## Copyright 2021, 2023 by Thomas Bock <[email protected]>
## Copyright 2018 by Barbara Eckl <[email protected]>
## Copyright 2018-2019 by Jakob Kronawitter <[email protected]>
## Copyright 2019 by Anselm Fehnker <[email protected]>
## Copyright 2020-2021 by Niklas Schneider <[email protected]>
## Copyright 2021 by Johannes Hostert <[email protected]>
## Copyright 2021 by Mirabdulla Yusifli <[email protected]>
## Copyright 2022 by Jonathan Baumann <[email protected]>
## All Rights Reserved.
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Libraries ---------------------------------------------------------------
requireNamespace("R6") # for R6 classes
requireNamespace("yaml") # for Codeface configuration files
requireNamespace("logging")
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Constants ---------------------------------------------------------------
## mapping of tagging to artifact
ARTIFACT.TO.TAGGING = list(
"feature" = "feature",
"featureexpression" = "feature",
"function" = "proximity",
"file" = "proximity"
)
ARTIFACT.TO.ABBREVIATION = list(
"feature" = "f",
"featureexpression" = "fe",
"function" = "func",
"file" = "cu"
)
ARTIFACT.CODEFACE = list(
"feature" = "Feature",
"featureexpression" = "FeatureExpression",
"function" = "Function",
"file" = "File"
)
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Conf --------------------------------------------------------------------
#' The class \code{Conf} provides convenient handling of a predefined set of
#' configuration options or, rather, attributes.
#'
#' **Note:** This class is considered abstract and should not instantiated directly,
#' as the list of handled attributes is empty.
Conf = R6::R6Class("Conf",
## * private -----------------------------------------------------------
private = list(
## * * attributes --------------------------------------------------
attributes = list(),
## * * value checking ----------------------------------------------
#' Check all attributes for their consistency.
#'
#' @return a logical indicating if the checks have been successful
check.values = function() {
current.values = lapply(names(private$attributes), function(att) {
return(self$get.value(att))
})
names(current.values) = names(private$attributes)
self$update.values(current.values)
},
#' Check whether the given 'value' is the correct datatype
#' for the attribute 'name'.
#'
#' @param value the new value for the attribute
#' @param name the name of the attribute
#'
#' @return a named vector of logical values, named:
#' - existing,
#' - value.not.empty,
#' - type,
#' - allowed,
#' - allowed.number, and
#' - updatable.
#' Does not need to contain all of the above; e.g. if \code{existing} is \code{FALSE} the result
#' consists of only this value.
check.value = function(value, name) {
if (!exists(name, where = private[["attributes"]])) {
result = c(existing = FALSE)
} else if (length(value) < 1){
result = c(existing = TRUE, value.not.empty = FALSE)
} else {
## check all other properties
attribute = private[["attributes"]][[name]]
## if non-updatable field, return early
if (!is.null(attribute[["updatable"]]) && !attribute[["updatable"]]) {
result = c(existing = TRUE, value.not.empty = TRUE, updatable = FALSE)
} else {
result = c(
existing = TRUE,
value.not.empty = TRUE,
updatable = TRUE,
type = class(value) %in% attribute[["type"]],
## if 'allowed' is not defined for this attribute, any
## value of the correct type should be accepted.
allowed = is.null(attribute[["allowed"]]) ||
if (attribute[["type"]] == "numeric" && length(attribute[["allowed"]]) == 1) {
value <= attribute[["allowed"]]
} else {
all(value %in% attribute[["allowed"]])
},
allowed.number = length(value) <= attribute[["allowed.number"]]
)
}
}
return(result)
}
),
## * public ------------------------------------------------------------
public = list(
#' The constructor, automatically checking the default values.
initialize = function() {
# ## check the default values for validity
# private$check.values()
},
## * * printing ----------------------------------------------------
#' Get configuration list as string.
#'
#' @param allowed Indicator whether to return also information on allowed values
#'
#' @return the configuration list as string [default: FALSE]
get.conf.as.string = function(allowed = FALSE) {
## get the complete list of attributes
attributes = private$attributes
## remove information on allowed values if not wanted
if (!allowed) {
attributes = lapply(attributes, function(att) {
att[["allowed"]] = NULL
att[["allowed.number"]] = NULL
att[["type"]] = NULL
return(att)
})
}
return(get.configuration.string(attributes, title = NULL))
},
#' Print the private variables of the class.
#'
#' @param allowed Indicator whether to print information on allowed values [default: FALSE]
print = function(allowed = FALSE) {
logging::loginfo("Configuration:\n%s", self$get.conf.as.string(allowed))
},
## * * updating ----------------------------------------------------
#' Update the attributes of the class with the new value for the given entry.
#'
#' @param entry the entry name for the value
#' @param value the new value
update.value = function(entry, value) {
## construct list for updating
updating = list(value)
names(updating) = entry
## update value
self$update.values(updating)
},
#' Update the attributes of the class with the new values given in the
#' 'updated.values' list.
#'
#' @param updated.values the new values for the attributes to be updated [default: list()]
update.values = function(updated.values = list()) {
## determine the function executed on an error
error.function = stop
## check values to update
names.to.update = c()
for (name in names(updated.values)) {
## get value to update
value = updated.values[[name]]
## check the value
check = private$check.value(value = value, name = name)
## if all checks are passed
if (all(check)) {
names.to.update = c(names.to.update, name)
}
## if some check failed
else {
## get current environment for logging
attribute = private[["attributes"]][[name]]
if (!check[["existing"]]) {
message = paste(
"Updating configuration attribute '%s' failed:",
"A configuraton attribute with this name does not exist."
)
error.function(sprintf(message, name))
} else if (!check[["value.not.empty"]]) {
message = paste(
"Updating configuration attribute '%s' failed:",
"The provided value is empty!"
)
error.function(sprintf(message, name))
} else if (!check[["updatable"]]) {
message = paste(
"Updating configuration attribute '%s' failed:",
"The value is not updatable!"
)
error.function(message, name)
} else {
message = paste0(
"Updating configuration attribute '%s' failed.\n",
"Allowed values (%s of type '%s'): %s\n",
"Given value (of type '%s'): %s"
)
error.function(sprintf(
message,
name,
# paste(self$get.value(name), collapse = ", "),
attribute[["allowed.number"]],
attribute[["type"]],
if (attribute[["type"]] == "numeric" && length(attribute[["allowed"]]) == 1) {
paste("<=", attribute[["allowed"]])
} else {
paste(attribute[["allowed"]], collapse = ", ")
},
class(value),
paste(value, collapse = ", ")
))
}
}
}
## Updating values if needed
if (length(names.to.update) > 0) {
logging::loginfo(
"Updating following configuration parameters: %s",
paste(names.to.update, collapse = ", ")
)
for (name in names.to.update) {
default.value = private[["attributes"]][[name]][["default"]]
new.value = updated.values[[name]]
## check if the default value or the given new value are NA
## if only one of both is NA that means that the value has to be changed
if (is.single.na(default.value) && !is.single.na(new.value) ||
!is.single.na(default.value) && is.single.na(new.value)) {
private[["attributes"]][[name]][["value"]] = new.value
} ## if the default value and the given value are the same and if the 'value' field is present
## then reset the 'value' field
else if (is.single.na(default.value) && is.single.na(new.value) ||
identical(sort(new.value), sort(default.value))) {
if ("value" %in% names(private[["attributes"]][[name]])) {
private[["attributes"]][[name]][["value"]] = NULL
}
} ## otherwise proceed with updating the value
else {
private[["attributes"]][[name]][["value"]] = sort(new.value)
}
}
} else {
logging::logwarn(
"Not updating any configuration parameters!"
)
}
## return invisible
invisible()
},
## * * value retrieval ---------------------------------------------
#' Get the value whose name is given by 'name'.
#'
#' @param name the name of the value to be returned
#'
#' @return the value
get.value = function(name) {
value = private[["attributes"]][[name]][["value"]]
## if there is no value set, retrieve the default
if (is.null(value)) {
value = self$get.value.default(name)
}
return(value)
},
#' Get the value whose name is given by 'name'.
#'
#' @param name the name of the value to be returned
#'
#' @return the value
get.entry = function(name) {
return(self$get.value(name))
},
#' Get the value whose name is given by 'name'.
#'
#' @param name the name of the value to be returned
#'
#' @return the value
get.variable = function(name) {
return(self$get.value(name))
},
#' Get the default value for the entry whose name is given by 'var.name'.
#'
#' @param name the name of the entry to be returned
#'
#' @return the default entry value
get.value.default = function(name) {
value = private[["attributes"]][[name]][["default"]]
return(value)
}
)
)
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## ProjectConf -------------------------------------------------------------
#' The class \code{ProjectConf} is a subclass of \code{Conf} and provides
#' convenient handling of project-related configuration attributes with the
#' class \code{ProjectData}.
#'
#' @seealso Conf
#' @seealso ProjectData
#' @seealso RangeData
ProjectConf = R6::R6Class("ProjectConf", inherit = Conf,
## * private -----------------------------------------------------------
private = list(
## * * project info ------------------------------------------------
data = NULL, # character
selection.process = NULL, # character
casestudy = NULL, # character
artifact = NULL, # character
## * * attributes ---------------------------------------------------
attributes = list(
commits.filter.base.artifact = list(
default = TRUE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
commits.filter.untracked.files = list(
default = TRUE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
commits.locked = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
commit.messages = list(
default = "none",
type = "character",
allowed = c("none", "title", "message"),
allowed.number = 1
),
issues.only.comments = list(
default = TRUE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
filter.bots = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
issues.from.source = list(
default = c("jira", "github"),
type = "character",
allowed = c("jira", "github"),
allowed.number = Inf
),
issues.locked = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
mails.filter.patchstack.mails = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
mails.locked = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
gender = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
synchronicity = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
synchronicity.time.window = list(
default = 5,
type = "numeric",
allowed = c(1, 5, 10, 15),
allowed.number = 1
),
pasta = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
custom.event.timestamps.file = list(
default = NA,
type = "character",
allowed.number = 1
),
custom.event.timestamps.locked = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
)
),
## * * revisions and ranges ----------------------------------------
#' Change the revision names to a equal name standard.
#'
#' @param ranges the list of ranges to be postprocessed
#'
#' @return the postprocessed ranges
postprocess.revision.list = function(ranges) {
# remove names, e.g. "version", from release cycle names
casestudy = private$casestudy
to.remove = c(
"version-", "v-", "version_", "v_", "version", "v",
paste0(casestudy, "-"), paste0(casestudy, "-"),
paste0(casestudy, "_"), paste0(casestudy, "_"),
casestudy, casestudy
)
# run gsub for all pattern
ranges = tolower(ranges)
for (string in to.remove) {
ranges = gsub(string, "", ranges)
}
# return simplified list of ranges
return(ranges)
},
#' Change the revision names of callgraph data to a equal name standard.
#'
#' @param r list of revisions to be postprocessed
#'
#' @return list of postprocessed revisions
postprocess.revision.list.for.callgraph.data = function(r) {
r = gsub("version-", "", r) # remove version prefix (SQLite)
r = gsub("OpenSSL_", "", r) # remove name prefix (OpenSSL)
r = gsub("\\.", "_", r) # replace dots by underscores
return(r)
},
## * * path construction -------------------------------------------
subfolder.configurations = "configurations",
subfolder.results = "results",
#' Construct and return the path to the configuration folder of Codeface.
#'
#' @param data the path to the codeface-data folder
#' @param selection.process the selection process of the current study ('threemonth', 'releases')
#'
#' @return the path to the configuration folder
get.configurations.folder = function(data, selection.process) {
return(file.path(data, private$subfolder.configurations, selection.process))
},
#' Construct and return the path to a Codeface configuration.
#'
#' @param data the path to the codeface-data folder
#' @param selection.process the selection process of the current study ('threemonth', 'releases')
#' @param casestudy the current casestudy
#' @param tagging the current tagging ('feature', 'proximity')
#'
#' @return the path to the configuration
construct.conf.path = function(data, selection.process, casestudy, tagging) {
## construct the base name of the configuration
conf.basename = paste(casestudy, "_", tagging, ".conf", sep = "")
## construct complete path
conf.file = file.path(private$get.configurations.folder(data, selection.process), conf.basename)
## return path to config file
return(conf.file)
},
#' Construct and return the path to the results folder of Codeface.
#'
#' @param data the path to the codeface-data folder
#' @param selection.process the selection process of the current study ('threemonth', 'releases')
#' @param casestudy the current casestudy
#' @param suffix the suffix of the casestudy's results folder
#' @param subfolder an optional subfolder [default: NULL]
#'
#' @return the path to the results folder
#' (i.e., "{data}/{selection.process}/{casestudy}_{suffix}[/{subfolder}]")
get.results.folder = function(data, selection.process, casestudy, suffix, subfolder = NULL) {
path = file.path(data, private$subfolder.results, selection.process, paste(casestudy, suffix, sep = "_"))
if (!is.null(subfolder)) {
path = file.path(path, subfolder)
}
return(path)
}
),
## * public ------------------------------------------------------------
public = list(
#' Constructor of the class.
#'
#' @param data the path to the codeface-data folder
#' @param selection.process the selection process of the current study ('threemonth', 'releases')
#' @param casestudy the current casestudy
#' @param artifact the artifact to study (one of \code{feature}, \code{function}, \code{file},
#' and \code{featureexpression}) [default: "feature"]
initialize = function(data, selection.process, casestudy, artifact = c("feature", "file",
"function", "featureexpression")) {
logging::loginfo("Construct project configuration: starting.")
## call super constructor
super$initialize()
## verify arguments using match.arg
artifact = match.arg(artifact)
## verify arguments
private$data = verify.argument.for.parameter(data, "character", "ProjectConf$new")
private$selection.process = verify.argument.for.parameter(selection.process, "character", "ProjectConf$new")
private$casestudy = verify.argument.for.parameter(casestudy, "character", "ProjectConf$new")
private$artifact = verify.argument.for.parameter(artifact, "character", "ProjectConf$new")
## convert artifact to tagging
tagging = ARTIFACT.TO.TAGGING[[ artifact ]]
if (is.null(tagging)) {
logging::logerror("Artifact '%s' cannot be converted to a proper Codeface tagging! Stopping...", artifact)
stop("Stopped due to wrong configuration parameters!")
}
## construct file name for configuration
conf.file = private$construct.conf.path(data, selection.process, casestudy, tagging)
## load case-study configuration from given file
logging::loginfo("Attempting to load configuration file: %s", conf.file)
conf = yaml::yaml.load_file(conf.file)
## store basic information
conf$selection.process = selection.process
conf$casestudy = casestudy
## store artifact in configuration
conf$artifact = artifact
conf$artifact.short = ARTIFACT.TO.ABBREVIATION[[ conf$artifact ]]
conf$artifact.codeface = ARTIFACT.CODEFACE[[ conf$artifact ]]
## store path to actual Codeface data
conf$datapath = private$get.results.folder(data, selection.process, casestudy, tagging, subfolder = tagging)
## store path to call graphs
conf$datapath.callgraph = private$get.results.folder(data, selection.process, casestudy, "callgraphs")
## store path to synchronicity data
conf$datapath.synchronicity = private$get.results.folder(data, selection.process, casestudy, "synchronicity")
## store path to PaStA data
conf$datapath.pasta = private$get.results.folder(data, selection.process, casestudy, "pasta")
## store path to gender data
conf$datapath.gender = private$get.results.folder(data, selection.process, casestudy, "gender")
## store path to issue data
conf$datapath.issues = private$get.results.folder(data, selection.process, casestudy, tagging, subfolder = tagging)
## READ REVISIONS META-DATA
## read revisions file
revisions.file = file.path(conf$datapath, "revisions.list")
revisions.df = try(read.table(revisions.file, header = FALSE, sep = ";", strip.white = TRUE,
encoding = "UTF-8"), silent = TRUE)
## break if the list of revisions is empty or any other error occurs
if (inherits(revisions.df, "try-error")) {
logging::logerror("There are no revisions available for the current casestudy.")
logging::logerror("Attempted to load following file: %s", revisions.file)
stop("Stopped due to missing revisions.")
}
## convert columns accordingly
revisions.cols = c(revision = "as.character", date = "get.date.from.string")
for (i in 1:ncol(revisions.df)) {
revisions.df[i] = do.call(base::c, lapply(revisions.df[[i]], revisions.cols[i]))
colnames(revisions.df)[i] = names(revisions.cols)[i]
}
revisions = revisions.df[["revision"]]
revisions.dates = revisions.df[["date"]]
if (!is.null(revisions.dates)) names(revisions.dates) = revisions
conf[["revisions"]] = NULL
## change structure of values (i.e., insert 'default' sublists)
conf = lapply(conf, function(entry) {
return(list(value = entry, updatable = FALSE))
})
## SAVE FULL CONFIGURATION OBJECT
private$attributes = c(conf, private$attributes)
## construct and save revisions and ranges
## (this has to be done after storing conf due to the needed access to the conf object)
self$set.revisions(revisions, revisions.dates)
# ## logging
# self$print(allowed = TRUE)
logging::loginfo("Construct project configuration: finished.")
},
## * * helper methods ----------------------------------------------
#' Get the corresponding callgraph revision for the given range.
#'
#' @param range the range for the callgraph revisions
#'
#' @return the callgraph revisions
get.callgraph.revision.from.range = function(range) {
idx = which(self$get.value("ranges") == range)
rev = self$get.value("revisions.callgraph")[idx + 1]
return(rev)
},
## * * updating revisions and splitting information ----------------
#' Set the revisions and ranges for the study.
#'
#' @param revisions the revisions of the study
#' @param revisions.dates the revision dates of the study
#' @param sliding.window whether sliding window splitting is enabled or not [default: FALSE]
set.revisions = function(revisions, revisions.dates, sliding.window = FALSE) {
## construct revisions for call-graph data
revisions.callgraph = private$postprocess.revision.list.for.callgraph.data(revisions)
## construct ranges
ranges = construct.ranges(revisions, sliding.window = sliding.window)
## assemble revision data
rev.data = list(
revisions = revisions,
revisions.dates = revisions.dates,
revisions.callgraph = revisions.callgraph,
ranges = ranges,
ranges.paths = generate.range.directory.names(ranges),
ranges.callgraph = construct.ranges(revisions.callgraph, sliding.window = sliding.window)
)
## change structure of values (i.e., insert 'default' sublists and set 'updatable' value)
rev.data = lapply(rev.data, function(entry) {
return(list(value = entry, updatable = FALSE))
})
## insert new values (update if needed)
for (name in names(rev.data)) {
private[["attributes"]][[name]] = rev.data[[name]]
}
},
#' Update the information on revisions and ranges regarding splitting.
#'
#' @param type either "time-based" or "activity-based", depending on splitting function
#' @param length the string given to time-based splitting (e.g., "3 months") or the activity
#' amount given to acitivity-based splitting
#' @param basis the data used as basis for splitting (either "commits", "mails", or "issues")
#' @param sliding.window whether sliding window splitting is enabled or not
#' @param revisions the revisions of the study
#' @param revisions.dates the revision dates of the study
set.splitting.info = function(type, length, basis, sliding.window, revisions, revisions.dates) {
## assemble splitting information
split.info = list(
## basic slpitting information
split.type = type,
split.length = length,
split.basis = basis,
split.sliding.window = sliding.window,
## splitting information on ranges
split.revisions = revisions,
split.revisions.dates = revisions.dates,
split.ranges = construct.ranges(revisions, sliding.window = sliding.window)
)
## change structure of values (i.e., insert 'default' sublists and set 'updatable' value)
split.info = lapply(split.info, function(entry) {
return(list(value = entry, updatable = FALSE))
})
## insert new values (update if needed)
for (name in names(split.info)) {
private[["attributes"]][[name]] = split.info[[name]]
}
}
)
)
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## NetworkConf -------------------------------------------------------------
#' The class \code{NetworkConf} is a subclass of \code{Conf} and provides
#' convenient handling of configuration attributes related to network
#' construction with the class \code{NetworkBuilder}.
#'
#' @seealso Conf
#' @seealso NetworkBuilder
NetworkConf = R6::R6Class("NetworkConf", inherit = Conf,
## * private -----------------------------------------------------------
private = list(
## * * attributes -----------------------------------------------------
attributes = list(
author.relation = list(
default = "mail",
type = "character",
allowed = c("mail", "cochange", "issue"),
allowed.number = Inf
),
author.directed = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
author.respect.temporal.order = list(
default = NA, # default value will be determined from the 'author.directed' parameter
type = "logical",
allowed = c(TRUE, FALSE, NA),
allowed.number = 1
),
author.all.authors = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
author.only.committers = list(
## FIXME rename to something like "author.only.authors.also.in.the.data.when.artifact.relation.is.used
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
artifact.relation = list(
default = "cochange",
type = "character",
allowed = c("cochange", "callgraph", "mail", "issue"),
allowed.number = Inf
),
artifact.directed = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
edges.for.base.artifacts = list(
default = TRUE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
edge.attributes = list(
default = c(
"date", "artifact.type", # general
"message.id", "thread", # mail data
"hash", "file", "artifact", # commit data
"issue.id", "event.name" # issue data
),
type = "character",
allowed = c(
# the date
"date", "date.offset",
# the artifact type indicating the edge
"artifact.type",
# author information
"author.name", "author.email",
# committer information
"committer.date", "committer.name", "committer.email",
# e-mail information
"message.id", "thread", "subject",
## commit information
"hash", "file", "artifact", "changed.files", "added.lines",
"deleted.lines", "diff.size", "artifact.diff.size", "synchronicity",
# PaStA information
"pasta",
# issue information
"issue.id", "issue.state", "creation.date", "closing.date", "is.pull.request",
"author.name", "author.mail", "event.date", "event.name"
),
allowed.number = Inf
),
simplify = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
),
skip.threshold = list(
default = Inf,
type = "numeric",
allowed = Inf,
allowed.number = 1
),
unify.date.ranges = list(
default = FALSE,
type = "logical",
allowed = c(TRUE, FALSE),
allowed.number = 1
)
)
),
## * public ------------------------------------------------------------
public = list(
#' The constructor, automatically checking the default values.
initialize = function() {
logging::loginfo("Construct network configuration: starting.")
## call super constructor
super$initialize()
logging::loginfo("Construct network configuration: finished.")
},
#' Update the attributes of the class with the new values given in the
#' 'updated.values' list.
#'
#' @param updated.values the new values for the attributes to be updated [default: list()]
update.values = function(updated.values = list()) {
super$update.values(updated.values = updated.values)
## 1) "date" and "artifact.type" always as edge attribute
name = "edge.attributes"
private[["attributes"]][[name]][["value"]] = unique(c(
"date",
"artifact.type",
self$get.value(name)
))
## return invisible
invisible()
},
#' Clears the edge attributes by setting the attribute to just the mandatory
#' 'date' value. This can be used to get rid of all the default values at once.
clear.edge.attributes = function() {
logging::loginfo("Clearing edge.attributes.")
self$update.values(list(edge.attributes = c("date")))
}
)
)
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
## Helper functions --------------------------------------------------------
#' Constructs a string representing a configuration (i.e., a potentially nested list).
#'
#' @param conf the configuration list to represent as string
#' @param title the title line right before the constructed string [default: deparse(substitute(conf))]
#'
#' @return a string representing the status of \code{conf}, including newline characters and
#' pretty-printed list style
get.configuration.string = function(conf, title = deparse(substitute(conf))) {
fill = "↳ "
front = "- "
indentation.item = " "
construct.configuration.string = function(struct, title, depth = 0) {
## construct the indentation
indentation = if (depth > 0) rep(indentation.item, depth - 1) else ""
output = c()
len = length(struct)
## add current title
if (!is.null(title)) {
if (depth > 0) output = c(output, indentation)
output = c(output, paste0(front, title))
if (mode(struct) == "list") {
updatable = struct[["updatable"]]
if (!is.null(updatable)) {
struct[["updatable"]] = NULL
if (!updatable) {
output = c(output, " [final]")
len = len - 1
}
}
output = c(output, "\n")
}
}
if (is.atomic(struct) && len > 0) {
if (len == 1) {
field = paste0(" = ", paste(struct, collapse = ", "), "\n")
} else if (len > 7) {
entries = paste0(indentation, indentation.item, indentation.item, struct)
field = paste0(
" = [\n",
paste(entries, collapse = ", \n"),
"\n",
if (depth > 0) indentation,
if (depth > 0) indentation.item,
"]\n"
)
} else {
field = paste0(" = [", paste(struct, collapse = ", "), "]\n")
}
output = c(output, field)
}
if (mode(struct) == "list" && len > 0) {
structnames = names(struct)
if (is.null(structnames)) structnames = rep("", len)
noname = structnames == ""
structnames[noname] = sprintf("[[%s]]", seq_len(len)[noname])
for (i in seq_len(len)) {
item = struct[[i]]
label = structnames[i]
entry = construct.configuration.string(
struct = item,
title = label,
depth = depth + 1
)