third_party/blink/renderer/build/scripts/update_css_ranking.py
def produce_partition_rule(config_file, css_ranking_api):
    """Find the partition rule for the groups and print them to config_file

    Args:
        config_file: the file to write the parameters to
        css_ranking_api: url to CSS ranking api

    """
    css_ranking = sorted(json.loads(urlopen(css_ranking_api).read()),
                         key=lambda x: -x["day_percentage"])
    total_css_properties = len(css_ranking)
    css_ranking_dictionary = dict(
        [(x["property_name"], x["day_percentage"] * 100) for x in css_ranking])
    css_ranking_cdf = dict(
        zip([x["property_name"] for x in css_ranking], [
            float(i) / total_css_properties
            for i in range(total_css_properties)
        ]))
    css_properties = json5_generator.Json5File.load_from_files(
        [CSS_PROPERTIES]).name_dictionaries

    rare_non_inherited_properties = sorted(
        [(x["name"].original, css_ranking_dictionary[x["name"].original])
         for x in css_properties
         if not x["inherited"] and x["field_group"] is not None and "*" in
         x["field_group"] and x["name"].original in css_ranking_dictionary],
        key=lambda x: -x[1])
    rare_inherited_properties = sorted(
        [(x["name"].original, css_ranking_dictionary[x["name"].original])
         for x in css_properties
         if x["inherited"] and x["field_group"] is not None and "*" in
         x["field_group"] and x["name"].original in css_ranking_dictionary],
        key=lambda x: -x[1])

    rni_properties_rule = find_partition_rule(
        rare_non_inherited_properties, css_ranking_cdf, n_cluster=3)

    ri_properties_rule = find_partition_rule(
        rare_inherited_properties,
        css_ranking_cdf,
        n_cluster=2,
        transform=lambda x: math.log(x + 10e-6))

    with open(config_file, 'w') as fw:
        fw.write(
            "// The grouping parameter is a cumulative distribution " \
            "over the whole set of ranked\n"
        )
        fw.write("// CSS properties.\n")
        json.dump({
            "parameters": {},
            "data": [{
                "name": "rare_non_inherited_properties_rule",
                "cumulative_distribution": rni_properties_rule
            },
                     {
                         "name": "rare_inherited_properties_rule",
                         "cumulative_distribution": ri_properties_rule
                     }]
        },
                  fw,
                  indent=4)
Find the partition rule for the groups and print them to config_file

    Args:
        config_file: the file to write the parameters to
        css_ranking_api: url to CSS ranking api

    
Find the partition rule for the groups and print them to config_file
Find the partition rule for the groups and print them to config_file
def produce_partition_rule(config_file, css_ranking_api):
    css_ranking = sorted(json.loads(urlopen(css_ranking_api).read()),
                         key=lambda x: -x["day_percentage"])
    total_css_properties = len(css_ranking)
    css_ranking_dictionary = dict(
        [(x["property_name"], x["day_percentage"] * 100) for x in css_ranking])
    css_ranking_cdf = dict(
        zip([x["property_name"] for x in css_ranking], [
            float(i) / total_css_properties
            for i in range(total_css_properties)
        ]))
    css_properties = json5_generator.Json5File.load_from_files(
        [CSS_PROPERTIES]).name_dictionaries
    rare_non_inherited_properties = sorted(
        [(x["name"].original, css_ranking_dictionary[x["name"].original])
         for x in css_properties
         if not x["inherited"] and x["field_group"] is not None and "*" in
         x["field_group"] and x["name"].original in css_ranking_dictionary],
        key=lambda x: -x[1])
    rare_inherited_properties = sorted(
        [(x["name"].original, css_ranking_dictionary[x["name"].original])
         for x in css_properties
         if x["inherited"] and x["field_group"] is not None and "*" in
         x["field_group"] and x["name"].original in css_ranking_dictionary],
        key=lambda x: -x[1])
    rni_properties_rule = find_partition_rule(
        rare_non_inherited_properties, css_ranking_cdf, n_cluster=3)
    ri_properties_rule = find_partition_rule(
        rare_inherited_properties,
        css_ranking_cdf,
        n_cluster=2,
        transform=lambda x: math.log(x + 10e-6))
    with open(config_file, 'w') as fw:
        fw.write(
            "// The grouping parameter is a cumulative distribution " \
            "over the whole set of ranked\n"
        )
        fw.write("// CSS properties.\n")
        json.dump({
            "parameters": {},
            "data": [{
                "name": "rare_non_inherited_properties_rule",
                "cumulative_distribution": rni_properties_rule
            },
                     {
                         "name": "rare_inherited_properties_rule",
                         "cumulative_distribution": ri_properties_rule
                     }]
        },
                  fw,
                  indent=4)
def produce_partition_rule ( config_file , css_ranking_api ) : css_ranking = sorted ( json . loads ( urlopen ( css_ranking_api ) . read ( ) ) , key = lambda x : - x [ "day_percentage" ] ) total_css_properties = len ( css_ranking ) css_ranking_dictionary = dict ( [ ( x [ "property_name" ] , x [ "day_percentage" ] * 100 ) for x in css_ranking ] ) css_ranking_cdf = dict ( zip ( [ x [ "property_name" ] for x in css_ranking ] , [ float ( i ) / total_css_properties for i in range ( total_css_properties ) ] ) ) css_properties = json5_generator . Json5File . load_from_files ( [ CSS_PROPERTIES ] ) . name_dictionaries rare_non_inherited_properties = sorted ( [ ( x [ "name" ] . original , css_ranking_dictionary [ x [ "name" ] . original ] ) for x in css_properties if not x [ "inherited" ] and x [ "field_group" ] is not None and "*" in x [ "field_group" ] and x [ "name" ] . original in css_ranking_dictionary ] , key = lambda x : - x [ 1 ] ) rare_inherited_properties = sorted ( [ ( x [ "name" ] . original , css_ranking_dictionary [ x [ "name" ] . original ] ) for x in css_properties if x [ "inherited" ] and x [ "field_group" ] is not None and "*" in x [ "field_group" ] and x [ "name" ] . original in css_ranking_dictionary ] , key = lambda x : - x [ 1 ] ) rni_properties_rule = find_partition_rule ( rare_non_inherited_properties , css_ranking_cdf , n_cluster = 3 ) ri_properties_rule = find_partition_rule ( rare_inherited_properties , css_ranking_cdf , n_cluster = 2 , transform = lambda x : math . log ( x + 10e-6 ) ) with open ( config_file , 'w' ) as fw : fw . write ( "// The grouping parameter is a cumulative distribution " "over the whole set of ranked\n" ) fw . write ( "// CSS properties.\n" ) json . dump ( { "parameters" : { } , "data" : [ { "name" : "rare_non_inherited_properties_rule" , "cumulative_distribution" : rni_properties_rule } , { "name" : "rare_inherited_properties_rule" , "cumulative_distribution" : ri_properties_rule } ] } , fw , indent = 4 )
Find the partition rule for the groups and print them to config_file
Find the partition rule for the groups and print them to config_file
"""Find the partition rule for the groups and print them to config_file

    Args:
        config_file: the file to write the parameters to
        css_ranking_api: url to CSS ranking api

    """
config_file
the file to write the parameters to
the file to write the parameters to
css_ranking_api
url to CSS ranking api
url to CSS ranking api