<<

NAME

ProductOpener::Stats - Compute stats for categories (nutrients, etc.)

DESCRIPTION

This module provides functions to compute and load stats for categories (nutrients, etc.)

FUNCTIONS

add_product_value_to_stats ($values_ref, $key, $value)

This build a collection ($value_ref) were for each nutrients (or other numeric attribute), $key, we store the accumulate values for that nutrient (s), number of instances <n> and each values array).

We will then pass $values_ref to compute_stats_for_products.

compute_stats_for_products ($stats_ref, $values_ref, $count, $n, $min_products, $id)

Arguments

Stats reference $stats_ref

Where we will store the stats.

Values reference $values_ref

Values for some nutrients (or other numeric values), with accumulated values and number of products considered (it is different from $n as some products might not have a value). See add_product_value_to_stats

Total number of products $count

Including products that have no values for the nutrients we are interested in.

Number of products with defined values for specified nutrients $n

Minimum number of products needed to compute stats $min_products

ID $id

E.g. category ID.

load_categories_stats_per_country ($force_reload = 0)

Loads nutrient stats for all categories and countries. If the data is already loaded, it does not reload it unless $force_reload is true.

The stats are displayed on category pages and used in product pages, as well as in data quality checks and improvement opportunity detection.

In integration tests, there are no stats in the data directory, and it is difficult to generate them on the fly as we need to stop and start Apache after to load them, which is complex in the test framework with Docker.

So instead we load them from the test data directory.

<<