'Summary of Current Indicator Status
@ToDo: Make this configurable'

@staticmethod
def project_current_indicator_status(row):

    if hasattr(row, 'project_project'):
        row = row.project_project
    if hasattr(row, 'id'):
        project_id = row['id']
    else:
        return current.messages['NONE']
    table = current.s3db.project_indicator_data
    query = ((table.deleted != True) & (table.project_id == project_id))
    rows = current.db(query).select(table.indicator_id, table.end_date, table.target_value, table.value)
    indicators = {}
    for row in rows:
        indicator_id = row.indicator_id
        if (indicator_id in indicators):
            old_date = indicators[indicator_id]['date']
            new_date = row.end_date
            if (datetime.datetime(old_date.year, new_date.month, new_date.day) > datetime.datetime(old_date.year, old_date.month, old_date.day)):
                indicators[indicator_id].update(date=new_date, percentage=row.percentage())
        else:
            indicators[indicator_id] = {'date': row.end_date, 'percentage': row.percentage()}
    len_indicators = len(indicators)
    if (not len_indicators):
        return 0
    NONE = current.messages['NONE']
    percentages = 0
    for indicator_id in indicators:
        percentage = indicators[indicator_id]['percentage']
        if (percentage != NONE):
            percentages += float(percentage[:(-1)])
    return (percentages / len_indicators)
