original_docstring: 
          Fetches user with the steps and time in conversation.
  
          :param collection: collection to connect to
          :param month: default is current month and max is last 6 months
          :return: list of users with step and time in conversation
          
docstring: Fetches user with the steps and time in conversation.
docstring_tokens: Fetches user with the steps and time in conversation .
code: def user_with_metrics(collection: Text, month=1):
  
          """
          Fetches user with the steps and time in conversation.
  
          :param collection: collection to connect to
          :param month: default is current month and max is last 6 months
          :return: list of users with step and time in conversation
          """
          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)
              users = []
              try:
                  users = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                               {"$match": {"events.event": {"$in": ["user", "bot"]},
                                                           "events.timestamp": {"$gte": Utility.get_timestamp_previous_month(month)}}},
                                               {"$group": {"_id": "$sender_id",
                                                           "latest_event_time": {"$first": "$latest_event_time"},
                                                           "events": {"$push": "$events"},
                                                           "allevents": {"$push": "$events"}}},
                                               {"$unwind": "$events"},
                                               {"$project": {
                                                   "_id": 1,
                                                   "events": 1,
                                                   "latest_event_time": 1,
                                                   "following_events": {
                                                       "$arrayElemAt": [
                                                           "$allevents",
                                                           {"$add": [{"$indexOfArray": ["$allevents", "$events"]}, 1]}
                                                       ]
                                                   }
                                               }},
                                               {"$project": {
                                                   "latest_event_time": 1,
                                                   "user_timestamp": "$events.timestamp",
                                                   "bot_timestamp": "$following_events.timestamp",
                                                   "user_event": "$events.event",
                                                   "bot_event": "$following_events.event",
                                                   "time_diff": {
                                                       "$subtract": ["$following_events.timestamp", "$events.timestamp"]
                                                   }
                                               }},
                                               {"$match": {"user_event": "user", "bot_event": "bot"}},
                                               {"$group": {"_id": "$_id",
                                                           "latest_event_time": {"$first": "$latest_event_time"},
                                                           "steps": {"$sum": 1}, "time": {"$sum": "$time_diff"}}},
                                               {"$project": {
                                                   "sender_id": "$_id",
                                                   "_id": 0,
                                                   "steps": 1,
                                                   "time": 1,
                                                   "latest_event_time": 1,
                                               }},
                                               {"$sort": {"latest_event_time": -1}}
                                               ], allowDiskUse=True))
              except Exception as e:
                  logger.error(e)
                  message = '\n'.join([message, str(e)])
              return users, message
code_tokens: def user_with_metrics ( collection : Text , month = 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 ) users = [ ] try : users = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.event" : { "$in" : [ "user" , "bot" ] } , "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$group" : { "_id" : "$sender_id" , "latest_event_time" : { "$first" : "$latest_event_time" } , "events" : { "$push" : "$events" } , "allevents" : { "$push" : "$events" } } } , { "$unwind" : "$events" } , { "$project" : { "_id" : 1 , "events" : 1 , "latest_event_time" : 1 , "following_events" : { "$arrayElemAt" : [ "$allevents" , { "$add" : [ { "$indexOfArray" : [ "$allevents" , "$events" ] } , 1 ] } ] } } } , { "$project" : { "latest_event_time" : 1 , "user_timestamp" : "$events.timestamp" , "bot_timestamp" : "$following_events.timestamp" , "user_event" : "$events.event" , "bot_event" : "$following_events.event" , "time_diff" : { "$subtract" : [ "$following_events.timestamp" , "$events.timestamp" ] } } } , { "$match" : { "user_event" : "user" , "bot_event" : "bot" } } , { "$group" : { "_id" : "$_id" , "latest_event_time" : { "$first" : "$latest_event_time" } , "steps" : { "$sum" : 1 } , "time" : { "$sum" : "$time_diff" } } } , { "$project" : { "sender_id" : "$_id" , "_id" : 0 , "steps" : 1 , "time" : 1 , "latest_event_time" : 1 , } } , { "$sort" : { "latest_event_time" : - 1 } } ] , allowDiskUse = True ) ) except Exception as e : logger . error ( e ) message = '\n' . join ( [ message , str ( e ) ] ) return users , message
short_docstring: Fetches user with the steps and time in conversation.
short_docstring_tokens: Fetches user with the steps and time in conversation .
comment: """
          Fetches user with the steps and time in conversation.
  
          :param collection: collection to connect to
          :param month: default is current month and max is last 6 months
          :return: list of users with step and time in conversation
          """