Skip to content

Commit

Permalink
feat: add fruits-vegetables-nuts-estimate-from-ingredients to CSV exp…
Browse files Browse the repository at this point in the history
…ort (openfoodfacts#6013)

feat: add fruits-vegetables-nuts-estimate-from-ingredients to CSV export openfoodfacts#6004
  • Loading branch information
stephanegigandet authored Oct 21, 2021
1 parent a3d1a55 commit 8e986b5
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions scripts/export_database.pl
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ sub sanitize_field_content {
$csv .= "image_ingredients_url\timage_ingredients_small_url\t";
$csv .= "image_nutrition_url\timage_nutrition_small_url\t";

# Construct the list of nutrients to export

my @nutrients_to_export = ();

foreach my $nid (@{$nutriments_tables{"europe"}}) {

$nid =~ /^#/ and next;
Expand All @@ -239,6 +243,21 @@ sub sanitize_field_content {
$nid =~ s/^-//g;
$nid =~ s/-$//g;

push @nutrients_to_export, $nid;

if ($nid eq "fruits-vegetables-nuts-estimate") {

# Add the fruits-vegetables-nuts-estimate-from-ingredients nutrient
# which is computed from the ingredients list, and is not in the list
# of nutrients we display and allow users to edit

push @nutrients_to_export, "fruits-vegetables-nuts-estimate-from-ingredients";
}
}

# Output the headers for the nutrients

foreach my $nid (@nutrients_to_export) {
$csv .= "${nid}_100g" . "\t";
}

Expand Down Expand Up @@ -369,14 +388,7 @@ sub sanitize_field_content {
$csv .= ($product_ref->{image_nutrition_url} // "") . "\t" . ($product_ref->{image_nutrition_small_url} // "") . "\t";


foreach my $nid (@{$nutriments_tables{"europe"}}) {

#$nid =~/^#/ and next;
next if (substr($nid, 0, 1) eq '#');

$nid =~ s/!//g;
$nid =~ s/^-//g;
$nid =~ s/-$//g;
foreach my $nid (@nutrients_to_export) {

if (defined $product_ref->{nutriments}{$nid . "_100g"}) {
my $value = $product_ref->{nutriments}{$nid . "_100g"};
Expand Down

0 comments on commit 8e986b5

Please sign in to comment.