-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLoadBeatString.R
More file actions
66 lines (55 loc) · 2.28 KB
/
LoadBeatString.R
File metadata and controls
66 lines (55 loc) · 2.28 KB
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
LoadBeatString <- function (HRVData, beatsaux, scale = 1, starttime=NULL, endtime=NULL, datetime = "1/1/1900 0:0:0", verbose = NULL) {
#-------------------------------
# Loads beats from a string
#-------------------------------
# x -> string
#-------------------------------
#HRVData = HandleVerboseArgument(HRVData, verbose)
#VerboseMessage(HRVData$Verbose,
# "Loading beats positions from string..")
if ( (!is.null(starttime) & is.null(endtime) ) | ( is.null(starttime) & !is.null(endtime) ) ) {
stop("Bad specification of starttime and endtime")
}
if (!is.null(starttime) & !is.null(endtime)) {
if ( (starttime<0) | (endtime<0) | (starttime > endtime) ) {
stop("Bad specification of starttime and endtime")
}
}
#VerboseMessage(HRVData$Verbose, paste("Scale:", scale))
beats = beatsaux[!duplicated(beatsaux)]
#if (length(beatsaux) != length(beats)) {
# VerboseMessage(HRVData$Verbose,
# paste("Removed", length(beatsaux) - length(beats),
# "duplicated beats")
# )
#}
if (!is.null(starttime)) {
lastbeattime = tail(beats,n=1)
if (endtime > lastbeattime) {
stop("Endtime exceeds record length")
}
beats <- beats[beats>=starttime & beats<=endtime]
# VerboseMessage(HRVData$Verbose, paste("Init time:", starttime))
# VerboseMessage(HRVData$Verbose, paste("End time:", endtime))
}
datetimeaux = strptime(datetime, "%d/%m/%Y %H:%M:%S")
if (is.na(datetimeaux)) {
stop("Date/time format is dd/mm/yyyy HH:MM:SS")
}
#VerboseMessage(HRVData$Verbose,
# c(paste("Date: ",
# sprintf("%02d", datetimeaux$mday), "/",
# sprintf("%02d", 1 + datetimeaux$mon), "/",
# 1900 + datetimeaux$year, "\n"),
# paste("Time: ",
# sprintf("%02d", datetimeaux$hour), ":",
# sprintf("%02d", datetimeaux$min), ":",
# sprintf("%02d", datetimeaux$sec))
# )
#)
HRVData$datetime = datetimeaux
HRVData$Beat = data.frame(Time = beats * scale)
#VerboseMessage(HRVData$Verbose,
# paste("Number of beats:", length(HRVData$Beat$Time)))
return(HRVData)
}