ProductOpener::KnowledgePanels - Generate product knowledge panels that can be requested through the API
Apps can request through the API knowledge panels for one product. They are returned in the same structured format for all panels.
See https://docs.google.com/document/d/1vJ9gatmv8pCXxyOERmYD16jOKRWJpz1RaQQ5MEcTxms/edit
Initialize the options for knowledge panels from parameters.
Create all knowledge panels for a product, with strings (descriptions, recommendations etc.) in a specific language, and return them in an array of panels.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned panels contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
If $target_lc is equal to "data", no strings are returned.
Needed for some country specific panels like the Eco-Score.
Defines how some panels should be created (or not created)
- deactivate_[panel_id] : do not create a default panel -- currently unimplemented - activate_[panel_id] : create an on demand panel -- currently only for physical_activities panel
Contains the request parameters, including the API request parameters.
Panels are returned in the "knowledge_panels_[$target_lc]" hash of the product reference passed as input.
Helper function to allow to enter multiline strings in JSON templates. The function converts the multiline string into a single line string.
Creates a knowledge panel from a JSON template. The template is passed both the full product data + optional panel specific data. The template is thus responsible for all the display logic (what to display and how to display it).
Some special features that are not included in the JSON format are supported:
1. Relative links are converted to absolute links using the requested country / language subdomain
2. Multiline strings can be included using backticks ` at the start and end of the multiline strings. - The multiline strings will be converted to a single string. - Quotes " are automatically escaped unless they are already escaped
3. Comments can be included by starting a line with // - Comments will be removed in the resulting JSON, they are only intended to make the source template easier to understand.
4. Trailing commas are removed - For each loops in templates can result in trailing commas when separating items in a list with a comma (e.g. if want to generate a list of labels)
Relative path to the the template panel file, from the "/templates" directory. e.g. "api/knowledge-panels/environment/ecoscore/agribalyse.tt.json"
Used to pass data that is necessary for the panel but is not contained in the product data.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
The Eco-Score depends on the country of the consumer (as the transport bonus/malus depends on it)
The impact estimator adds a lot of data to products. This function extracts the data we need to display knowledge panels.
gen_top_tags_per_country.pl computes stats for categories for nutrients, and now also for the extended ecoscore impacts computed by the impact estimator.
For a specific product, this function finds the most specific category for which we have impact stats to compare with.
Creates a knowledge panel to describe the Eco-Score, including sub-panels for the different components of the Eco-Score.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
The Eco-Score depends on the country of the consumer (as the transport bonus/malus depends on it)
Creates a knowledge panel card that contains all knowledge panels related to the environment.
Created for all products (with at least a packaging panel).
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
The Eco-Score depends on the country of the consumer (as the transport bonus/malus depends on it)
Creates a knowledge panel card that contains all knowledge panels related to the circular economy: - sharing, buying, selling etc.
Created for products in specific categories, for users in specific countries.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Used to select secondhand options (e.g. classified ads sites) that are relevant for the user.
Creates a knowledge panel when we know the location of the manufacturing place, usually through a packaging code.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
The Eco-Score depends on the country of the consumer (as the transport bonus/malus depends on it)
Creates a knowledge panel card that contains all knowledge panels related to health.
This panel card is created for food, pet food, and beauty products.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
We may display country specific recommendations from health authorities, or country specific scores.
Creates knowledge panels to describe the Nutri-Score.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Creates knowledge panels for nutrient levels for fat, saturated fat, sugars and salt.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Creates a knowledge panel with the nutrition facts table.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Creates a knowledge panel with portion size.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Creates a knowledge panel to indicate how much time is needed to burn the calories of a product for various activities.
Description: https://en.wikipedia.org/wiki/Metabolic_equivalent_of_task
1 MET = (kJ / 4.2) / (kg * hour)
Data: https://sites.google.com/site/compendiumofphysicalactivities/
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Data: https://sites.google.com/site/compendiumofphysicalactivities/
Creates a knowledge panel with the list of ingredients.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Creates knowledge panels for additives.
Creates a knowledge panel with the results of ingredients analysis.
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
This function adds to the hash ref $object_ref (for instance a data structure passed to a template) the values of selected properties, if they exist in one of the target languages.
For instance for the panel for an additive, we can include a Wikipedia abstract in the requested language if available, or in English if not.
Properties to add to the resulting object.
Reference to an array of preferred languages, with the preferred language first.
Creates knowledge panels with recommendations (e.g. related to health or the environment). Recommendations can depend on product properties (e.g. categories or ingredients) and user properties (e.g. country and language to get country specific recommendations, but possibly also user preferences regarding trusted sources of information).
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.
Creates knowledge panels to describe the NOVA groups / processing / ultra-processing
Loaded from the MongoDB database, Storable files, or the OFF API.
Returned attributes contain both data and strings intended to be displayed to users. This parameter sets the desired language for the user facing strings.