コード例 #1
0
def render_path_image(summary):
    n_freq_table_max = config["n_freq_table_max"].get(int)
    image_format = config["plot"]["image_format"].get(str)

    template_variables = render_path(summary)

    # Top
    template_variables["top"].content["items"][0].content[
        "var_type"] = "Image Path"

    # Bottom
    keys = {"Image shape": "image_shape", "Exif keys": "exif_keys"}

    for title, key in keys.items():
        template_variables["freqtable_{}".format(key)] = freq_table(
            freqtable=summary["{}_counts".format(key)],
            n=summary["n"],
            max_number_to_print=n_freq_table_max,
        )

    # TODO: add dropdown to switch to specific values
    exif_keys = FrequencyTable(
        template_variables["freqtable_{}".format("exif_keys")],
        name="Exif keys",
        anchor_id="{varid}exif_frequency".format(varid=summary["varid"]),
    )

    template_variables["bottom"].content["items"].append(exif_keys)

    image_shape_freq = FrequencyTable(
        template_variables["freqtable_{}".format("image_shape")],
        name="Frequency",
        anchor_id="{varid}image_shape_frequency".format(
            varid=summary["varid"]),
    )

    image_shape_scatter = Image(
        scatter_series(summary["scatter_data"]),
        image_format=image_format,
        alt="Scatterplot of image sizes",
        caption="Scatterplot of image sizes",
        name="Scatter",
        anchor_id="{varid}scatter".format(varid=summary["varid"]),
    )

    image_shape = Sequence(
        [image_shape_freq, image_shape_scatter],
        sequence_type="tabs",
        name="Image shape",
        anchor_id="{varid}image_shape".format(varid=summary["varid"]),
    )

    template_variables["bottom"].content["items"].append(image_shape)

    return template_variables
コード例 #2
0
def render_image(config: Settings, summary: dict) -> dict:
    varid = summary["varid"]
    n_freq_table_max = config.n_freq_table_max
    redact = config.vars.cat.redact

    template_variables = render_file(config, summary)

    # Top
    template_variables["top"].content["items"][0].content["var_type"] = "Image"

    # Bottom
    image_items = []
    """
    Min Width           Min Height          Min Area
    Mean Width          Mean Height         Mean Height
    Median Width        Median Height       Median Height
    Max Width           Max Height          Max Height

    All dimension properties are in pixels.
    """

    image_shape_items = [
        Container(
            [
                Table([
                    {
                        "name":
                        "Min width",
                        "value":
                        fmt_numeric(summary["min_width"],
                                    precision=config.report.precision),
                        "alert":
                        False,
                    },
                    {
                        "name":
                        "Median width",
                        "value":
                        fmt_numeric(
                            summary["median_width"],
                            precision=config.report.precision,
                        ),
                        "alert":
                        False,
                    },
                    {
                        "name":
                        "Max width",
                        "value":
                        fmt_numeric(summary["max_width"],
                                    precision=config.report.precision),
                        "alert":
                        False,
                    },
                ]),
                Table([
                    {
                        "name":
                        "Min height",
                        "value":
                        fmt_numeric(summary["min_height"],
                                    precision=config.report.precision),
                        "alert":
                        False,
                    },
                    {
                        "name":
                        "Median height",
                        "value":
                        fmt_numeric(
                            summary["median_height"],
                            precision=config.report.precision,
                        ),
                        "alert":
                        False,
                    },
                    {
                        "name":
                        "Max height",
                        "value":
                        fmt_numeric(summary["max_height"],
                                    precision=config.report.precision),
                        "alert":
                        False,
                    },
                ]),
                Table([
                    {
                        "name":
                        "Min area",
                        "value":
                        fmt_numeric(summary["min_area"],
                                    precision=config.report.precision),
                        "alert":
                        False,
                    },
                    {
                        "name":
                        "Median area",
                        "value":
                        fmt_numeric(
                            summary["median_area"],
                            precision=config.report.precision,
                        ),
                        "alert":
                        False,
                    },
                    {
                        "name":
                        "Max area",
                        "value":
                        fmt_numeric(summary["max_area"],
                                    precision=config.report.precision),
                        "alert":
                        False,
                    },
                ]),
            ],
            anchor_id=f"{varid}tbl",
            name="Overview",
            sequence_type="grid",
        ),
        Image(
            scatter_series(config, summary["image_dimensions"]),
            image_format=config.plot.image_format,
            alt="Scatter plot of image sizes",
            caption="Scatter plot of image sizes",
            name="Scatter plot",
            anchor_id=f"{varid}image_dimensions_scatter",
        ),
        FrequencyTable(
            freq_table(
                freqtable=summary["image_dimensions"].value_counts(),
                n=summary["n"],
                max_number_to_print=n_freq_table_max,
            ),
            name="Common values",
            anchor_id=f"{varid}image_dimensions_frequency",
            redact=False,
        ),
    ]

    image_shape = Container(
        image_shape_items,
        sequence_type="named_list",
        name="Dimensions",
        anchor_id=f"{varid}image_dimensions",
    )

    if "exif_keys_counts" in summary:
        items = [
            FrequencyTable(
                freq_table(
                    freqtable=pd.Series(summary["exif_keys_counts"]),
                    n=summary["n"],
                    max_number_to_print=n_freq_table_max,
                ),
                name="Exif keys",
                anchor_id=f"{varid}exif_keys",
                redact=redact,
            )
        ]
        for key, counts in summary["exif_data"].items():
            if key == "exif_keys":
                continue

            items.append(
                FrequencyTable(
                    freq_table(
                        freqtable=counts,
                        n=summary["n"],
                        max_number_to_print=n_freq_table_max,
                    ),
                    name=key,
                    anchor_id=f"{varid}_exif_{key}",
                    redact=redact,
                ))

        image_items.append(
            Container(
                items,
                anchor_id=f"{varid}exif_data",
                name="Exif data",
                sequence_type="named_list",
            ))

    image_items.append(image_shape)

    image_tab = Container(
        image_items,
        name="Image",
        sequence_type="tabs",
        anchor_id=f"{varid}image",
    )

    template_variables["bottom"].content["items"].append(image_tab)

    return template_variables