original_docstring: 
          Computes the user retention percentage of the bot
  
          :param collection: collection to connect to
          :param month: default is current month and max is last 6 months
          :return: user retention percentage
          
docstring: Computes the user retention percentage of the bot
docstring_tokens: Computes the user retention percentage of the bot
code: def user_retention(collection: Text, month: int = 1):
  
          """
          Computes the user retention percentage of the bot
  
          :param collection: collection to connect to
          :param month: default is current month and max is last 6 months
          :return: user retention percentage
          """
  
          client, message = HistoryProcessor.get_mongo_connection()
          message = ' '.join([message, f', collection: {collection}'])
          with client as client:
              db = client.get_database()
              conversations = db.get_collection(collection)
              total = []
              repeating_users = []
              try:
                  total = list(
                      conversations.aggregate([{"$match": {"latest_event_time": {
                          "$gte": Utility.get_timestamp_previous_month(month)}}},
                          {"$group": {"_id": None, "count": {"$sum": 1}}},
                          {"$project": {"_id": 0, "count": 1}}
                      ]))
              except Exception as e:
                  logger.error(e)
                  message = '\n'.join([message, str(e)])
  
              try:
                  repeating_users = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                               {"$match": {"events.name": {"$regex": ".*session_start*.", "$options": "$i"}}},
                                               {"$group": {"_id": '$sender_id', "count": {"$sum": 1},
                                                           "latest_event_time": {"$first": "$latest_event_time"}}},
                                               {"$match": {"count": {"$gte": 2}}},
                                               {"$match": {"latest_event_time": {
                                                   "$gte": Utility.get_timestamp_previous_month(month)}}},
                                               {"$group": {"_id": None, "count": {"$sum": 1}}},
                                               {"$project": {"_id": 0, "count": 1}}
                                               ]))
  
              except Exception as e:
                  logger.error(e)
                  message = '\n'.join([message, str(e)])
  
              if not total:
                  total_count = 1
              else:
                  total_count = total[0]['count'] if total[0]['count'] else 1
  
              if not repeating_users:
                  repeat_count = 0
              else:
                  repeat_count = repeating_users[0]['count'] if repeating_users[0]['count'] else 0
  
              return (
                  {"user_retention": 100*(repeat_count/total_count)},
                  message
              )
code_tokens: def user_retention ( collection : Text , month : int = 1 ) : client , message = HistoryProcessor . get_mongo_connection ( ) message = ' ' . join ( [ message , f', collection: {collection}' ] ) with client as client : db = client . get_database ( ) conversations = db . get_collection ( collection ) total = [ ] repeating_users = [ ] try : total = list ( conversations . aggregate ( [ { "$match" : { "latest_event_time" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$group" : { "_id" : None , "count" : { "$sum" : 1 } } } , { "$project" : { "_id" : 0 , "count" : 1 } } ] ) ) except Exception as e : logger . error ( e ) message = '\n' . join ( [ message , str ( e ) ] ) try : repeating_users = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.name" : { "$regex" : ".*session_start*." , "$options" : "$i" } } } , { "$group" : { "_id" : '$sender_id' , "count" : { "$sum" : 1 } , "latest_event_time" : { "$first" : "$latest_event_time" } } } , { "$match" : { "count" : { "$gte" : 2 } } } , { "$match" : { "latest_event_time" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$group" : { "_id" : None , "count" : { "$sum" : 1 } } } , { "$project" : { "_id" : 0 , "count" : 1 } } ] ) ) except Exception as e : logger . error ( e ) message = '\n' . join ( [ message , str ( e ) ] ) if not total : total_count = 1 else : total_count = total [ 0 ] [ 'count' ] if total [ 0 ] [ 'count' ] else 1 if not repeating_users : repeat_count = 0 else : repeat_count = repeating_users [ 0 ] [ 'count' ] if repeating_users [ 0 ] [ 'count' ] else 0 return ( { "user_retention" : 100 * ( repeat_count / total_count ) } , message )
short_docstring: Computes the user retention percentage of the bot
short_docstring_tokens: Computes the user retention percentage of the bot
comment: """
          Computes the user retention percentage of the bot
  
          :param collection: collection to connect to
          :param month: default is current month and max is last 6 months
          :return: user retention percentage
          """