# data schema actionNames <- c("dynamic_lever_pressing", "cage_exploring", "lying_down", "grooming", "laser", "freezing", "akinesia", "slow_lever_pressing", "presence_next_to_feeder", "scratching", "chewing", "yawning") # utility functions trimmedAction = trimws(action) } else { } } } } counter <- 1 counter <- counter+1 } } counter <- 1 counter <- counter+1 } } } amount <- 0 } amount } } } # business logic } amount = (as.numeric(numbers[1]) * 3600) + (as.numeric(numbers[2]) * 60) + as.numeric(numbers[3]) + (as.numeric(numbers[4]) / 100) } res[["time_in_sec"]] <- timeStrToSeconds(parts[1]) res[["action"]] <- parts[2] } startTimeInSeconds <- parsedRows[[1]][["time_in_sec"]] counter <- 1 cacheValue <- rowActionsCache[[action]] rowActionsCache[[action]] <- calculatedTime } else { previousTime <- cacheValue entry[["start_time"]] <- previousTime entry[["end_time"]] <- calculatedTime entry[["duration"]] <- (calculatedTime - previousTime) result[[counter]] <- entry counter <- counter+1 rowActionsCache[[action]] <- NULL } } } }) entry <- pair entry[["duration"]] <- (entry[["end_time"]] - entry[["start_time"]]) }) } } } } } else { } } # procedure pairsFromFile = getActionPairsFromFile(fullPath) pairsFromPeriod = getActionPairsPerDuration(pairsFromFile, period[1], period[2]) finalData[[actionName]][[filename]][[periodIndex]][["n"]] = calculateAmountPerAction(pairsFromPeriod, actionName) finalData[[actionName]][[filename]][[periodIndex]][["total"]] = calculateTotalDurationPerAction(pairsFromPeriod, actionName) finalData[[actionName]][[filename]][[periodIndex]][["average"]] = calculateAverageDurationPerAction(pairsFromPeriod, actionName) } } } csvData[["Filenames"]] <- generateVectorFromCollection(filenames) })) csvData[[header]] <- numbers } } } outputFileName = "output.csv" }