Skip to content

Commit

Permalink
Add further checks to 'get.first.activity.data'
Browse files Browse the repository at this point in the history
Now additionally check whether the author lists are empty or 'NA'

Signed-off-by: Niklas Schneider <s8nlschn@stud.uni-saarland.de
  • Loading branch information
nlschn committed Mar 28, 2022
1 parent 5707517 commit 42a4bef
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions util-networks-covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ add.vertex.attribute.artifact.first.occurrence = function(list.of.networks, proj
#' @param default.value The default value to add if no information is available per author and activity type. [default: NA]
#'
#' @return A list containing per author a list of first activity values named with the corresponding activity type.
#' Empty list if there are no activities in \code{range.data} at all or none corresponding to the configured
#' types in \code{activity.types}
get.first.activity.data = function(range.data, activity.types = c("commits", "mails", "issues"),
default.value = NA) {

Expand Down Expand Up @@ -1021,23 +1023,37 @@ get.first.activity.data = function(range.data, activity.types = c("commits", "ma
return(minima.per.person)
})

## if activity.by.type is null, print a warning and return an empty list
if (is.null(activity.by.type)) {
logging::logwarn('There were no activities in the given RangeData')
## if activity.by.type is null or the list is empty, print a warning and return an empty list
if (is.null(activity.by.type) | length(activity.by.type) == 0) {
logging::logwarn("There were no activities in the given RangeData at all")
return(list())
}

## for each missing activity type add it with together with a copy of
## any other key but with the author lists set to NA;
## additionally, print a warning
## first, get the keys that are entirely missing or present
missing.keys = setdiff(names(activity.by.type), activity.types)
present.key = intersect(names(activity.by.type), activity.types)[[1]]
na.list = lapply(activity.by.type[present.key], function (x) NA)
present.keys = intersect(names(activity.by.type), activity.types)

## now check for the present keys whether their list is actually empty; in this case, the key is also declared
## missing
present.keys = present.keys[!is.na(activity.by.type[present.keys]) & length(activity.by.type[present.keys]) > 0]
append(missing.keys,
present.keys[is.na(activity.by.type[present.keys]) | length(activity.by.type[present.keys]) == 0])

## if there are no keys left, that are present, again, print a warning and return an empty list as there is no data
## for the configured activity types
if (length(present.keys) == 0 || is.null(present.keys)) {
logging::logwarn("There were no activities in the given RangeData that were configured")
return(list())
}

## else, take the first present item, copy its list and replace all entries with NA so that the reduce and apply
## can work it out
na.list = lapply(activity.by.type[present.keys[[1]]], function (x) NA)

for (missing.key in missing.keys) {
logging::logwarn(paste(c('The type', missing.key, 'was configured',
'but the RangeData did not cotain any',
'activities of that type'), sep = ' '))
logging::logwarn(paste(c("The type", missing.key, "was configured",
"but the RangeData did not cotain any",
"activities of that type"), sep = " "))
activity.by.type[missing.key] = na.list
}

Expand Down

0 comments on commit 42a4bef

Please sign in to comment.