PHEASYKAL product database: how it is built
===========================================

The food products PHEASYKAL shows in food search and barcode lookups come from
Open Food Facts (https://world.openfoodfacts.org), a free and open database of food
products made by everyone.

The Open Food Facts database is available under the Open Database License (ODbL) 1.0:
https://opendatacommons.org/licenses/odbl/1-0/
Its individual contents are under the Database Contents License (DbCL) 1.0:
https://opendatacommons.org/licenses/dbcl/1-0/

Our product database (foods.db) is a derivative of the Open Food Facts
database, and is also available under the Open Database License (ODbL) 1.0.
These files are the complete method that builds it from the Open Food Facts
export (ODbL section 4.6 b): what is kept, what is left out, what is converted,
and the order the products are stored in. No other content is added.

You may run, copy and change these files to build and use the database.


How to build it
---------------
1. Download the Open Food Facts product export (tab-separated CSV, about 1 GB
   compressed). It is renewed every night:
   https://static.openfoodfacts.org/data/en.openfoodfacts.org.products.csv.gz

2. Run, with Python 3.9 or newer (nothing to install; Python's own sqlite3
   needs FTS5, which the standard Python downloads include):

   python build_foods.py en.openfoodfacts.org.products.csv.gz foods.db

   It takes a few minutes and writes an SQLite file of about 600 MB.
   The export changes every night, so the counts will differ a little from
   ours below.


What the files do
-----------------
services/food_import.py   reads the export and writes the database; the top
                          of the file lists what is kept and what is left out
services/food_keys.py     how names are written for search, and how barcodes
                          are keyed (UPC-A and EAN-13 of a product match)
build_foods.py            runs it from the command line


Our current copy
----------------
Built:      2026-10-28T22:27:22+00:00 (UTC) from en.openfoodfacts.org.products.csv
Settings:   --min-scans 0 (every product kept)
Rows read:  4,879,512
Products:   3,264,812
Left out:
      85,326  no usable barcode
     340,063  no name
   1,112,902  no calories, protein, carbs or fat
      29,260  impossible values (over 900 kcal, or over 100 g of a macro, per 100 g)
      47,115  calories far from what the macros add up to
          34  a barcode already listed (the best-ranked row is kept)


Open Food Facts is crowd-sourced: the data can contain errors and is not meant
for medical use. To fix a product, edit it on Open Food Facts itself, and the
fix reaches everyone.


בעברית
------
המוצרים שמופיעים ב־PHEASYKAL בחיפוש ובסריקת ברקוד מגיעים מ־Open Food Facts,
מאגר פתוח של מוצרי מזון שהציבור בונה. המאגר זמין לפי רישיון ODbL 1.0, וגם
העותק שלנו זמין לפי הרישיון הזה. הקבצים כאן הם הקוד שבונה את העותק שלנו
מהייצוא של Open Food Facts. מותר להריץ, להעתיק ולשנות אותם. ההוראות למעלה.
