original_docstring: 
          Computes the trend for fallback counts
          :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 fallback counts for the previous months
          
docstring: Computes the trend for fallback counts
docstring_tokens: Computes the trend for fallback counts
code: def fallback_count_range(collection: Text,
                               month: int = 6,
                               fallback_action: str = 'action_default_fallback',
                               nlu_fallback_action: str = 'nlu_fallback'):
  
          """
          Computes the trend for fallback counts
          :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 fallback counts 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)
              action_counts = []
              fallback_counts = []
              try:
  
                  fallback_counts = list(
                      conversations.aggregate([{"$unwind": {"path": "$events"}},
                                               {"$match": {"events.event": "action",
                                                           "events.timestamp": {
                                                               "$gte": Utility.get_timestamp_previous_month(
                                                                   month)}}},
                                               {"$match": {'$or': [{"events.name": fallback_action},
                                                                   {"events.name": nlu_fallback_action}]}},
                                               {"$addFields": {"month": {
                                                   "$month": {"$toDate": {"$multiply": ["$events.timestamp", 1000]}}}}},
                                               {"$group": {"_id": "$month", "count": {"$sum": 1}}},
                                               {"$project": {"_id": 1, "count": 1}}
                                               ]))
                  action_counts = list(
                      conversations.aggregate([{"$unwind": {"path": "$events"}},
                                               {"$match": {"$and": [{"events.event": "action"},
                                               {"events.name": {"$nin": ['action_listen', 'action_session_start']}}]}},
                                               {"$match": {"events.timestamp": {
                                                "$gte": Utility.get_timestamp_previous_month(month)}}},
                                               {"$addFields": {"month": {
                                                "$month": {"$toDate": {"$multiply": ["$events.timestamp", 1000]}}}}},
                                               {"$group": {"_id": "$month", "total_count": {"$sum": 1}}},
                                               {"$project": {"_id": 1, "total_count": 1}}
                                               ]))
              except Exception as e:
                  logger.error(e)
                  message = '\n'.join([message, str(e)])
              action_count = {d['_id']: d['total_count'] for d in action_counts}
              fallback_count = {d['_id']: d['count'] for d in fallback_counts}
              final_trend = {k: 100*(fallback_count.get(k)/action_count.get(k)) for k in list(fallback_count.keys())}
              return (
                  {"fallback_count_rate": final_trend, "total_fallback_count": fallback_count},
                  message
              )
code_tokens: def fallback_count_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 ) action_counts = [ ] fallback_counts = [ ] try : fallback_counts = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" } } , { "$match" : { "events.event" : "action" , "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$match" : { '$or' : [ { "events.name" : fallback_action } , { "events.name" : nlu_fallback_action } ] } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$events.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : "$month" , "count" : { "$sum" : 1 } } } , { "$project" : { "_id" : 1 , "count" : 1 } } ] ) ) action_counts = list ( conversations . aggregate ( [ { "$unwind" : { "path" : "$events" } } , { "$match" : { "$and" : [ { "events.event" : "action" } , { "events.name" : { "$nin" : [ 'action_listen' , 'action_session_start' ] } } ] } } , { "$match" : { "events.timestamp" : { "$gte" : Utility . get_timestamp_previous_month ( month ) } } } , { "$addFields" : { "month" : { "$month" : { "$toDate" : { "$multiply" : [ "$events.timestamp" , 1000 ] } } } } } , { "$group" : { "_id" : "$month" , "total_count" : { "$sum" : 1 } } } , { "$project" : { "_id" : 1 , "total_count" : 1 } } ] ) ) except Exception as e : logger . error ( e ) message = '\n' . join ( [ message , str ( e ) ] ) action_count = { d [ '_id' ] : d [ 'total_count' ] for d in action_counts } fallback_count = { d [ '_id' ] : d [ 'count' ] for d in fallback_counts } final_trend = { k : 100 * ( fallback_count . get ( k ) / action_count . get ( k ) ) for k in list ( fallback_count . keys ( ) ) } return ( { "fallback_count_rate" : final_trend , "total_fallback_count" : fallback_count } , message )
short_docstring: Computes the trend for fallback counts
short_docstring_tokens: Computes the trend for fallback counts
comment: """
          Computes the trend for fallback counts
          :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 fallback counts for the previous months
          """