ProductOpener::PackagingStats
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 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 (means etc.) for packaging components, aggregated at the countries, categories, shapes and materials levels
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 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
Remove packaging materials stats for categories that have less than the required amount of product.
Store the stats in JSON format for internal use in Product Opener and store a copy in the static web directory
Open a file, initialize a Text::CSV object, and output the CSV header for packaging components.
Export each packaging component of the product as one line in the CSV file.
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 (means etc.) for packaging materials, aggregated at the countries, categories and materials levels
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/