Skip to content

Commit

Permalink
Merge branch 'main' into aleene-25-7
Browse files Browse the repository at this point in the history
  • Loading branch information
aleene committed Feb 17, 2025
2 parents 5c69587 + e57ad01 commit 908c3e1
Show file tree
Hide file tree
Showing 83 changed files with 5,107 additions and 400 deletions.
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,12 @@ Tags:
- any-glob-to-any-file: 'lib/ProductOpener/APITagRead.pm'
- any-glob-to-any-file: 'lib/ProductOpener/TagsEntries.pm'
- any-glob-to-any-file: 'lib/ProductOpener/KnowledgePanelsTags.pm'
- any-glob-to-any-file: 'docs/api/ref/schemas/product_tags.yaml'
- any-glob-to-any-file: 'docs/api/ref/schemas/tags/input_taxonomy_tag_entry.yaml'
- any-glob-to-any-file: 'docs/api/ref/schemas/tags/tags-write.yaml'
- any-glob-to-any-file: 'docs/api/ref/schemas/tags/tagtype.yaml'
- any-glob-to-any-file: 'docs/api/ref/schemas/tags/taxonomy_tag_entry.yaml'
- any-glob-to-any-file: 'po/tags/**/*'

Site layout:
- changed-files:
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt \
libemail-valid-perl
RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt \
--mount=type=cache,id=lib-apt-cache,target=/var/lib/apt set -x && \
# rerun apt update, because last RUN might be in cache
( ( [[ ! -e /var/cache/apt/pkgcache.bin ]] || [[ $(($(date +%s) - $(stat --format=%Y /var/cache/apt/pkgcache.bin))) -gt 3600 ]] ) && \
apt update || true \
) && \
apt install -y \
#
# cpan dependencies that can be satisfied by apt even if the package itself can't:
Expand Down Expand Up @@ -210,6 +214,10 @@ RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt \
--mount=type=cache,id=lib-apt-cache,target=/var/lib/apt \
--mount=type=cache,id=cpanm-cache,target=/root/.cpanm \
set -x && \
# also run apt update if needed because some package might need to apt install
( ( [[ ! -e /var/cache/apt/pkgcache.bin ]] || [[ $(($(date +%s) - $(stat --format=%Y /var/cache/apt/pkgcache.bin))) -gt 3600 ]] ) && \
apt update || true \
) && \
# first install some dependencies that are not well handled
cpanm --notest --quiet --skip-satisfied --local-lib /tmp/local/ "Apache::Bootstrap" && \
cpanm $CPANMOPTS --notest --quiet --skip-satisfied --local-lib /tmp/local/ --installdeps . \
Expand Down
11 changes: 11 additions & 0 deletions cgi/test_ingredients_analysis.pl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use ProductOpener::Ingredients
qw/clean_ingredients_text extract_additives_from_text extract_ingredients_from_text preparse_ingredients_text/;
use ProductOpener::Text qw/remove_tags_and_quote/;
use ProductOpener::EnvironmentalImpact qw/estimate_environmental_impact_service/;

use CGI qw/:cgi :form escapeHTML charset/;
use URI::Escape::XS;
Expand Down Expand Up @@ -85,6 +86,16 @@

my $json = JSON::MaybeXS->new->pretty->encode($product_ref->{ingredients});
$template_data_ref->{json} = $json;

# Environmental impact
my $errors_ref = [];
estimate_environmental_impact_service($product_ref, {}, $errors_ref);

$template_data_ref->{ecobalyse_request_json}
= JSON::MaybeXS->new->pretty->encode($product_ref->{environmental_impact}{ecobalyse_request} || {});
# If there was an error, we have ecobalyse_response, otherwise we have ecobalyse_response_data
$template_data_ref->{ecobalyse_response_json}
= JSON::MaybeXS->new->pretty->encode($product_ref->{environmental_impact} || {});
}

process_template('web/pages/test_ingredients/test_ingredients_analysis.tt.html', $template_data_ref, \$html)
Expand Down
3 changes: 3 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ requires 'Module::Load';
# To measure the time taken by requests
requires 'Time::Monotonic';

# To measure similarity between words and find possible typo
requires 'Text::Levenshtein';

