From bfee0d0b8d56bbb7b6585a9aa6c6836577752059 Mon Sep 17 00:00:00 2001 From: sash713 Date: Mar 04 2020 12:53:04 +0000 Subject: Added feature to find user activities --- diff --git a/scripts/GetTicketInfo/README.md b/scripts/GetTicketInfo/README.md index ef56204..bc8b3b8 100644 --- a/scripts/GetTicketInfo/README.md +++ b/scripts/GetTicketInfo/README.md @@ -20,13 +20,15 @@ Make sure you have the following packages, if not install them with the given co After cloning run the following command in the terminal : `python3 main.py` +Change the file name of `myconfig.cfg.example` to `myconfig.cfg` and fill it with relevant details namely your FAS user ID and FAS password + You will then be asked 2 questions: - `Do you want to view the last time the newcomer has logged in (slows the program down) ?(y/n)` - type `y` for yes and `n` for no. This feature slows down the programme as it has to ping the API for every ticket + type `y` for yes and `n` for no. This feature slows down the programme as it has to ping the API for every ticket. -- `Would you like to generate a report of the newcomers ?(y/n)` - type `y` for yes and `n` for no. +- `Enter the number of days for which you would like to check new comer's activity: ` + type in the number of days to check the activity of every new comer in that given time period. ## Result: The script's output is as follows: @@ -41,6 +43,5 @@ The script's output is as follows: * Number of new comers in queue * Number of successfully joined newcomers * Number of unsuccessful joined newcomers - * User ID, Progress Check, Interests (for each ticket where newcomer has declared his/her interests) - * A list of all claimed interests and the number of newcomers per interest + * User ID, Progress Check, Interests (for each ticket where newcomer has declared his/her interests) \ No newline at end of file diff --git a/scripts/GetTicketInfo/main.py b/scripts/GetTicketInfo/main.py index edc6aef..58a263c 100644 --- a/scripts/GetTicketInfo/main.py +++ b/scripts/GetTicketInfo/main.py @@ -9,7 +9,51 @@ Author: Sashreek Shankar from fedora.client.fas2 import AccountSystem import requests from datetime import datetime +import datetime as dt import configparser +import dateutil.relativedelta +import time + + +def out_progress(current, total, backspace): + """ + function to print out the progress of any process. + """ + print('\b'*backspace, end="") + print_string = str(current)+"/"+str(total) + print(print_string, end="") + num_backspace = len(print_string) + return num_backspace + + +def getactivitycount(username, days): + """ + function to retrieve activity data from the datagrepper based on the FAS username + """ + activity_baseurl = 'https://apps.fedoraproject.org/datagrepper/raw' + days = int(days) + today = dt.date.today() + activity_lst = [] + + d = datetime.strptime(today.strftime("%Y-%m-%d %H:%M:%S"), "%Y-%m-%d %H:%M:%S") + d = d - dateutil.relativedelta.relativedelta(days=days) + start = time.mktime(datetime.strptime(str(d), "%Y-%m-%d %H:%M:%S").timetuple()) + + activity_params = {'rows_per_page': 100, 'size': 'small', 'start': start, 'user': username} + activity_results = requests.get(activity_baseurl, params=activity_params).json() + pages = activity_results['pages'] + + for i in range(0, pages): + activity_params2 = {'page': 1, 'rows_per_page': 100, 'size': 'small', 'start': start, 'user': username} + activity_results2 = requests.get(activity_baseurl, params=activity_params2).json() + + for j in range(0, len(activity_results2['raw_messages'])): + msgdate = datetime.fromtimestamp(int(activity_results2['raw_messages'][j]['timestamp'])) + topic = activity_results2['raw_messages'][j]['topic'] + activity = str(msgdate)+" "+ topic + activity_lst.append(activity) + + return activity_lst class NewComers: @@ -90,12 +134,14 @@ class NewComers: info_dictionary['last update (new-comer)'] = last_update_user prog_lst = ticket_dict['tags'] - if 'C: Progress check 1'in prog_lst: + if 'C: Progress check 1' in prog_lst: info_dictionary['progress check'] = 1 - if 'C: Progress check 2' in prog_lst: + elif 'C: Progress check 2' in prog_lst: info_dictionary['progress check'] = 2 - if 'C: Progress check 3' in prog_lst: + elif 'C: Progress check 3 - Final' in prog_lst: info_dictionary['progress check'] = 3 + else: + info_dictionary['progress check'] = None except TypeError: # In case the issue hasn't been assigned @@ -111,14 +157,16 @@ class NewComers: prog_lst = ticket_dict['tags'] if 'C: Progress check 1' in prog_lst: info_dictionary['progress check'] = 1 - if 'C: Progress check 2' in prog_lst: + elif 'C: Progress check 2' in prog_lst: info_dictionary['progress check'] = 2 - if 'C: Progress check 3' in prog_lst: + elif 'C: Progress check 3 - Final' in prog_lst: info_dictionary['progress check'] = 3 + else: + info_dictionary['progress check'] = None return info_dictionary - def gen_report(self): + def gen_report(self, days): """ The method to write data to a report file and save it in the same directory as this file""" print("Generating report ...") @@ -152,44 +200,64 @@ class NewComers: try: tag_lst = self.issues[i]['tags'] newcomer = self.issues[i]['assignee']['name'] - interest_dict[newcomer] = [[],["None"]] + interest_dict[newcomer] = [[], ["None"]] for x in tag_lst: if "I:" in x: interest = x.replace('I: ', '') interest_dict[newcomer][0].append(interest) if interest in interest_counter: interest_counter[interest] += 1 - else : + else: interest_counter[interest] = 1 if "C: Progress check" in x: interest_dict[newcomer][1] = [(x.replace('C: ', ''))] - if interest_dict[newcomer][0] == []: - del(interest_dict[newcomer]) - except TypeError: # In case the issue hasn't been assigned pass - for i in interest_dict: - user_string = i+" "*(50-(len(i)))+(interest_dict[i][1][0]) - line = user_string+" "*(75-len(user_string)) - for j in interest_dict[i][0]: - line += j+" " - f.write(line+"\n\n") + activity_dict = {} + num_backspace = 0 # variable to store number of backspeaces + progress = 1 # variable to hold the current progress of the following for loop + for i in interest_dict: + if interest_dict[i][0] != []: + num_backspace = out_progress(progress, len(interest_dict), num_backspace) # print out current progress + user_string = i+" "*(50-(len(i)))+(interest_dict[i][1][0]) + line = user_string+" "*(85-len(user_string)) + for j in interest_dict[i][0]: + line += j+" " + f.write(line+"\n\n") + activity_lst = getactivitycount(i, days) + activity_dict[i] = activity_lst + progress += 1 + else: + num_backspace = out_progress(progress, len(interest_dict), num_backspace) # print out current progress + activity_lst = getactivitycount(i, days) + activity_dict[i] = activity_lst + progress += 1 + print() + f.write("\n"*4) + f.write("\n" + "-x-" * 50 + "\n\n") + f.write("Activities of new comers : ") + for i in activity_dict: + f.write("\n" * 2) + f.write(i+" : ") + f.write("\n") + for j in activity_dict[i]: + if len(activity_dict[i]) != 0: + f.write("\t"+j+"\n") + + f.write("\n" + "-x-" * 50 + "\n\n") f.write("\n\nA summary of number of tickets by the interest tags:\n\n") - for i in interest_counter: f.write(i+" : "+str(interest_counter[i])+"\n") f.close() -newcomer = NewComers() - - def main(): + newcomer = NewComers() """ Main function """ requirement = input( "Do you want to view the last time the newcomer has logged in (slows the program down) ?(y/n) : ") @@ -197,7 +265,7 @@ def main(): requirement = True else: requirement = False - require_report = input("Would you like to generate a report of the newcomers ?(y/n) : ") + days = int(input("Enter the number of days for which you would like to check new comer's activity: ")) print("\n") for j in range(len(newcomer.issues)): ticket = newcomer.issues[j] @@ -206,9 +274,8 @@ def main(): print(i, ':', info_dict[i]) print() print("Done") - if require_report == 'y': - newcomer.gen_report() + newcomer.gen_report(days) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/scripts/GetTicketInfo/myconfig.cfg b/scripts/GetTicketInfo/myconfig.cfg deleted file mode 100644 index f4df31e..0000000 --- a/scripts/GetTicketInfo/myconfig.cfg +++ /dev/null @@ -1,4 +0,0 @@ -# add FAS credentials here -[FAS] -user: fasuser -pass: faspassword \ No newline at end of file diff --git a/scripts/GetTicketInfo/myconfig.cfg.example b/scripts/GetTicketInfo/myconfig.cfg.example new file mode 100644 index 0000000..dcada5a --- /dev/null +++ b/scripts/GetTicketInfo/myconfig.cfg.example @@ -0,0 +1,4 @@ +# add FAS credentials here +[FAS] +user: fasuser +pass: faspassword