Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ def get_channel_messages(self, channel_name):
write a function to get all the messages from a channel

'''

with open(os.path.join(self.path, "message.json"), 'r') as f:
messages = json.load(f)

return messages[channel_name]

#
def get_user_map(self):
'''
Expand Down
40 changes: 40 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,43 @@ def convert_2_timestamp(column, data):
timestamp_.append(a.strftime('%Y-%m-%d %H:%M:%S'))
return timestamp_
else: print(f"{column} not in data")

def get_tagged_users(df):
"""get all @ in the messages"""

return df['msg_content'].map(lambda x: re.findall(r'@U\w+', x))



def map_userid_2_realname(user_profile: dict, comm_dict: dict, plot=False):
"""
map slack_id to realnames
user_profile: a dictionary that contains users info such as real_names
comm_dict: a dictionary that contains slack_id and total_message sent by that slack_id
"""
user_dict = {} # to store the id
real_name = [] # to store the real name
ac_comm_dict = {} # to store the mapping
count = 0
# collect all the real names
for i in range(len(user_profile['profile'])):
real_name.append(dict(user_profile['profile'])[i]['real_name'])

# loop the slack ids
for i in user_profile['id']:
user_dict[i] = real_name[count]
count += 1

# to store mapping
for i in comm_dict:
if i in user_dict:
ac_comm_dict[user_dict[i]] = comm_dict[i]

ac_comm_dict = pd.DataFrame(data= zip(ac_comm_dict.keys(), ac_comm_dict.values()),
columns=['LearnerName', '# of Msg sent in Threads']).sort_values(by='# of Msg sent in Threads', ascending=False)

if plot:
ac_comm_dict.plot.bar(figsize=(15, 7.5), x='LearnerName', y='# of Msg sent in Threads')
plt.title('Student based on Message sent in thread', size=20)

return ac_comm_dict