(counts: dict, as_json: bool)
return output
Returns the Trello status output as a summarized table
Returns the Trello status output as a summarized table
Returns the Trello status output as a summarized table
def _summary_status(counts: dict, as_json: bool) -> List[str]:
    """Returns the Trello status output as a summarized table"""

    row_format = ROW_FORMAT['summarized']

    total_assigned = 0
    total_completed = 0

    computed_data = []
    for team_name, data in counts.items():
        completed = data['Done']
        assigned = data['Total']

        total_completed += completed
        total_assigned += assigned

        if assigned == 0:
            computed_data.append((team_name, 100))
            continue

        computed_data.append((team_name, _get_percent(completed, assigned)))

    computed_data.sort(key=lambda x: x[1])
    total_percent_complete = _get_percent(total_completed, total_assigned)

    if as_json:
        json_data = {}
        for team_name, pct_complete in computed_data:
            json_data[team_name] = {
                "PctComplete": pct_complete,
            }

        json_data['Total'] = {
            "PctComplete": total_percent_complete,
        }

        return [json.dumps(json_data, indent=2)]

    output = []
    output.append(row_format.format(*HEADERS['summarized']))
    output.append(row_format.format(ROW_DIVIDER * 5, ROW_DIVIDER))

    for team_name, pct_complete in computed_data:
        row = row_format.format(team_name, "{}%".format(pct_complete))
        output.append(row)

    output.append(row_format.format(ROW_DIVIDER * 5, ROW_DIVIDER))
    output.append(row_format.format('TOTAL', "{}%".format(total_percent_complete)))

    return output
def _summary_status ( counts : dict , as_json : bool ) -> List [ str ] : row_format = ROW_FORMAT [ 'summarized' ] total_assigned = 0 total_completed = 0 computed_data = [ ] for team_name , data in counts . items ( ) : completed = data [ 'Done' ] assigned = data [ 'Total' ] total_completed += completed total_assigned += assigned if assigned == 0 : computed_data . append ( ( team_name , 100 ) ) continue computed_data . append ( ( team_name , _get_percent ( completed , assigned ) ) ) computed_data . sort ( key = lambda x : x [ 1 ] ) total_percent_complete = _get_percent ( total_completed , total_assigned ) if as_json : json_data = { } for team_name , pct_complete in computed_data : json_data [ team_name ] = { "PctComplete" : pct_complete , } json_data [ 'Total' ] = { "PctComplete" : total_percent_complete , } return [ json . dumps ( json_data , indent = 2 ) ] output = [ ] output . append ( row_format . format ( * HEADERS [ 'summarized' ] ) ) output . append ( row_format . format ( ROW_DIVIDER * 5 , ROW_DIVIDER ) ) for team_name , pct_complete in computed_data : row = row_format . format ( team_name , "{}%" . format ( pct_complete ) ) output . append ( row ) output . append ( row_format . format ( ROW_DIVIDER * 5 , ROW_DIVIDER ) ) output . append ( row_format . format ( 'TOTAL' , "{}%" . format ( total_percent_complete ) ) ) return output