<jupyter_start><jupyter_text>AzMeta Resize Recommendations<jupyter_code>import datetime

print("Report Date:", datetime.datetime.now().isoformat())
print("Total Annual Savings:", "${:,.2f}".format(local_data[('AzMeta', 'annual_savings')].sum()), "(Non-RI Pricing, SQL and Windows AHUB Licensing)")
# Present the dataset
import matplotlib as plt
import itertools
from matplotlib import colors


def background_limit_coloring(row):
    cmap="coolwarm"
    text_color_threshold=0.408
    limit_index = (row.index.get_level_values(0)[0], 'new_limit')
    smin = 0
    smax = row[limit_index] 
    if pd.isna(smax):
        return [''] * len(row)
    
    rng = smax - smin
    norm = colors.Normalize(smin, smax)
    rgbas = plt.cm.get_cmap(cmap)(norm(row.to_numpy(dtype=float)))

    def relative_luminance(rgba):
        r, g, b = (
            x / 12.92 if x <= 0.03928 else ((x + 0.055) / 1.055 ** 2.4)
            for x in rgba[:3]
        )
        return 0.2126 * r + 0.7152 * g + 0.0722 * b

    def css(rgba):
        dark = relative_luminance(rgba) < text_color_threshold
        text_color = "#f1f1f1" if dark else "#000000"
        return f"background-color: {colors.rgb2hex(rgba)};color: {text_color};"
    
    return [css(rgba) for rgba in rgbas[0:-1]] + ['']


def build_header_style(col_groups):
    start = 0
    styles = []
    palette = ['#f6f6f6', '#eae9e9', '#d4d7dd', '#f6f6f6', '#eae9e9', '#d4d7dd', '#f6f6f6', '#eae9e9', '#d4d7dd']
    for i,group in enumerate(itertools.groupby(col_groups, lambda c:c[0])):
        styles.append({'selector': f'.col_heading.level0.col{start}', 'props': [('background-color', palette[i])]})
        group_len = len(tuple(group[1]))
        for j in range(group_len):
            styles.append({'selector': f'.col_heading.level1.col{start + j}', 'props': [('background-color', palette[i])]})
        start += group_len
    return styles


data_group_names = [x for x in full_data.columns.get_level_values(0).unique() if x not in ('Resource', 'AzMeta', 'Advisor')]
num_mask = [x[0] in data_group_names for x in full_data.columns.to_flat_index()]
styler = full_data.style.hide_index() \
    .set_properties(**{'font-weight': 'bold'}, subset=[('Resource', 'resource_name')]) \
    .format('{:.1f}', subset=num_mask, na_rep='N/A') \
    .format('${:.2f}', subset=[('AzMeta', 'annual_savings')], na_rep='N/A') \
    .set_table_styles(build_header_style(full_data.columns))
for data_group in data_group_names:
    mask = [x == data_group for x in full_data.columns.get_level_values(0)]
    styler = styler.apply(background_limit_coloring, axis=1, subset=mask)
styler<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16874763526295877, 'fraction_numerical': 0.03329549754067348, 'mean_word_length': 3.8962962962962964, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '2386', 'license': 'MIT', 'n_tokens_mistral': 1028, 'n_tokens_neox': 979, 'n_words': 195, 'path': 'src/rightsize/rightsizereport.ipynb', 'repo_name': 'wpbrown/azmeta-rightsize-iaas', 'size': '2643'}