original_docstring: 
          Computes the trend for successful conversation count
  
          :param collection: collection to connect to
          :param month: default is 6 months
          :param fallback_action: fallback action configured for bot
          :param nlu_fallback_action: nlu fallback configured for bot
          :return: dictionary of counts of successful bot conversations for the previous months
          
docstring: Computes the trend for successful conversation count
docstring_tokens: Computes the trend for successful conversation count
code: def successful_conversation_range(collection: Text,
                                        month: int = 6,
                                        fallback_action: str = 'action_default_fallback',
                                        nlu_fallback_action: str = 'nlu_fallback'):
  
          """
          Computes the trend for successful conversation count
  
          :param collection: collection to connect to
          :param month: default is 6 months
          :param fallback_action: fallback action configured for bot
          :param nlu_fallback_action: nlu fallback configured for bot
          :return: dictionary of counts of successful bot conversations 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)
              new_session_total, single_session_total = [], []
              unsuccessful_new_session, unsuccessful_single_session = [], []
              try:
                  new_session_total = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                            {"$match": {"events.timestamp": {"$gte": Utility.get_timestamp_previous_month(month)}}},
                                            {"$match": {"events.name": "action_session_start"}},
                                            {"$addFields": {"month": {
                                                "$month": {"$toDate": {"$multiply": ["$events.timestamp", 1000]}}}}},
                                            {"$group": {"_id": "$month", "count": {"$sum": 1}}},
                                            ], allowDiskUse=True))
  
                  single_session_total = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                            {"$match": {"events.timestamp": {"$gte": Utility.get_timestamp_previous_month(month)}}},
                                            {"$match": {"$or": [{"events.event": "user"},
                                                                {"events.name": "action_session_start"}]}},
                                            {"$group": {"_id": "$sender_id", "events": {"$push": "$events"}}},
                                            {"$addFields": {"first_event": {"$first": "$events"}}},
                                            {"$match": {"first_event.event": "user"}},
                                            {"$addFields": {"month": {
                                                "$month": {"$toDate": {"$multiply": ["$first_event.timestamp", 1000]}}}}},
                                            {"$group": {"_id": "$month", "count": {"$sum": 1}}},
                                            ], allowDiskUse=True))
  
                  unsuccessful_new_session = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                            {"$match": {"events.timestamp": {"$gte": Utility.get_timestamp_previous_month(month)}}},
                                            {"$match": {"events.name": {
                                                "$in": ["action_session_start", fallback_action,
                                                        nlu_fallback_action]}}},
                                            {"$group": {"_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]}
                                                    ]
                                                }
                                            }},
                                            {"$match": {'$or': [{"events.name": fallback_action},
                                                                {"events.name": nlu_fallback_action}],
                                                        "following_events.name": "action_session_start"}},
                                            {"$addFields": {"month": {
                                                "$month": {"$toDate": {"$multiply": ["$events.timestamp", 1000]}}}}},
                                            {"$group": {"_id": "$month", "count": {"$sum": 1}}},
  
                                            ], allowDiskUse=True))
  
                  unsuccessful_single_session = list(
                      conversations.aggregate([{"$unwind": {"path": "$events", "includeArrayIndex": "arrayIndex"}},
                                            {"$match": {"events.timestamp": {"$gte": Utility.get_timestamp_previous_month(month)}}},
                                            {"$match": {"events.name": {
                                                "$in": ["action_session_start", fallback_action,
                                                        nlu_fallback_action]}}},
                                            {"$group": {"_id": "$sender_id", "events": {"$push": "$events"}}},
                                            {"$addFields": {"last_event": {"$last": "$events"}}},
                                            {"$match": {'$or': [{"last_event.name": fallback_action},
                                                                {"last_event.name": nlu_fallback_action}]}},
                                            {"$addFields": {"month": {
                                                "$month": {"$toDate": {"$multiply": ["$last_event.timestamp", 1000]}}}}},
                                            {"$group": {"_id": "$month", "count": {"$sum": 1}}},
                                            ], allowDiskUse=True)
                      )
              except Exception as e:
                  logger.error(e)
                  message = '\n'.join([message, str(e)])
              single_session_total = {d['_id']: d['count'] for d in single_session_total}
              new_session_total = {d['_id']: d['count'] for d in new_session_total}
              single_session_total = {k: single_session_total.get(k, 0) for k in new_session_total.keys()}
              total_sessions = {k: single_session_total[k] + new_session_total[k] for k in new_session_total.keys()}
              unsuccessful_single_session = {d['_id']: d['count'] for d in unsuccessful_single_session}
              unsuccessful_new_session = {d['_id']: d['count'] for d in unsuccessful_new_session}
              unsuccessful_single_session = {k: unsuccessful_single_session.get(k, 0) for k in
                                             unsuccessful_new_session.keys()}
              total_unsuccessful_sessions = {k: unsuccessful_single_session[k] + unsuccessful_new_session[k] for k in
                                             unsuccessful_new_session.keys()}
              successful_sessions = {k: total_sessions[k] - total_unsuccessful_sessions.get(k, 0) for k in
                                     total_sessions.keys()}
              return (
                  {"successful_sessions": successful_sessions, "total_sessions": total_sessions},
                  message
              )
code_tokens: def successful_conversation_range ( collection : Text , month : int = 6 , fallback_action : str = 'action_default_fallback' , nlu_fallback_action : str = 'nlu_fallback' ) : 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 ) new_session_total , single_session_total = [ ] , [ ] unsuccessful_new_session , unsuccessful_single_session = [ ] , [ ] try : new_session_total = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$match" : { "events.name" : "action_session_start" } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$events.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : "$month" , "count" : { "$sum" : 1 } } } , ] , allowDiskUse = True ) ) single_session_total = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$match" : { "$or" : [ { "events.event" : "user" } , { "events.name" : "action_session_start" } ] } } , { "$group" : { "_id" : "$sender_id" , "events" : { "$push" : "$events" } } } , { "$addFields" : { "first_event" : { "$first" : "$events" } } } , { "$match" : { "first_event.event" : "user" } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$first_event.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : "$month" , "count" : { "$sum" : 1 } } } , ] , allowDiskUse = True ) ) unsuccessful_new_session = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$match" : { "events.name" : { "$in" : [ "action_session_start" , fallback_action , nlu_fallback_action ] } } } , { "$group" : { "_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 ] } ] } } } , { "$match" : { '$or' : [ { "events.name" : fallback_action } , { "events.name" : nlu_fallback_action } ] , "following_events.name" : "action_session_start" } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$events.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : "$month" , "count" : { "$sum" : 1 } } } , ] , allowDiskUse = True ) ) unsuccessful_single_session = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" , "includeArrayIndex" : "arrayIndex" } } , { "$match" : { "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$match" : { "events.name" : { "$in" : [ "action_session_start" , fallback_action , nlu_fallback_action ] } } } , { "$group" : { "_id" : "$sender_id" , "events" : { "$push" : "$events" } } } , { "$addFields" : { "last_event" : { "$last" : "$events" } } } , { "$match" : { '$or' : [ { "last_event.name" : fallback_action } , { "last_event.name" : nlu_fallback_action } ] } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$last_event.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : "$month" , "count" : { "$sum" : 1 } } } , ] , allowDiskUse = True ) ) except Exception as e : logger . error ( e ) message = '\n' . join ( [ message , str ( e ) ] ) single_session_total = { d [ '_id' ] : d [ 'count' ] for d in single_session_total } new_session_total = { d [ '_id' ] : d [ 'count' ] for d in new_session_total } single_session_total = { k : single_session_total . get ( k , 0 ) for k in new_session_total . keys ( ) } total_sessions = { k : single_session_total [ k ] + new_session_total [ k ] for k in new_session_total . keys ( ) } unsuccessful_single_session = { d [ '_id' ] : d [ 'count' ] for d in unsuccessful_single_session } unsuccessful_new_session = { d [ '_id' ] : d [ 'count' ] for d in unsuccessful_new_session } unsuccessful_single_session = { k : unsuccessful_single_session . get ( k , 0 ) for k in unsuccessful_new_session . keys ( ) } total_unsuccessful_sessions = { k : unsuccessful_single_session [ k ] + unsuccessful_new_session [ k ] for k in unsuccessful_new_session . keys ( ) } successful_sessions = { k : total_sessions [ k ] - total_unsuccessful_sessions . get ( k , 0 ) for k in total_sessions . keys ( ) } return ( { "successful_sessions" : successful_sessions , "total_sessions" : total_sessions } , message )
short_docstring: Computes the trend for successful conversation count
short_docstring_tokens: Computes the trend for successful conversation count
comment: """
          Computes the trend for successful conversation count
  
          :param collection: collection to connect to
          :param month: default is 6 months
          :param fallback_action: fallback action configured for bot
          :param nlu_fallback_action: nlu fallback configured for bot
          :return: dictionary of counts of successful bot conversations for the previous months
          """