-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_chat_timeframes.R
208 lines (130 loc) · 5.74 KB
/
get_chat_timeframes.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
rm(list=ls())
setwd("C:/Users/conra/Documents/GitHub/ngss_words")
library(magrittr)
library(lubridate)
library(rtweet)
load("NGSSchat_sentiment_states_revised.rda")
# ind <- grep("Welcome to #NGSSchat", tweets_dl$text)
# Select 1,000 most busy hours in data set
time <- tweets_dl$created_at
time <- format(time, format="%Y-%m-%d %H")
freq <- table(time)
freq <- sort(freq, decreasing = T)
freq <- freq %>% head(1000)
hours <- names(freq)
# Select tweets at the beginning and end of these 500 hours (+- 5 minutes around edge)
hours <- sapply(hours, paste, ":00:00 UTC", sep="")
hours <- as.character(hours)
hours <- as.POSIXct(hours, tz = "UTC")
# Add minutes of +- 3 minutes to "hours"
original <- hours
for (i in seq(60, 5*60, 60)){
hours <- c(hours, original-i)
}
for (i in seq(60, 5*60, 60)){
hours <- c(hours, original+i)
}
# Standardize tweet posting times to minutes
ptimes <- tweets_dl$created_at
ptimes <- round_date(ptimes, unit="1 minute")
possible <- tweets_dl[which(ptimes %in% hours), c("created_at", "text")]
# Grab chats with "Welcome to "NGSSchat"
ind <- grep("Welcome to #NGSSchat", possible$text)
sort_out <- possible$created_at[ind]
sort_out <- format(sort_out, format="%Y-%m-%d %H")
# Get hours of "Welcome to #NGSSchat"
sort_out <- sapply(sort_out, paste, ":00:00 UTC", sep="")
sort_out <- as.character(sort_out)
sort_out <- as.POSIXct(sort_out, tz = "UTC")
# Exclude these hours from all possible, most busy 500 hours
hours2 <- names(freq)
hours2 <- sapply(hours2, paste, ":00:00 UTC", sep="")
hours2 <- as.character(hours2)
hours2 <- as.POSIXct(hours2, tz = "UTC")
hours2 <- hours2[-which(hours2 %in% sort_out)]
# Iterate again and create +- 5 minutes
hours <- hours2
original <- hours
for (i in seq(60, 5*60, 60)){
hours <- c(hours, original-i)
}
for (i in seq(60, 5*60, 60)){
hours <- c(hours, original+i)
}
# Standardize tweet posting times to minutes
ptimes <- tweets_dl$created_at
ptimes <- round_date(ptimes, unit="1 minute")
# Again, take those tweets that fit the possible chat edges
possible <- tweets_dl[which(ptimes %in% hours), c("created_at", "text")]
# Exclude already ascertained days from possible chat starting points and +-1 day
# Because there are two chats in a period of three days (done because there is
# day overlap due to timezones)
possible <- possible[-which(date(possible$created_at) %in% date(sort_out)),]
possible <- possible[-which(date(possible$created_at) %in% (date(sort_out) + 1)),]
possible <- possible[-which(date(possible$created_at) %in% (date(sort_out) - 1)),]
# 337 possible tweets for manual lookup remain
write.csv(possible, "lookup.csv") # look up manually
# Grab additional chats from lookup
ind <- grep("Welcome to the first session of #NGSSchat", possible$text)
ind <- c(ind, grep("Our #nhed guest moderator for this evening is", possible$text))
ind <- c(ind, grep("Excited to learn and connect with my #NGSSchat community-- Join us-- happening", possible$text))
sort_out2 <- possible$created_at[ind]
sort_out2 <- format(sort_out2, format="%Y-%m-%d %H")
sort_out2 <- sapply(sort_out2, paste, ":00:00 UTC", sep="")
sort_out2 <- as.character(sort_out2)
sort_out2 <- as.POSIXct(sort_out2, tz = "UTC")
sort_out <- c(sort_out, sort_out2)
sort_out <- sort(sort_out)
sort_out <- sort_out %>% unique()
hours2 <- names(freq)
hours2 <- sapply(hours2, paste, ":00:00 UTC", sep="")
hours2 <- as.character(hours2)
hours2 <- as.POSIXct(hours2, tz = "UTC")
hours2 <- hours2[-which(hours2 %in% sort_out)]
# Iterate again
hours <- hours2
original <- hours
for (i in seq(60, 5*60, 60)){
hours <- c(hours, original-i)
}
for (i in seq(60, 5*60, 60)){
hours <- c(hours, original+i)
}
# Standardize tweet posting times to minutes
ptimes <- tweets_dl$created_at
ptimes <- round_date(ptimes, unit="1 minute")
possible <- tweets_dl[which(ptimes %in% hours), c("created_at", "text")]
# Exclude already ascertained days from possible chat starting points and +-1 day
possible <- possible[-which(date(possible$created_at) %in% date(sort_out)),]
possible <- possible[-which(date(possible$created_at) %in% (date(sort_out) + 1)),]
possible <- possible[-which(date(possible$created_at) %in% (date(sort_out) - 1)),]
# 233 possible tweets for manual lookup remain -> chat_frames_annotations.txt for discussion
length(sort_out) # 167 chat hours identified
# Create Variable "isChat", strict definition of chat as a 1 hour timeframe
time <- tweets_dl$created_at
time <- format(time, format="%Y-%m-%d %H")
hours <- sapply(time, paste, ":00:00 UTC", sep="")
hours <- as.character(hours)
hours <- as.POSIXct(hours, tz = "UTC")
ind <- which(hours %in% sort_out)
isChat <- rep(0, nrow(tweets_dl))
for (i in 1:length(isChat)){
if (i %in% ind){
isChat[i] <- 1
}
}
tweets_dl$isChat <- isChat
# Setting isChat to 0 where hsNGSSchat is ongoing for possible overlap where isChat = 1
ind <- grep("#hsNGSSchat", tweets_dl[tweets_dl$isChat == 1,]$text)
tweets_dl[tweets_dl$isChat == 1,]$created_at[ind] # for overview on dates
# index 24,223: user tweeted #hsNGSSchat in a regular chat at random, no changing
tweets_dl[tweets_dl$isChat == 1,]$text[(ind[1]-20):(ind[1]+5)]
# index 25,169 to 25,400: a few mentiones of hsNGSSchat at the beginning of NGSSchat session, no changing
tweets_dl[tweets_dl$isChat == 1,]$text[25169:25200]
# index 26,271 to 26,402: yet few tweets are overlap with the end of hsNGSSchat and NGSSchat, no changing
tweets_dl[tweets_dl$isChat == 1,]$text[(26271-10):(26402+10)]
## ... taking a look at the dates of creation of the overlapping tweets, there seems to be only
## overlap at the beginning of NGSSchat sessions following right after hsNGSSchat
length(ind) # only 33 mentions of hsNGSSchat in declared NGSSchat sessions
write_as_csv(tweets_dl, "CB2020_08_22_NGSSChat_chats.csv")
save(isChat, file="isChat.rda")