#192 Added feature to find user activities
Merged 4 years ago by hhlp. Opened 4 years ago by sash713.
fedora-join/ sash713/Fedora-Join master  into  master

@@ -20,13 +20,15 @@ 

  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 @@ 

      * 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

file modified
+92 -25
@@ -9,7 +9,51 @@ 

  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 @@ 

              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 @@ 

              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 @@ 

              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 @@ 

          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 @@ 

              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()

scripts/GetTicketInfo/myconfig.cfg.example scripts/GetTicketInfo/myconfig.cfg
file renamed
+1 -1
@@ -1,4 +1,4 @@ 

  # add FAS credentials here

  [FAS]

  user: fasuser

- pass: faspassword 

\ No newline at end of file

+ pass: faspassword

I have added a feature to the script to get the activity of all newcomers according to this issue :
https://pagure.io/fedora-join/Fedora-Join/issue/190

Pull-Request has been merged by hhlp

4 years ago