'Generate HTML.'

def generate_html(self):

    html = HTMLDocument('Results')
    for phase in self.run_data.keys():
        if (phase in ('fake_assets',)):
            continue
        per_phase = self.run_data[phase]
        html.add_header(1, phase)
        title_map = {'duration': 'Total    Duration    (ms)', 'ratio': 'Total    Duration    Per    Number    of    Assets    (ms/asset)', 'variable_cost': 'Asset    Export    Duration    Per    Number    of    Assets    (ms/asset)'}
        for table_type in ('duration', 'ratio', 'variable_cost'):
            if ((phase == 'all') and (table_type in ('ratio', 'variable_cost'))):
                continue
            columns = ['Asset    Metadata    Amount']
            ms_keys = sorted(self.all_modulestore_combos)
            for k in ms_keys:
                columns.append('{}    ({})'.format(k, table_type))
            phase_table = HTMLTable(columns)
            for amount in sorted(per_phase.keys()):
                per_amount = per_phase[amount]
                num_assets = int(amount)
                row = [amount]
                for modulestore in ms_keys:
                    if (table_type == 'duration'):
                        value = per_amount[modulestore]
                    elif (table_type == 'ratio'):
                        if (num_assets != 0):
                            value = (per_amount[modulestore] / float(amount))
                        else:
                            value = 0
                    elif (table_type == 'variable_cost'):
                        if (num_assets == 0):
                            value = 0
                        else:
                            value = ((per_amount[modulestore] - per_phase['0'][modulestore]) / float(amount))
                    row.append('{}'.format(value))
                phase_table.add_row(row)
            html.add_header(2, title_map[table_type])
            html.add_to_body(phase_table.table)
    return html
