original_docstring: 
          Computes the trend for engaged user count
  
          :param collection: collection to connect to
          :param month: default is 6 months
          :param conversation_limit: conversation step number to determine engaged users
          :return: dictionary of counts of engaged users for the previous months
          
docstring: Computes the trend for engaged user count
docstring_tokens: Computes the trend for engaged user count
code: def engaged_users_range(collection: Text, month: int = 6, conversation_limit: int = 10):
  
          """
          Computes the trend for engaged user count
  
          :param collection: collection to connect to
          :param month: default is 6 months
          :param conversation_limit: conversation step number to determine engaged users
          :return: dictionary of counts of engaged users for the previous months
          """
  
          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)
              engaged = []
              try:
                  engaged = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                            {"$match": {"events.event": {"$in": ["user", "bot"]},
                                                        "events.timestamp": {
                                                            "$gte": Utility.get_timestamp_previous_month(month)}}
                                             },
  
                                            {"$addFields": {"month": {
                                                "$month": {"$toDate": {"$multiply": ["$events.timestamp", 1000]}}}}},
  
                                            {"$group": {"_id": {"month": "$month", "sender_id": "$sender_id"},
                                                        "events": {"$push": "$events"},
                                                        "allevents": {"$push": "$events"}}},
                                            {"$unwind": "$events"},
                                            {"$project": {
                                                "_id": 1,
                                                "events": 1,
                                                "following_events": {
                                                    "$arrayElemAt": [
                                                        "$allevents",
                                                        {"$add": [{"$indexOfArray": ["$allevents", "$events"]}, 1]}
                                                    ]
                                                }
                                            }},
                                            {"$project": {
                                                "user_event": "$events.event",
                                                "bot_event": "$following_events.event",
                                            }},
                                            {"$match": {"user_event": "user", "bot_event": "bot"}},
                                            {"$group": {"_id": "$_id", "event": {"$sum": 1}}},
                                            {"$match": {"event": {"$gte": conversation_limit}}},
                                            {"$group": {"_id": "$_id.month", "count": {"$sum": 1}}},
                                            {"$project": {
                                                "_id": 1,
                                                "count": 1,
                                            }}
                                            ], allowDiskUse=True)
                  )
              except Exception as e:
                  logger.error(e)
                  message = '\n'.join([message, str(e)])
              engaged_users = {d['_id']: d['count'] for d in engaged}
              return (
                  {"engaged_user_range": engaged_users},
                  message
              )
code_tokens: def engaged_users_range ( collection : Text , month : int = 6 , conversation_limit : int = 10 ) : 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 ) engaged = [ ] try : engaged = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.event" : { "$in" : [ "user" , "bot" ] } , "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$events.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : { "month" : "$month" , "sender_id" : "$sender_id" } , "events" : { "$push" : "$events" } , "allevents" : { "$push" : "$events" } } } , { "$unwind" : "$events" } , { "$project" : { "_id" : 1 , "events" : 1 , "following_events" : { "$arrayElemAt" : [ "$allevents" , { "$add" : [ { "$indexOfArray" : [ "$allevents" , "$events" ] } , 1 ] } ] } } } , { "$project" : { "user_event" : "$events.event" , "bot_event" : "$following_events.event" , } } , { "$match" : { "user_event" : "user" , "bot_event" : "bot" } } , { "$group" : { "_id" : "$_id" , "event" : { "$sum" : 1 } } } , { "$match" : { "event" : { "$gte" : conversation_limit } } } , { "$group" : { "_id" : "$_id.month" , "count" : { "$sum" : 1 } } } , { "$project" : { "_id" : 1 , "count" : 1 , } } ] , allowDiskUse = True ) ) except Exception as e : logger . error ( e ) message = '\n' . join ( [ message , str ( e ) ] ) engaged_users = { d [ '_id' ] : d [ 'count' ] for d in engaged } return ( { "engaged_user_range" : engaged_users } , message )
short_docstring: Computes the trend for engaged user count
short_docstring_tokens: Computes the trend for engaged user count
comment: """
          Computes the trend for engaged user count
  
          :param collection: collection to connect to
          :param month: default is 6 months
          :param conversation_limit: conversation step number to determine engaged users
          :return: dictionary of counts of engaged users for the previous months
          """