From ec1bbfe128a9ceed37412c04ae1c7b626cddc31a Mon Sep 17 00:00:00 2001 From: Natnael Kibru Date: Mon, 27 Nov 2023 21:21:45 +0300 Subject: [PATCH] final commit --- src/loader.py | 6 +++++- src/utils.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/loader.py b/src/loader.py index c75b68d..55d8b81 100644 --- a/src/loader.py +++ b/src/loader.py @@ -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): ''' diff --git a/src/utils.py b/src/utils.py index 45dda22..0b9ccc1 100644 --- a/src/utils.py +++ b/src/utils.py @@ -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 \ No newline at end of file