@read_session
def get_bad_replicas_summary(rse_expression=None, from_date=None, to_date=None, filter=None, session=None):
    "\n    List the bad file replicas summary. Method used by the rucio-ui.\n    :param rse_expression: The RSE expression.\n    :param from_date: The start date.\n    :param to_date: The end date.\n    :param filter: Dictionary of attributes by which the RSE results should be filtered. e.g.: {'availability_write': True}\n    :param session: The database session in use.\n    "
    result = []
    incidents = {}
    rse_clause = []
    if rse_expression:
        for rse in parse_expression(expression=rse_expression, filter=filter, session=session):
            rse_clause.append((models.BadReplicas.rse_id == rse['id']))
    elif filter:
        for rse in list_rses(filters=filter, session=session):
            rse_clause.append((models.BadReplicas.rse_id == rse['id']))
    if (session.bind.dialect.name == 'oracle'):
        to_days = func.trunc(models.BadReplicas.created_at, str('DD'))
    elif (session.bind.dialect.name == 'mysql'):
        to_days = func.date(models.BadReplicas.created_at)
    elif (session.bind.dialect.name == 'postgresql'):
        to_days = func.date_trunc('day', models.BadReplicas.created_at)
    else:
        to_days = func.strftime(models.BadReplicas.created_at, '%Y-%m-%d')
    query = session.query(func.count(), to_days, models.BadReplicas.rse_id, models.BadReplicas.state, models.BadReplicas.reason)
    if (rse_clause != []):
        query = query.filter(or_(*rse_clause))
    if from_date:
        query = query.filter((models.BadReplicas.created_at > from_date))
    if to_date:
        query = query.filter((models.BadReplicas.created_at < to_date))
    summary = query.group_by(to_days, models.BadReplicas.rse_id, models.BadReplicas.reason, models.BadReplicas.state).all()
    for row in summary:
        if ((row[2], row[1], row[4]) not in incidents):
            incidents[(row[2], row[1], row[4])] = {}
        incidents[(row[2], row[1], row[4])][str(row[3].name)] = row[0]
    for incident in incidents:
        res = incidents[incident]
        res['rse_id'] = incident[0]
        res['rse'] = get_rse_name(rse_id=incident[0], session=session)
        res['created_at'] = incident[1]
        res['reason'] = incident[2]
        result.append(res)
    return result
List the bad file replicas summary. Method used by the rucio-ui.
:param rse_expression: The RSE expression.
:param from_date: The start date.
:param to_date: The end date.
:param filter: Dictionary of attributes by which the RSE results should be filtered. e.g.: {'availability_write': True}
:param session: The database session in use.
@read_session
def get_bad_replicas_summary(rse_expression=None, from_date=None, to_date=None, filter=None, session=None):
    "\n    List the bad file replicas summary. Method used by the rucio-ui.\n    :param rse_expression: The RSE expression.\n    :param from_date: The start date.\n    :param to_date: The end date.\n    :param filter: Dictionary of attributes by which the RSE results should be filtered. e.g.: {'availability_write': True}\n    :param session: The database session in use.\n    "
    result = []
    incidents = {}
    rse_clause = []
    if rse_expression:
        for rse in parse_expression(expression=rse_expression, filter=filter, session=session):
            rse_clause.append((models.BadReplicas.rse_id == rse['id']))
    elif filter:
        for rse in list_rses(filters=filter, session=session):
            rse_clause.append((models.BadReplicas.rse_id == rse['id']))
    if (session.bind.dialect.name == 'oracle'):
        to_days = func.trunc(models.BadReplicas.created_at, str('DD'))
    elif (session.bind.dialect.name == 'mysql'):
        to_days = func.date(models.BadReplicas.created_at)
    elif (session.bind.dialect.name == 'postgresql'):
        to_days = func.date_trunc('day', models.BadReplicas.created_at)
    else:
        to_days = func.strftime(models.BadReplicas.created_at, '%Y-%m-%d')
    query = session.query(func.count(), to_days, models.BadReplicas.rse_id, models.BadReplicas.state, models.BadReplicas.reason)
    if (rse_clause != []):
        query = query.filter(or_(*rse_clause))
    if from_date:
        query = query.filter((models.BadReplicas.created_at > from_date))
    if to_date:
        query = query.filter((models.BadReplicas.created_at < to_date))
    summary = query.group_by(to_days, models.BadReplicas.rse_id, models.BadReplicas.reason, models.BadReplicas.state).all()
    for row in summary:
        if ((row[2], row[1], row[4]) not in incidents):
            incidents[(row[2], row[1], row[4])] = {}
        incidents[(row[2], row[1], row[4])][str(row[3].name)] = row[0]
    for incident in incidents:
        res = incidents[incident]
        res['rse_id'] = incident[0]
        res['rse'] = get_rse_name(rse_id=incident[0], session=session)
        res['created_at'] = incident[1]
        res['reason'] = incident[2]
        result.append(res)
    return result