on 'test' => sub {
requires 'Test2::V0';
requires 'Mock::Quick';
Expand Down
21 changes: 11 additions & 10 deletions docs/dev/how-to-quick-start-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Docker provides an isolated environment, very close to a Virtual Machine. This e
> **_NOTE:_** New to Perl? Check [how to learn perl](how-to-learn-perl.md)!
**Installation steps:**
- GIT version >= 2.25.0
- [Install Docker CE](https://docs.docker.com/engine/install/)
> If you run e.g. Debian, don't forget to add your user to the `docker` group!
Expand All @@ -41,9 +42,9 @@ Make sure you also activated the [Developer mode](https://learn.microsoft.com/en

### Windows Subsystem for Linux (WSL) Prerequisites

Ensure that you have WSL installed on your Windows machine. For instructions on how to do so, you can follow [Microsoft's guide to install WSL](https://learn.microsoft.com/en-us/windows/wsl/install).
Ensure that you have WSL installed on your Windows machine. For instructions on how to do so, you can follow [Microsoft's guide to install WSL](https://learn.microsoft.com/en-us/windows/wsl/install).

After succcessfully installing WSL, you need to set up your Linux distribution and install Docker on it:
After succcessfully installing WSL, you need to set up your Linux distribution and install Docker on it:
- Go to the Microsoft Store and install [Ubuntu](https://www.microsoft.com/store/productId/9PDXGNCFSCZV?ocid=pdpshare) as your Linux distribution
- Open Ubuntu and execute the commands/instructions specified in [Installing Docker Engine on Ubuntu](https://docs.docker.com/engine/install/ubuntu/) (**NOTE: this is NOT the same thing as Docker for Desktop)
- Restart your computer to ensure all changes take effect and WSL can properly integrate with Docker
Expand All @@ -60,7 +61,7 @@ If you use Docker Desktop:

> _You must have a GitHub account and fork the project if you want to contribute to Open Food Facts development, but it’s not required if you just want to see how it works._
> _Cloning Open Food Facts server with the default options downloads 2.23 GiB (as of 2024-03). See [Shallow Clone](#shallow-clone) if this might be a problem for you._
> _Cloning Open Food Facts server with the default options downloads 2.23 GiB (as of 2024-03). See [Shallow Clone](#shallow-clone) if this might be a problem for you._
### Fork the repository

Expand Down Expand Up @@ -184,7 +185,7 @@ make dev
```

> **Note:**
>
>
> If you are using Windows, you may encounter issues regarding this command. Take a look at the **Troubleshooting** section further in this tutorial.
> **Note:**
Expand Down Expand Up @@ -246,7 +247,7 @@ When running `make dev`:
bash: make: command not found
```

**Solution (if using Windows):**
**Solution (if using Windows):**
Click the Windows button, then type “environment properties” into the search bar and hit Enter. Click Environment Variables, then under System variables choose Path and click Edit. Click New and insert C:\Program Files (x86)\GnuWin32\bin, then save the changes. Open a new terminal and test that the command works.
(See [Make Windows](https://pakstech.com/blog/make-windows/) for more.)

Expand Down Expand Up @@ -306,7 +307,7 @@ When running `make dev`:
docker compose --env-file=.env build 2>&1
open /.docker/buildx/current: permission denied
make: *** [build] Error 1
openfoodfacts-server %
openfoodfacts-server %
```

**Solution:**
Expand All @@ -318,7 +319,7 @@ If there is a file that is not owned by user with root instead of USER:
```console
-rw------- 1 root staff 48 Apr 28 17:04 current
```
Then Run
Then Run
```console
sudo chown -R USER:USER /Users/USER/.docker/buildx
```
Expand All @@ -343,7 +344,7 @@ make (e=2): The system cannot find the file specified.

You need to install [wget for windows](https://eternallybored.org/misc/wget/). The referenced version is able to use the Windows Certificate Store, whereas the standard [gnuwin32 version](https://gnuwin32.sourceforge.net/packages/wget.htm) will give errors about not being able to verify the server certificate.

### make: *** [Makefile:154: import_sample_data] Error 22
### make: *** [Makefile:154: import_sample_data] Error 22

When running `make import_sample_data`

Expand All @@ -367,7 +368,7 @@ make: *** [Makefile:154: import_sample data] Error 22
```

**Solution:**
The cause of this issue is that you already have the mongodb database server running on your local machine at port 27017.
The cause of this issue is that you already have the mongodb database server running on your local machine at port 27017.

*For Linux users:*

Expand All @@ -386,7 +387,7 @@ systemctl status mongod | grep Active

Then, execute this:
```console
docker compose up
docker compose up
```
> **Note:**
> To know more about docker compose commands do read [this guide](how-to-develop-using-docker.md)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lib/ProductOpener/APIProductServices.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Currently implemented services:
- extend_ingredients : extend the ingredients object with additional information
- estimate_ingredients_percent : compute percent_min, percent_max, percent_estimate for each ingredient in the ingredients object
- analyze_ingredients : analyze the ingredients object and return a summary object
- estimate_environmental_cost_ingredients : estimate the environmental cost of a given product (see Ecobalyse)
=head4 product
Expand Down Expand Up @@ -90,6 +91,7 @@ use ProductOpener::Users qw/:all/;
use ProductOpener::Lang qw/:all/;
use ProductOpener::Products qw/:all/;
use ProductOpener::API qw/add_error customize_response_for_product/;
use ProductOpener::EnvironmentalImpact;

use Encode;

Expand All @@ -116,6 +118,7 @@ my %service_functions = (
extend_ingredients => \&ProductOpener::Ingredients::extend_ingredients_service,
estimate_ingredients_percent => \&ProductOpener::Ingredients::estimate_ingredients_percent_service,
analyze_ingredients => \&ProductOpener::Ingredients::analyze_ingredients_service,
estimate_environmental_impact => \&ProductOpener::EnvironmentalImpact::estimate_environmental_impact_service,
determine_food_contact_of_packaging_components =>
\&ProductOpener::PackagingFoodContact::determine_food_contact_of_packaging_components_service,
);
Expand Down
4 changes: 4 additions & 0 deletions lib/ProductOpener/Attributes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1206,6 +1206,7 @@ sub compute_attribute_nutrient_level ($product_ref, $target_lc, $level, $nid) {
lang_in_other_lc($target_lc, "unknown_quantity")
);
$attribute_ref->{missing} = lang_in_other_lc($target_lc, "missing_nutrition_facts");
$attribute_ref->{panel_id} = "nutrition_facts_table";
}
}
else {
Expand Down Expand Up @@ -1262,6 +1263,9 @@ sub compute_attribute_nutrient_level ($product_ref, $target_lc, $level, $nid) {
$attribute_ref->{description_short}
= sprintf(lang_in_other_lc($target_lc, 'g_per_100g'), (sprintf('%.2e', $value) + 0.0));
}

$attribute_ref->{panel_id} = "nutrient_level_" . $nid;
$attribute_ref->{panel_id} =~ s/-/_/g;
}
}
}
Expand Down
Loading

0 comments on commit 908c3e1

Please sign in to comment.