-
Notifications
You must be signed in to change notification settings - Fork 1
/
4.1 - Save Week.R
52 lines (41 loc) · 1.25 KB
/
4.1 - Save Week.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
dataFolder = "Data/Week"
mondayFolder = paste(dataFolder, "/Monday/2015-01-12-", sep="")
wednesdayFolder = paste(dataFolder, "/Wednesday/2015-01-14-", sep="")
fridayFolder = paste(dataFolder, "/Friday/2015-01-16-", sep="")
readEventsLineByLine <- function(file, eventNames) {
eventCount = 0
while(length(line <- readLines(file, n = 1, warn = FALSE)) > 0) {
json <- fromJSON(line)
if (json$type %in% eventNames) {
eventCount <- eventCount + 1
}
}
return(eventCount)
}
readDayFolder = function(folderName) {
pushes = integer()
for(n in 0:23) {
fileName = paste(folderName, n, ".json", sep="")
stream <- file(fileName, open="r")
pushesPerHour = readEventsLineByLine(stream, list("PushEvent"))
close(stream)
pushes = c(pushes, pushesPerHour)
}
return(pushes)
}
hours = 0:23
week = data.frame(hours)
#mondayPushes = readDayFolder(mondayFolder)
#wednesdayPushes = readDayFolder(wednesdayFolder)
#fridayPushes = readDayFolder(fridayFolder)
week$Monday = mondayPushes
week$Wednesday = wednesdayPushes
week$Friday = fridayPushes
week
write.csv(week, file="Data/weekData.csv")
rm(dataFolder)
rm(mondayFolder)
rm(wednesdayFolder)
rm(fridayFolder)
rm(hours)
rm(week)