Open Food Facts and the Nutri-Score
Cleaning the Open Food Facts database in PostgreSQL, statistical analysis in R and a report in English about the Nutri-Score.
CompletedDatabaseIn pairs2024
Context
First-year BUT project, carried out in pairs from April 2 to 9, 2024 for SAÉ 2.04, “Working with a database”. It reproduced a small data science assignment at the crossroads of three subjects: databases, statistics and English. The scenario: two members of an association committed to open data want to inform consumers about the Nutri-Score.
The data came from Open Food Facts, an open database filled in by its contributors, so often incomplete and far richer than needed: more than 3 million rows, about 7 GiB. Each pair accessed it in PostgreSQL through a personal read-only view, with a specific question to address about the Nutri-Score of a product family.
Goals
- Extract from the database, with a psql script, a CSV file keeping only the useful, cleaned data.
- Present the selected variables, spot outliers, then produce at least five commented charts or tables in R.
- Write a study in English that analyzes these charts and answers the question.
- Frame the project: constraints, risks and how to keep them under control.
Implementation
Phase 1: exploration and cleaning
Since the IUT’s Linux workstations were in high demand, we worked on Windows,
going through TigerVNC on a Linux workstation to reach the PostgreSQL server.
SQL queries first explored the values of the useful fields, with LIMIT and
OFFSET to go through only a few rows at a time. Cleaning removed duplicates
and rows with impossible values, and checked barcodes and nutritional values.
Added fields made the analysis simpler: organic, vegan, and so on.
The selected data went through temporary tables before being exported to CSV. The psql script was due on April 4 at noon; once every script was in, the IUT shared one CSV file per topic for the rest of the project.
Phase 2: statistics
A few simple statistics first presented the selected variables and brought out the outliers. The charts and tables then answered the question, in the Nutri-Score colors. Everything was put together as a PDF with R Markdown.
Phase 3: report in English
The report followed precise guidelines: an introduction presenting the Nutri-Score, the products studied, the number of observations and the outline, then each chart introduced before being interpreted, and a short conclusion. The vocabulary had to match the type of chart: comparatives for bar charts, changes for line graphs, quartiles and outliers for boxplots.
Project management
Alongside that, the analysis of the brief listed the imposed constraints, sorted by type (time, human and material resources, technologies), then the risks they created. Each risk was rated by its criticality, impact times probability, placed in a matrix and given a preventive or corrective measure.
Results
In one week, the project went through the whole chain of a data study: from a raw database of several million rows to a report in English. It showed me how much the cleaning phase conditions everything else: without it, the charts tell of trends that do not exist.
My role
- All the work done together: psql exploration and cleaning script, statistics and charts in R, report in English and project framing.
Skills used
SAÉ 2.04 · Working with a database
Manage information data
Level 1 · Design and set up a database from a client's specification
- AC14.01 Update and query a relational database (directly or through an application)
- AC14.02 Visualize data
What I learned
- Exploring a table of several million rows with SQL queries, going through only part of it at a time with LIMIT and OFFSET.
- Cleaning open data entered by contributors: duplicates, impossible values, barcodes and nutritional values to check.
- Preparing a dataset for analysis: derived fields, temporary tables, CSV export from a psql script.
- Producing statistics and charts in R suited to a question, then a PDF report with R Markdown.
- Describing charts in English with the vocabulary of statistics: comparatives, quartiles, outliers.