<<

NAME

ProductOpener::PackagingStats

DESCRIPTION

Generates aggregated data about the packaging components of products for a specific category in a specific country

Aggregation counts are stored in a structure of the form:

{ countries => { "en:world" => .. "en:france" => { categories => { "all" => .. # stats for all categories "en:yogourts" => { shapes => { "en:unknown" => .. "all" => .. # stats for all shapes "en:bottle" => { materials_parents => .. # stats for parents materials (e.g. PET will also count for plastic) materials => { "all" => .. "en:plastic" => 12, # number of products sold in France that are yogurts and that have a plastic bottle packaging component } }, .. } }, .. } }, .. } }

add_product_components_to_stats($name, $packagings_stats_ref, $product_ref)

Add data from all packagings of a product to stats for all its countries and categories combinations.

When $name is "packagings-with-weights", we store stats for weights, otherwise, we store only the number of products.

compute_stats_for_all_weights ($packagings_stats_ref)

Compute stats (means etc.) for packaging components, aggregated at the countries, categories, shapes and materials levels

compute_stats_for_values ($values_ref)

Compute stats for values (e.g. weights or percent) passed in $values_ref->{values} in comma delimited format The values are converted to an array.

remove_unpopular_categories_shapes_and_materials ($packagings_stats_ref, $min_products)

Remove stats for categories, shapes, and materials that have less than the required amount of product.

This is necessary to generate a smaller dataset that can be used to generate autocomplete suggestions for packaging shapes and materials, given a country and a list of categories of the product.

Also remove shapes_parents and materials_parents

Arguments

$packagings_stats_ref

$min_products

remove_packagings_materials_stats_for_unpopular_categories ($packagings_materials_stats_ref, $min_products)

Remove packaging materials stats for categories that have less than the required amount of product.

Arguments

$packagings_materials_stats_ref

$min_products

store_stats($name, $packagings_stats_ref, $packagings_materials_stats_ref)

Store the stats in JSON format for internal use in Product Opener and store a copy in the static web directory

init_products_packaging_components_csv($name)

Open a file, initialize a Text::CSV object, and output the CSV header for packaging components.

Return values

$filehandle

$csv

export_product_packaging_components_to_csv($csv, $filehandle, $product_ref)

Export each packaging component of the product as one line in the CSV file.

add_product_materials_to_stats($name, $packagings_stats_ref, $product_ref)

Add aggregated (by parent materials) data for all packagings of a product to stats for all its countries and categories combinations.

For each material, we record values for those fields: - contain: the product contains the material - main: the product has the material as its main material - weight: weight of the material, even if the product does not contain it (0 otherwise) - weight_contain: weight of the material, if the product contains it - weight_main: weight of the material, if the product has it as its main material

compute_stats_for_all_materials ($packagings_materials_stats_ref)

Compute stats (means etc.) for packaging materials, aggregated at the countries, categories and materials levels

generate_packaging_stats_for_query($name, $query_ref)

Generate packaging stats for products matching a specific query.

Stats are saved in .json format in $BASE_DIRS{PRIVATE_DATA}/categories_stats/ and in JSON format in $BASE_DIRS{PUBLIC_DATA}/categories_stats/

Arguments

name $name

query reference $query_ref

<<