diff --git a/.github/workflows/food-data.yml b/.github/workflows/food-data.yml index 217af21..be33a1a 100644 --- a/.github/workflows/food-data.yml +++ b/.github/workflows/food-data.yml @@ -2,8 +2,8 @@ name: Food data # Imports into GRIT's food database (packages/food-data). Runs by hand for # full imports (USDA after each release, twice a year; Open Food Facts; -# CoFID), and daily for Open Food Facts' changes to products already in the -# database. Needs the DIRECT_URL repository secret: a session-mode +# the national tables: CoFID, CNF, CIQUAL, Fineli), and daily for Open Food +# Facts' changes to products already in the database. Needs the DIRECT_URL repository secret: a session-mode # connection, not Supabase's transaction pooler on port 6543 (see the # package README). Without it, the workflow does nothing. @@ -13,7 +13,7 @@ on: source: description: What to import type: choice - options: [off-delta, fdc, off, cofid] + options: [off-delta, fdc, off, cofid, cnf, ciqual, fineli] default: off-delta options: description: 'Options, e.g. "--dataset foundation,sr,fndds --full", "--min-scans 5 --countries gb,us", "--only-existing", "--dry-run"' diff --git a/README.md b/README.md index 18bddc9..df0c99a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ grit/ │ └── mobile/ # Expo (React Native) app └── packages/ ├── backend/ # NestJS REST API - └── food-data/ # Importers for GRIT's food database (USDA, Open Food Facts, UK CoFID) + └── food-data/ # Importers for GRIT's food database (USDA, Open Food Facts, national tables) ``` --- @@ -245,7 +245,7 @@ A cloud instance can't run a simulator. Use it for type-checking and linting, or ### Food data -GRIT's food database is filled by the importers in [`packages/food-data`](./packages/food-data/README.md): USDA FoodData Central (public domain), Open Food Facts (ODbL) and the UK's CoFID (Open Government Licence). Each is idempotent, so a re-run changes nothing. The [Food data workflow](./.github/workflows/food-data.yml) runs them against the database in the `DIRECT_URL` repository secret: by hand for full imports, and daily for Open Food Facts' changes. Sources are credited in the app under Profile → Food data sources. +GRIT's food database is filled by the importers in [`packages/food-data`](./packages/food-data/README.md): USDA FoodData Central (public domain), Open Food Facts (ODbL) and the national tables of the UK (CoFID, Open Government Licence), Canada (CNF, OGL – Canada), France (CIQUAL, Licence Ouverte) and Finland (Fineli, CC BY 4.0). Each is idempotent, so a re-run changes nothing. The [Food data workflow](./.github/workflows/food-data.yml) runs them against the database in the `DIRECT_URL` repository secret: by hand for full imports, and daily for Open Food Facts' changes. Sources are credited in the app under Profile → Food data sources. --- diff --git a/apps/mobile/lib/foodSources.ts b/apps/mobile/lib/foodSources.ts index ed24378..4b48a4f 100644 --- a/apps/mobile/lib/foodSources.ts +++ b/apps/mobile/lib/foodSources.ts @@ -4,7 +4,7 @@ * Nutrients screen. Edit the wording here. */ export interface FoodSource { - /** The `source` code foods carry (fdc, off, cofid) */ + /** The `source` code foods carry (fdc, off, cofid, cnf, ciqual, fineli) */ code: string; name: string; /** Who publishes it, or the attribution the licence asks for */ @@ -39,8 +39,28 @@ export const FOOD_SOURCES: FoodSource[] = [ licence: 'Open Government Licence v3.0', url: 'https://www.gov.uk/government/publications/composition-of-foods-integrated-dataset-cofid', }, - // Canada's CNF, France's CIQUAL and Finland's Fineli join this list when - // they're imported (see docs/ROADMAP.md, Phase 7) + { + code: 'cnf', + name: 'Canadian Nutrient File', + credit: 'Canadian Nutrient File 2015, Health Canada.', + notice: 'Contains information licensed under the Open Government Licence – Canada.', + licence: 'Open Government Licence – Canada', + url: 'https://www.canada.ca/en/health-canada/services/food-nutrition/healthy-eating/nutrient-data.html', + }, + { + code: 'ciqual', + name: 'ANSES-CIQUAL', + credit: 'ANSES-CIQUAL French food composition table, 2025 version (Anses), last updated 19 November 2025.', + licence: 'Licence Ouverte / Open Licence 2.0 (Etalab)', + url: 'https://ciqual.anses.fr', + }, + { + code: 'fineli', + name: 'Fineli', + credit: 'Finnish Institute for Health and Welfare (THL), Fineli, the Finnish food composition database, release 20.', + licence: 'Creative Commons Attribution 4.0 (CC BY 4.0)', + url: 'https://fineli.fi', + }, ]; /** "fdc.nal.usda.gov" from a source's URL, for its link text. */ diff --git a/docs/PLAN_PHASES_5_TO_9.md b/docs/PLAN_PHASES_5_TO_9.md index 88ccd13..00f6b0a 100644 --- a/docs/PLAN_PHASES_5_TO_9.md +++ b/docs/PLAN_PHASES_5_TO_9.md @@ -438,9 +438,14 @@ with these differences: - **Size:** the full Open Food Facts and USDA branded imports would take 12–14 GB as stored, well over the 2–4 GB estimated here. They aren't imported yet (see ROADMAP). -- **National tables:** the UK's CoFID is imported. Canada's, France's and - Finland's sites couldn't be downloaded from a server, so those wait for - the files. +- **National tables:** the UK's CoFID, Canada's CNF 2015, France's + CIQUAL 2025 and Finland's Fineli (release 20) are imported, with their + other-language names. Health Canada's and Fineli's sites refuse servers, + so those two release files are kept in the repository and checked by + SHA-256; CIQUAL comes from Recherche Data Gouv, where ANSES deposits it. +- **Search** scores a food on each of its names, so a French table's food + found by its French name ranks like a product named exactly that, and + shows one result per name and brand before its limit. - **Smart log** matches unbranded items to measured foods and branded items to branded foods first, and only when the calories agree with the reading. Branded before measured, for branded items, keeps "Fage yogurt" @@ -566,7 +571,7 @@ duplicating them. | USDA FoodData Central: Branded | ~400k US products, label nutrients | Public domain | | Open Food Facts | ~3M products from about 150 countries, names in many languages | **ODbL** (decision 3) | | UK CoFID | UK foods | Open Government Licence | -| Canada CNF, France CIQUAL, Finland Fineli | National foods | Open licences; confirm each | +| Canada CNF, France CIQUAL, Finland Fineli | National foods | OGL – Canada; Licence Ouverte 2.0; CC BY 4.0 | - **Size:** filtered Open Food Facts plus everything else is roughly 2–4 GB. Only products with a name and calories are imported, using bulk `COPY` into diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 75e2465..5bad2dc 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -229,7 +229,12 @@ writing is on. - Open Food Facts: the full export, or a filtered one, and a daily job for its changes. Only label values are kept; OFF's own estimates from ingredients are left out; - - the UK's CoFID (2,854 foods); + - the national tables of the UK (CoFID, 2,854 foods), Canada (CNF 2015, + 5,690), France (CIQUAL 2025, 3,341) and Finland (Fineli, 4,231), with + their French, Finnish and Swedish names, so "ruisleipä" finds rye + bread. Health Canada's and Fineli's sites refuse servers, so their + release files are kept in the repository (`packages/food-data/data`); + CIQUAL comes from Recherche Data Gouv; - the same product from two sources is one food, showing the better source (government tables, then manufacturers, then Open Food Facts). - **Search** runs on GRIT's own data: @@ -240,7 +245,9 @@ writing is on. scanned (the "core") are always searched in full; the millions of other products are sampled, so common words stay fast; - ranked by the user's own foods (logged, favourite, remembered), then - their country's, how closely the name matches, quality and popularity; + their country's, how closely any of a food's names matches, quality + and popularity, with one result per name and brand (so 60 products + called "Baguette" don't hide the French table's baguette); - results show the typical serving and a "Verified" label for government and manufacturer data; - p95 of 131 ms on 3.4 million foods, locally with the full Open Food @@ -273,8 +280,8 @@ writing is on. **After deploying Phase 7:** apply the migration to Supabase. Add the `DIRECT_URL` repository secret (Supabase's session pooler, port 5432), then -run the Food data workflow for `fdc` and `cofid`. Together they take about -90 MB, within the Free plan. Until then search falls back to Open Food +run the Food data workflow for `fdc`, `cofid`, `cnf`, `ciqual` and +`fineli`. Together they take about 170 MB, within the Free plan. Until then search falls back to Open Food Facts live, and only scanned products carry micronutrients. The daily job then keeps saved Open Food Facts products up to date. Deploy the backend before the app: the app sends new fields that older backends reject. @@ -289,9 +296,6 @@ before the app: the app sends new fields that older backends reject. first searches after a database restart time out (2.5 s) until its cache warms up (seen locally on 3.4 million foods); they fall back to the live search meanwhile. -- Canada's CNF, France's CIQUAL and Finland's Fineli: their sites couldn't - be downloaded from the server (no response, maintenance, a bot check), so - their importers wait for the files. - Open Food Facts' licence (ODbL) review by a lawyer (decision 3): the barcode lookup already saves the products it finds, and every saved row is marked with its source, so they can all be removed in one step. @@ -355,9 +359,11 @@ Ordered from easiest to hardest, each phase is released on its own: - Food database (Phase 7): - add the `DIRECT_URL` repository secret in GitHub (Supabase → Connect → Session pooler, port 5432, with the database password), then run the - Food data workflow for `fdc` and then `cofid`; + Food data workflow for `fdc`, then `cofid`, `cnf`, `ciqual` and + `fineli`; - decide on Supabase Pro and filters before importing all of Open Food Facts and USDA's branded products (12–14 GB as stored now); - have a lawyer review the Open Food Facts licence (decision 3); - - download Canada's CNF, France's CIQUAL and Finland's Fineli files in a - browser (their sites block servers) so their importers can be built. + - when Health Canada publishes CNF 2026, or Fineli a new release, + download it in a browser and replace the file in + `packages/food-data/data` (their sites block servers). diff --git a/docs/TRUST_AND_SAFETY.md b/docs/TRUST_AND_SAFETY.md index bb380da..341bee8 100644 --- a/docs/TRUST_AND_SAFETY.md +++ b/docs/TRUST_AND_SAFETY.md @@ -244,5 +244,9 @@ completed with a lawyer.* - **UK CoFID (Open Government Licence v3.0)**, imported with the required statement in the app. - **USDA FoodData Central** is public domain; credited as a courtesy. - - **Canada's CNF (OGL – Canada), France's CIQUAL (Licence Ouverte) and - Finland's Fineli (CC BY 4.0):** confirm each before they're imported. + - **Canada's CNF (Open Government Licence – Canada), France's CIQUAL + (Licence Ouverte / Open Licence 2.0) and Finland's Fineli (CC BY + 4.0):** open licences that allow commercial use and redistribution + with attribution, given in the app with the wording each asks for + (CIQUAL's includes the date it was last updated). CNF's and Fineli's + release files are kept unchanged in the repository. diff --git a/packages/backend/src/food/food-db.db-spec.ts b/packages/backend/src/food/food-db.db-spec.ts index a33be9c..9053158 100644 --- a/packages/backend/src/food/food-db.db-spec.ts +++ b/packages/backend/src/food/food-db.db-spec.ts @@ -31,6 +31,7 @@ async function seed( servings?: { label: string; grams: number; typical?: boolean }[]; extra?: Record; basis?: string; + names?: { name: string; lang: string }[]; } = {}, ) { const nutrients = { @@ -51,7 +52,12 @@ async function seed( quality: over.quality ?? 1, popularity: over.popularity ?? 0, verified: over.verified ?? true, - searchText: searchTextOf(name, over.brand), + searchText: searchTextOf( + name, + over.brand, + over.names?.map((n) => n.name), + ), + names: over.names ? { create: over.names } : undefined, barcodes: over.barcode ? { create: { code: over.barcode } } : undefined, servings: over.servings ? { create: over.servings } : undefined, nutrients: { @@ -227,6 +233,55 @@ describe('food database search', () => { }); }); +describe('search across many products and languages', () => { + it('shows one product per name and brand, so other foods still fit', async () => { + // 60 products with one name would fill every place before + for (let i = 0; i < 60; i++) { + await seed(`test_quib_${i}`, 'Quibbet', { + kind: 'branded', + source: 'off', + countries: ['fr'], + quality: 0.6, + verified: false, + basis: 'label', + }); + } + await seed('test_quib_ciqual', 'Bread, French bread, quibbet', { + source: 'ciqual', + countries: ['fr'], + }); + const results = await foodDb.search('quibbet', { country: 'FR' }); + expect(results.filter((r) => r.name === 'Quibbet')).toHaveLength(1); + expect(results.map((r) => r.foodId)).toContain('test_quib_ciqual'); + }); + + it("ranks a food by its name in the user's language too", async () => { + await seed('test_zorp_ciqual', 'Chocolate zorpleck, from bakery', { + source: 'ciqual', + countries: ['fr'], + names: [{ name: 'Zorpleck au chocolat, artisanal', lang: 'fr' }], + }); + // A product named exactly what's typed + await seed('test_zorp_off', 'Zorpleck au chocolat', { + kind: 'branded', + source: 'off', + countries: ['fr'], + quality: 0.6, + verified: false, + basis: 'label', + }); + const results = await foodDb.search('zorpleck au chocolat', { + country: 'FR', + }); + // The French table's food, found by its French name, leads (a near + // miss search adds real products after these two) + expect(results.slice(0, 2).map((r) => r.foodId)).toEqual([ + 'test_zorp_ciqual', + 'test_zorp_off', + ]); + }); +}); + describe('barcodes and single foods', () => { it('finds a barcode however it was written', async () => { for (const code of ['099999888775', '0099999888775', '00099999888775']) { diff --git a/packages/backend/src/food/food-db.service.ts b/packages/backend/src/food/food-db.service.ts index 4c698fe..10e4a3e 100644 --- a/packages/backend/src/food/food-db.service.ts +++ b/packages/backend/src/food/food-db.service.ts @@ -230,22 +230,44 @@ export class FoodDbService { SELECT h.id, h.id IN (SELECT "foodId" FROM mine) AS mine, extensions.word_similarity(${key}, h."searchText") AS wsim, - extensions.similarity(${key}, h."searchText") AS sim, - h."searchText" LIKE ${key + '%'} AS prefix, + -- The search text joins every name ("chocolate croissant … pain + -- au chocolat"), so a food also scores on each name of its own + GREATEST( + extensions.similarity(${key}, h."searchText"), + (SELECT max(extensions.similarity(${key}, lower(n.name))) + FROM food_names n WHERE n."foodId" = h.id) + ) AS sim, + (h."searchText" LIKE ${key + '%'} OR EXISTS ( + SELECT 1 FROM food_names n + WHERE n."foodId" = h.id AND lower(n.name) LIKE ${key + '%'} + )) AS prefix, ${country} = ANY(h.countries) AS local, - h.kind, h.quality, h.popularity, h.verified + h.kind, h.quality, h.popularity, h.verified, + lower(h.name) AS name, lower(coalesce(h.brand, '')) AS brand FROM cand c JOIN foods h ON h.id = c.id + ), + ranked AS ( + SELECT id, mine, wsim, name, brand, + ((CASE WHEN mine THEN 1.0 ELSE 0 END) + + (CASE WHEN local THEN 0.25 ELSE 0 END) + + 0.5 * sim + 0.2 * wsim + + (CASE WHEN prefix THEN 0.3 ELSE 0 END) + + (CASE WHEN kind = 'generic' THEN 0.05 ELSE 0 END) + + (CASE WHEN verified THEN 0.2 ELSE 0 END) + + 0.5 * quality + + 0.1 * least(1.0, ln(1 + popularity) / ln(101))) AS score + FROM scored + ), + -- One food per name and brand before the limit: dozens of products + -- called "Baguette" would otherwise fill it, and the national + -- table's baguette would never be seen + best AS ( + SELECT DISTINCT ON (name, brand) id, mine, wsim, score + FROM ranked + ORDER BY name, brand, score DESC, id ) - SELECT id, mine, wsim::float8 AS wsim, - ((CASE WHEN mine THEN 1.0 ELSE 0 END) - + (CASE WHEN local THEN 0.25 ELSE 0 END) - + 0.5 * sim + 0.2 * wsim - + (CASE WHEN prefix THEN 0.3 ELSE 0 END) - + (CASE WHEN kind = 'generic' THEN 0.05 ELSE 0 END) - + (CASE WHEN verified THEN 0.2 ELSE 0 END) - + 0.5 * quality - + 0.1 * least(1.0, ln(1 + popularity) / ln(101)))::float8 AS score - FROM scored + SELECT id, mine, wsim::float8 AS wsim, score::float8 AS score + FROM best ORDER BY score DESC, id LIMIT ${limit * 2}`; diff --git a/packages/food-data/README.md b/packages/food-data/README.md index c853614..8cccf80 100644 --- a/packages/food-data/README.md +++ b/packages/food-data/README.md @@ -1,7 +1,8 @@ # food-data Importers for GRIT's own food database (plan Phase 7.1): USDA FoodData -Central, Open Food Facts and the UK's CoFID, written into the `foods`, +Central, Open Food Facts and four national food tables (the UK's CoFID, +Canada's CNF, France's CIQUAL and Finland's Fineli), written into the `foods`, `food_nutrients`, `food_servings`, `food_barcodes`, `food_names` and `food_sources` tables that the backend's migrations create. Values are per 100 g in the 28 nutrient codes of `packages/backend/src/food/nutrients.ts`. @@ -21,10 +22,12 @@ npm run import -w packages/food-data -- --help | `off` | the JSONL export (default, streamed: about 13 GB gzip) or `--file` the CSV export | the OFF code, as OFF writes it | **ODbL** (database), DbCL (contents), CC BY-SA (images) | | `off-delta` | OFF's daily delta files (JSONL), since the last import | the OFF code | ODbL | | `cofid` | McCance and Widdowson's CoFID 2021 workbook (checked by SHA-256) | the food code (`13-669~` for the one code used twice) | Open Government Licence v3.0 | +| `cnf` | the Canadian Nutrient File 2015 CSV zip, kept in `data/` (checked by SHA-256) | the FoodID | Open Government Licence – Canada | +| `ciqual` | the ANSES-CIQUAL 2025 XML files from Recherche Data Gouv (checked by SHA-256) | the food code (`alim_code`) | Licence Ouverte / Etalab 2.0 | +| `fineli` | Fineli release 20, basic package 2 zip, kept in `data/` (checked by SHA-256) | the FOODID | CC BY 4.0 | -CNF (Canada), CIQUAL (France) and Fineli (Finland) aren't written yet: their -files couldn't be downloaded here, and the importers will be built from the -real files. +Health Canada's and Fineli's sites refuse servers, so their releases are +kept in [`data/`](data/README.md), as downloaded in a browser. ### USDA FoodData Central @@ -111,12 +114,81 @@ real files. verified, quality 1, no servings (CoFID has no portions), `fetchedAt` the release date (2021-03-19). +### Canada's CNF + +- The Canadian Nutrient File 2015 (the latest; Health Canada is preparing a + 2026 edition). Relational CSV files in Latin-1: `FOOD NAME`, `NUTRIENT +AMOUNT`, `CONVERSION FACTOR`, `MEASURE NAME` and `FOOD GROUP` are read; + the release's update files aren't needed. +- Nutrients by `NutrientID` (not `NutrientCode`, which differs for newer + ones: RAE is ID 814, code 320): energy 208, else kJ (268) / 4.184; carbs + by difference (205, including fibre like USDA's; slightly negative values + clamped to 0); vitamin A as RAE (814); vitamin D in µg (339), else IU + (324) × 0.025; vitamin E α-tocopherol (323); niacin preformed (406); + folate as DFE (815), else total folacin (417); caffeine (262). +- Servings are CNF's measures as multiples of 100 g: "250ml chopped or + diced" becomes "250 ml, chopped or diced". A weight alone ("85g", Canada's + serving of meat) becomes "1 serving" when CNF has none of its own, and + 100 g is left out. Typical: CNF's own "1 serving", else the first "1 + " (a slice, a waffle), else that weight, else the first measure other + than 100 ml. Measures the release has no name for are skipped. +- 5,690 foods, all with energy. Country `ca`, the French name as another + name, the food group as the category, kind `dish` for Mixed Dishes and + Fast Foods, else `generic`; measured, verified, quality 1, `fetchedAt` the + newest values in the release (2015-10-30). + +### France's CIQUAL + +- The ANSES-CIQUAL table 2025 (published 19 November 2025), downloaded from + [Recherche Data Gouv](https://entrepot.recherche.data.gouv.fr/dataset.xhtml?persistentId=doi%3A10.57745%2FRDMHWY), + where ANSES deposits it (Ciqual's own site is often down for maintenance). + `alim`, `alim_grp` and `compo` are read: flat XML, streamed, so the 69 MB + `compo` file is never in memory at once. `--dir` or `--file` takes a + folder or zip of the XML files instead. +- Values use a decimal comma; "traces" is 0; "-" and "< 0,5" (below what the + lab could measure) are missing, never zero. +- Energy by EU Regulation 1169/2011 (328 kcal, as labels), else N × Jones' + factor (333), else kJ / 4.184; carbs are available carbohydrate (31000, + excluding fibre, like CoFID's); sodium (10110), else salt (10004) × 400; + vitamin A as RAE (51104), else retinol + β-carotene / 12; vitamin E + α-tocopherol (71010), else vitamin E (53100); vitamin K1 (54101); folate as + DFE (56702), else total (56700). +- 3,484 foods, 3,341 with energy. Country `fr`, the French name as another + name, the subgroup as the category, kind `dish` for starters and dishes + (group 01), else `generic`; no servings (CIQUAL has no portions); + measured, verified, quality 1. + +### Finland's Fineli + +- Fineli release 20, basic package 2 (74 components; the latest release). + Semicolon-separated Latin-1 files with CRLF line ends and decimal commas: + `food`, `foodname_EN`/`FI`/`SV`, `component_value`, `foodaddunit` and + `fuclass_EN`. +- Names are in capitals in the release and written in sentence case + ("RYE BREAD, 51% RYE" → "Rye bread, 51% rye"); the Finnish and Swedish + names are other names, so "ruisleipä" finds rye bread. +- Energy is in kJ only (/ 4.184); carbs are available carbohydrate + (`CHOAVL`, excluding fibre); fibre `FIBC`; sodium `NA`, else salt (`NACL`, + in mg) × 0.4; vitamin A as RAE (`VITA`); niacin preformed (`NIA`); folate + total (Fineli has no DFE). No caffeine in this package. +- Servings from Fineli's units: the product's own piece ("1 piece, as + sold"), small/medium/large pieces and portions, dl, tbsp and tsp (kg, l + and the "1000 kJ portion" aren't portions). Typical: the product's piece, + else a medium piece, else a medium portion. +- Fineli's `DISH` type means "made from a recipe" (breads and porridges + too), so kind is `dish` only for recipes in a mixed-dish use class (meat, + fish, egg, pulse, potato and vegetable dishes, soups, pizza, sandwiches, + mixed salads), else `generic`. The one dietary supplement is left out. +- 4,237 foods, 4,231 with energy. Country `fi`, the use class as the + category; measured, verified, quality 1, `fetchedAt` the release's file + date (2019-08-08). + ## Options | Option | | | ---------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `--file ` | a local file instead of downloading (repeatable for `fdc`; the dataset is told by USDA's file name) | -| `--dir ` | a folder of local files: USDA's or CoFID's files by name, or OFF delta files | +| `--dir ` | a folder of local files: USDA's or CoFID's files by name, OFF delta files, or an extracted CNF, CIQUAL or Fineli release | | `--dataset ` | `fdc`: `foundation,sr,fndds,branded` (default `foundation,sr,fndds`) | | `--limit ` | stop after n records: a sample | | `--dry-run` | run everything in transactions that are rolled back, and report what would change | @@ -173,6 +245,9 @@ of the six food tables, indexes included; per dataset from the per-row sizes): | `fdc` Foundation + SR Legacy | 7,970 | 198,085 | ≈ 42 MB | 10 s / 9 s | | `fdc` FNDDS | 5,431 | 152,063 | ≈ 35 MB | 7 s / 6 s | | `cofid` | 2,854 | 69,073 | ≈ 13 MB | 5 s / 5 s | +| `cnf` | 5,690 | 148,430 | ≈ 34 MB | 13 s / 8 s | +| `ciqual` | 3,341 | 66,419 | ≈ 14 MB | 5 s / 4 s | +| `fineli` | 4,231 | 113,795 | ≈ 28 MB | 10 s / 6 s | | `fdc --dataset branded --limit 5000` (sample) | 4,941 | 51,244 | ≈ 15 MB | 76 s / 77 s (70 s of it is the pass over the whole file) | | `off --file products.csv.gz --min-scans 20` (sample) | 27,111 | 226,565 | ≈ 70 MB | 2.5 min to read all 4.9M rows | | **All food tables** | 48,307 | 697,030 | **167 MB** | | @@ -180,8 +255,8 @@ of the six food tables, indexes included; per dataset from the per-row sizes): Per row: about 156 bytes per nutrient value, 650 per food, 275 per serving, 260 per source and 160 per barcode. So: -- **USDA generic foods + CoFID (about 16k foods, 90 MB) fit Supabase Free - (500 MB)** next to the app's own data. +- **USDA generic foods and the four national tables (about 30k foods, + 170 MB) fit Supabase Free (500 MB)** next to the app's own data. - **USDA Branded** in full: about 1.6M products (2.0M rows, 390k of them older versions) at about 3 KB each: **4–5 GB**. - **Open Food Facts** in full: 2.7–3.7M products with a name and calories @@ -206,6 +281,14 @@ branded`), then the same with `--full` to remove foods USDA dropped. The Action can run them by hand (Actions → Food data → Run workflow). - **CoFID**: when gov.uk publishes a new edition (none since 2021); update `COFID_URL` and `COFID_SHA256` in `src/sources/cofid.ts`. +- **CNF and Fineli**: when a new edition comes out (Health Canada is + preparing CNF 2026), download it in a browser and replace the file in + `data/` (see [its README](data/README.md)). +- **CIQUAL**: when ANSES publishes a new table, update the file ids and + SHA-256 in `CIQUAL_FILES` (`src/sources/ciqual.ts`). + +After a national table's new edition, run it with `--full` to remove foods +it no longer lists. The Action needs a `DIRECT_URL` repository secret (Settings → Secrets and variables → Actions); without it, it succeeds with a notice and imports @@ -229,8 +312,17 @@ nothing. - **CoFID**: "Contains public sector information licensed under the Open Government Licence v3.0. Source: Public Health England (2021) McCance and Widdowson's The Composition of Foods Integrated Dataset." -- National tables to come (CNF, CIQUAL, Fineli): open licences, each to be - confirmed. +- **CNF**: Open Government Licence – Canada. "Contains information + licensed under the Open Government Licence – Canada. Source: Canadian + Nutrient File 2015, Health Canada." +- **CIQUAL**: Licence Ouverte / Open Licence 2.0 (Etalab), which asks for + the source and the date it was last updated: "ANSES-CIQUAL French food + composition table, 2025 version (Anses), last updated 19 November 2025." +- **Fineli**: CC BY 4.0. "Finnish Institute for Health and Welfare (THL), + Fineli, the Finnish food composition database, release 20." + +All three credits are on the app's Food data sources screen +(`apps/mobile/lib/foodSources.ts`). ## Tests @@ -247,7 +339,7 @@ merge with or remove real imported foods. They import every fixture twice (the second run must change nothing) and check the Foundation/SR merge, scoped `--full` removals, obsolete OFF products and `--only-existing`. -`fixtures/` holds small cuts of the real files (under 400 KB in all): +`fixtures/` holds small cuts of the real files (under 600 KB in all): - `fdc/`: 7 Foundation foods (JSON, fields the importer doesn't read removed), 10 SR Legacy foods (a zip laid out like USDA's), 4 FNDDS foods, @@ -258,4 +350,17 @@ scoped `--full` removals, obsolete OFF products and `--only-existing`. contributors, https://world.openfoodfacts.org; - `cofid/`: 39 foods of three CoFID sheets as CSV (the tests build the workbook from them): Open Government Licence v3.0, source Public Health - England (2021). + England (2021); +- `cnf/`: 7 foods of the CNF 2015 files, as the release writes them + (Latin-1; a dish, a measure the release has no name for, vitamin D in IU + only): Open Government Licence – Canada, source Health Canada; +- `fineli/`: 8 foods of Fineli release 20 (semicolons, Latin-1, CRLF; a + mixed dish, a recipe that isn't one, a food without energy, the dietary + supplement): CC BY 4.0, THL; +- `ciqual/`: 9 foods of the CIQUAL 2025 XML (traces, values below the + lab's limit, salt without sodium, an entity in a name, a dish, a food + without energy), cut to the constituents read: Licence Ouverte 2.0, + Anses. + +The CNF and Fineli tests also read the whole releases in `data/` (a few +seconds each), so a changed file fails them. diff --git a/packages/food-data/data/Fineli_Rel20_74_ravintotekijaa.zip b/packages/food-data/data/Fineli_Rel20_74_ravintotekijaa.zip new file mode 100644 index 0000000..f130505 Binary files /dev/null and b/packages/food-data/data/Fineli_Rel20_74_ravintotekijaa.zip differ diff --git a/packages/food-data/data/README.md b/packages/food-data/data/README.md new file mode 100644 index 0000000..7ead965 --- /dev/null +++ b/packages/food-data/data/README.md @@ -0,0 +1,19 @@ +# National table releases kept here + +Health Canada's and Fineli's sites refuse requests from servers (a dropped +connection and a bot check), so these two releases were downloaded in a +browser and are kept in the repository, unchanged. The importers check each +file's SHA-256 before reading it, so a changed or truncated file is never +imported as the release it claims to be. CIQUAL isn't kept here: the importer +downloads it from Recherche Data Gouv, which answers servers. + +| File | What it is | From | SHA-256 | Licence | +| ------------------------------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------ | ---------------------------------------------------------------------------- | +| `cnf-fcen-csv.zip` | Canadian Nutrient File 2015, full database, CSV (Health Canada) | [Health Canada](https://www.canada.ca/en/health-canada/services/food-nutrition/healthy-eating/nutrient-data/canadian-nutrient-file-2015-download-files.html) | `fb77503d88186844cc2c27b39432d755505f97a789c97fc5973a30d0cd4b0367` | Open Government Licence – Canada; credit Health Canada | +| `Fineli_Rel20_74_ravintotekijaa.zip` | Fineli release 20, basic package 2 (74 components) (THL), renamed to ASCII | [Fineli open data](https://fineli.fi/fineli/en/avoin-data) | `e7e6bd8d4b9261d751229e763dad436b297d36d48fe853faf49e1fd2a116d262` | CC BY 4.0; credit the Finnish Institute for Health and Welfare (THL), Fineli | + +Both were downloaded on 7 November 2026. To update one, download the new +release in a browser, replace the file (keep the name, or change the name +and the constant in `src/sources/cnf.ts` or `src/sources/fineli.ts`), +update its SHA-256 there and here, and run the tests: they read the whole +file. diff --git a/packages/food-data/data/cnf-fcen-csv.zip b/packages/food-data/data/cnf-fcen-csv.zip new file mode 100644 index 0000000..f3f8c81 Binary files /dev/null and b/packages/food-data/data/cnf-fcen-csv.zip differ diff --git a/packages/food-data/fixtures/ciqual/alim_2025_11_03.xml b/packages/food-data/fixtures/ciqual/alim_2025_11_03.xml new file mode 100644 index 0000000..fc25414 --- /dev/null +++ b/packages/food-data/fixtures/ciqual/alim_2025_11_03.xml @@ -0,0 +1,93 @@ + + + + 1000 + Pastis + Pastis (anise-flavoured spirit) + + 06 + 0603 + 060303 + 6.25 + + + 1007 + Apéritif à base de vin ou vermouth + Wine-based aperitif + + 06 + 0603 + 060303 + 6.25 + + + 1010 + Pastis, prêt à boire (1+ 5) + Anise spirit, diluted (1+5) + + 06 + 0603 + 060303 + 6.25 + + + 1018 + Kir (vin blanc, crème de cassis) + Kir (white wine with blackcurrant liqueur) + + 06 + 0603 + 060304 + 6.25 + + + 2023 + Jus de mangue, frais + Mango juice, fresh + + 06 + 0602 + 060201 + 6.25 + + + 5002 + Bière forte (>8° alcool) + Beer, strong (>8° alcohol) + + 06 + 0603 + 060302 + 6.25 + + + 7603 + Croissant, sans précision (aliment moyen) + Croissant (average) + + 07 + 0705 + 000000 + 5.7 + + + 25601 + Salade de thon et légumes, appertisée + Tuna salad, with vegetables, canned + + 01 + 0101 + 000000 + 6.25 + + + 40109 + Foie, volaille, cuit + Liver, poultry, cooked + + 04 + 0401 + 040108 + 6.25 + +
diff --git a/packages/food-data/fixtures/ciqual/alim_grp_2025_11_03.xml b/packages/food-data/fixtures/ciqual/alim_grp_2025_11_03.xml new file mode 100644 index 0000000..112ca88 --- /dev/null +++ b/packages/food-data/fixtures/ciqual/alim_grp_2025_11_03.xml @@ -0,0 +1,245 @@ + + + + 01 + entrées et plats composés + starters and dishes + 0101 + salades composées et crudités + mixed salads + 000000 + - + - + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 000000 + - + - + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040101 + boeuf et veau + beef and veal + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040102 + porc + pork + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040103 + poulet + poultry + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040104 + dinde + turkey + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040105 + agneau et mouton + lamb and mutton + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040106 + gibier + game + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040107 + autres viandes + other meats + + + 04 + viandes, oeufs, poissons + meat, egg and fish + 0401 + viandes cuites + cooked meat + 040108 + abats + offals + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060201 + jus + juices + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060202 + nectars + nectars + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060203 + boissons rafraîchissantes sans alcool + soft drinks + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060204 + boissons rafraîchissantes lactées + dairy beverages + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060205 + boissons végétales + plant-based beverages + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060206 + café, thé, cacao etc. prêts à consommer + coffee, tea, cocoa beverages, etc. ready to drink + + + 06 + eaux et autres boissons + beverages + 0602 + boissons sans alcool + non-alcoholic beverages + 060207 + boissons à reconstituer + beverages, to reconstitute + + + 06 + eaux et autres boissons + beverages + 0603 + boisson alcoolisées + alcoholic beverages + 060301 + vins + wines + + + 06 + eaux et autres boissons + beverages + 0603 + boisson alcoolisées + alcoholic beverages + 060302 + bières et cidres + beers and ciders + + + 06 + eaux et autres boissons + beverages + 0603 + boisson alcoolisées + alcoholic beverages + 060303 + liqueurs et alcools + liqueurs and spirits + + + 06 + eaux et autres boissons + beverages + 0603 + boisson alcoolisées + alcoholic beverages + 060304 + cocktails + cocktails + + + 07 + produits sucrés + sugar and confectionery + 0705 + viennoiseries + Viennese pastries + 000000 + - + - + +
diff --git a/packages/food-data/fixtures/ciqual/compo_2025_11_03.xml b/packages/food-data/fixtures/ciqual/compo_2025_11_03.xml new file mode 100644 index 0000000..272d585 --- /dev/null +++ b/packages/food-data/fixtures/ciqual/compo_2025_11_03.xml @@ -0,0 +1,3000 @@ + + + + 1000 + 327 + 1140 + + + D + 444 + + + 1000 + 328 + 274 + + + D + 444 + + + 1000 + 332 + 1140 + + + D + 444 + + + 1000 + 333 + 274 + + + D + 444 + + + 1000 + 400 + 59,7 + 58,7 + 60,4 + D + 1373 + + + 1000 + 10004 + 0 + + + C + 355 + + + 1000 + 10110 + 0 + + + C + 355 + + + 1000 + 10120 + 0 + + + D + 74 + + + 1000 + 10150 + - + + + + + + + 1000 + 10190 + 2 + + + D + 74 + + + 1000 + 10200 + 0 + + + D + 74 + + + 1000 + 10260 + - + + + + + + + 1000 + 10300 + 0,02 + + + D + 243 + + + 1000 + 10340 + 0 + + + D + 243 + + + 1000 + 25000 + 0 + + + C + 444 + + + 1000 + 25003 + 0 + + + C + 444 + + + 1000 + 31000 + 2,86 + + + D + 444 + + + 1000 + 32000 + 0 + + + C + 355 + + + 1000 + 34100 + 0 + + + C + 355 + + + 1000 + 40000 + 0 + + + C + 355 + + + 1000 + 40302 + 0 + + + C + 355 + + + 1000 + 51104 + 0 + + + D + 444 + + + 1000 + 52100 + 0 + + + D + 74 + + + 1000 + 53100 + - + + + + + + + 1000 + 54101 + - + + + + + + + 1000 + 55100 + 0 + + + D + 74 + + + 1000 + 56100 + 0 + + + D + 74 + + + 1000 + 56200 + 0 + + + D + 74 + + + 1000 + 56310 + 0 + + + D + 74 + + + 1000 + 56500 + 0 + + + D + 74 + + + 1000 + 56600 + 0 + + + D + 74 + + + 1000 + 56700 + 0 + + + D + 74 + + + 1000 + 56702 + - + + + + + + + 1000 + 60000 + 37,5 + 37,3 + 37,6 + D + 74 + + + 1000 + 71010 + - + + + + + + + 1007 + 327 + 573 + + + D + 444 + + + 1007 + 328 + 137 + + + D + 444 + + + 1007 + 332 + 573 + + + D + 444 + + + 1007 + 333 + 137 + + + D + 444 + + + 1007 + 400 + 75,3 + 60 + 83,2 + D + 575 + + + 1007 + 10004 + 0,038 + 0,0075 + 0,07 + D + 575 + + + 1007 + 10110 + 15 + 3 + 28 + D + 575 + + + 1007 + 10120 + 7 + 5 + 9 + D + 535 + + + 1007 + 10150 + 6,25 + 6 + 7 + D + 583 + + + 1007 + 10190 + 48 + 30 + 75 + D + 492 + + + 1007 + 10200 + 7,37 + 1,5 + 10 + D + 575 + + + 1007 + 10260 + 0,44 + 0,3 + 0,8 + D + 575 + + + 1007 + 10300 + 0,035 + 0,03 + 0,04 + D + 23 + + + 1007 + 10340 + traces + + + D + 23 + + + 1007 + 25000 + 0,054 + 0,013 + 0,1 + D + 444 + + + 1007 + 25003 + 0,054 + 0,01 + 0,1 + D + 444 + + + 1007 + 31000 + 11,3 + + + D + 444 + + + 1007 + 32000 + 11,1 + 2,51 + 15,9 + D + 1380 + + + 1007 + 34100 + 0 + + + D + 575 + + + 1007 + 40000 + 0 + + + D + 575 + + + 1007 + 40302 + 0 + + + D + 1380 + + + 1007 + 51104 + 0 + + + D + 444 + + + 1007 + 52100 + 0 + + + D + 575 + + + 1007 + 53100 + 0 + + + D + 106 + + + 1007 + 54101 + - + + + + + + + 1007 + 55100 + - + + + + + + + 1007 + 56100 + traces + + + D + 23 + + + 1007 + 56200 + traces + + + D + 23 + + + 1007 + 56310 + 0,045 + 0,04 + 0,05 + D + 535 + + + 1007 + 56500 + 0,0075 + + + D + 583 + + + 1007 + 56600 + 0,0033 + + + D + 23 + + + 1007 + 56700 + traces + + + D + 23 + + + 1007 + 56702 + - + + + + + + + 1007 + 60000 + 13,1 + 11,2 + 14,7 + D + 575 + + + 1007 + 71010 + - + + + + + + + 1010 + 327 + - + + + + + + + 1010 + 328 + - + + + + + + + 1010 + 332 + - + + + + + + + 1010 + 333 + - + + + + + + + 1010 + 400 + 93,1 + + + B + 392 + + + 1010 + 10004 + 0,0063 + + + B + 392 + + + 1010 + 10110 + 1,99 + + + B + 392 + + + 1010 + 10120 + 0,82 + + + B + 392 + + + 1010 + 10150 + - + + + + + + + 1010 + 10190 + - + + + + + + + 1010 + 10200 + - + + + + + + + 1010 + 10260 + 0,039 + + + B + 392 + + + 1010 + 10300 + 0,013 + + + B + 392 + + + 1010 + 10340 + 0,42 + + + B + 392 + + + 1010 + 25000 + 0 + + + B + 444 + + + 1010 + 25003 + 0 + + + D + 444 + + + 1010 + 31000 + 0,5 + + + B + 444 + + + 1010 + 32000 + 0 + + + B + 392 + + + 1010 + 34100 + 0 + + + B + 392 + + + 1010 + 40000 + 0 + + + B + 392 + + + 1010 + 40302 + 0 + + + B + 392 + + + 1010 + 51104 + 0 + + + B + 444 + + + 1010 + 52100 + - + + + + + + + 1010 + 53100 + - + + + + + + + 1010 + 54101 + 0 + + + B + 392 + + + 1010 + 55100 + 0 + + + B + 392 + + + 1010 + 56100 + 0 + + + B + 392 + + + 1010 + 56200 + 0 + + + B + 392 + + + 1010 + 56310 + 0 + + + B + 392 + + + 1010 + 56500 + 0 + + + B + 392 + + + 1010 + 56600 + 0 + + + B + 392 + + + 1010 + 56700 + 0 + + + B + 392 + + + 1010 + 56702 + - + + + + + + + 1010 + 60000 + - + + + + + + + 1010 + 71010 + - + + + + + + + 1018 + 327 + 311 + + + D + 444 + + + 1018 + 328 + 74,7 + + + D + 444 + + + 1018 + 332 + 311 + + + D + 444 + + + 1018 + 333 + 74,7 + + + D + 444 + + + 1018 + 400 + 83,5 + 79,9 + 87,1 + D + 1724 + + + 1018 + 10004 + 0,0039 + 0,0032 + 0,0046 + A + 162 + + + 1018 + 10110 + 1,56 + 1,28 + 1,83 + A + 162 + + + 1018 + 10120 + 5,09 + 4,92 + 5,26 + A + 162 + + + 1018 + 10150 + 18 + + 18,1 + D + 1724 + + + 1018 + 10190 + 108 + 85,4 + 131 + D + 1724 + + + 1018 + 10200 + 6,88 + 5,86 + 7,9 + A + 162 + + + 1018 + 10260 + 0,67 + 0,64 + 0,7 + D + 1724 + + + 1018 + 10300 + 0,082 + 0,063 + 0,1 + A + 162 + + + 1018 + 10340 + < 2,2 + + + A + 162 + + + 1018 + 25000 + 0,18 + 0,056 + 0,31 + D + 444 + + + 1018 + 25003 + 0,18 + 0,056 + 0,31 + D + 444 + + + 1018 + 31000 + 3,3 + + + D + 444 + + + 1018 + 32000 + 3,3 + + 7,8 + D + 444 + + + 1018 + 34100 + 0 + + + D + 240 + + + 1018 + 40000 + 0 + + + D + 1724 + + + 1018 + 40302 + 0 + + + D + 240 + + + 1018 + 51104 + 0,73 + + + D + 444 + + + 1018 + 52100 + 0 + + + D + 240 + + + 1018 + 53100 + 0,14 + 0,093 + 0,18 + D + 1724 + + + 1018 + 54101 + - + + + + + + + 1018 + 55100 + 18,5 + 0,9 + 36 + D + 1724 + + + 1018 + 56100 + 0,0068 + + + D + 240 + + + 1018 + 56200 + 0,019 + 0,01 + 0,029 + D + 1724 + + + 1018 + 56310 + 0,12 + 0,11 + 0,14 + D + 1724 + + + 1018 + 56500 + 0,03 + + + D + 1724 + + + 1018 + 56600 + 0 + + + D + 240 + + + 1018 + 56700 + 3,97 + 0,94 + 7 + D + 1724 + + + 1018 + 56702 + - + + + + + + + 1018 + 60000 + 8,69 + 7 + 10,4 + D + 1724 + + + 1018 + 71010 + - + + + + + + + 2023 + 327 + 165 + + + D + 444 + + + 2023 + 328 + 38,8 + + + D + 444 + + + 2023 + 332 + 165 + + + D + 444 + + + 2023 + 333 + 38,8 + + + D + 444 + + + 2023 + 400 + 86 + + + D + 243 + + + 2023 + 10004 + 0,028 + + + D + 243 + + + 2023 + 10110 + - + + + + + + + 2023 + 10120 + 14,3 + + + D + 243 + + + 2023 + 10150 + - + + + + + + + 2023 + 10190 + - + + + + + + + 2023 + 10200 + - + + + + + + + 2023 + 10260 + - + + + + + + + 2023 + 10300 + 0,02 + + + D + 243 + + + 2023 + 10340 + 0,1 + + + D + 243 + + + 2023 + 25000 + 0,19 + + + D + 444 + + + 2023 + 25003 + 0,19 + + 0,2 + D + 444 + + + 2023 + 31000 + 9,5 + + + D + 444 + + + 2023 + 32000 + 9,3 + + + D + 20 + + + 2023 + 34100 + traces + + + D + 20 + + + 2023 + 40000 + 0 + + + B + 444 + + + 2023 + 40302 + traces + + + D + 444 + + + 2023 + 51104 + 31,3 + + + D + 444 + + + 2023 + 52100 + 0 + + + D + 444 + + + 2023 + 53100 + 1,05 + + + D + 20 + + + 2023 + 54101 + - + + + + + + + 2023 + 55100 + - + + + + + + + 2023 + 56100 + 0,01 + + + D + 20 + + + 2023 + 56200 + - + + + + + + + 2023 + 56310 + - + + + + + + + 2023 + 56500 + 0,12 + + + D + 243 + + + 2023 + 56600 + 0 + + + D + 444 + + + 2023 + 56700 + 27,1 + + + D + 243 + + + 2023 + 56702 + - + + + + + + + 2023 + 60000 + 0 + + + D + 444 + + + 2023 + 71010 + - + + + + + + + 5002 + 327 + 261 + + + D + 444 + + + 5002 + 328 + 62,5 + + + D + 444 + + + 5002 + 332 + 261 + + + D + 444 + + + 5002 + 333 + 62,5 + + + D + 444 + + + 5002 + 400 + 88,8 + 88 + 89,2 + D + 608 + + + 5002 + 10004 + 0,017 + 0,0025 + 0,036 + D + 284 + + + 5002 + 10110 + 6,8 + 1 + 14,4 + D + 284 + + + 5002 + 10120 + 9 + 7,7 + 10,5 + D + 284 + + + 5002 + 10150 + 18,4 + + + D + 284 + + + 5002 + 10190 + 64,2 + 37,5 + 81,3 + D + 284 + + + 5002 + 10200 + 4,3 + 2,9 + 5,7 + D + 284 + + + 5002 + 10260 + 0,02 + 0,008 + 0,033 + D + 284 + + + 5002 + 10300 + 0,013 + + 0,05 + D + 284 + + + 5002 + 10340 + 0,11 + + 0,9 + D + 284 + + + 5002 + 25000 + 0,51 + 0,4 + 0,63 + D + 444 + + + 5002 + 25003 + 0,51 + 0,4 + 0,63 + D + 444 + + + 5002 + 31000 + 4,6 + + + D + 444 + + + 5002 + 32000 + - + + + + + + + 5002 + 34100 + 0 + + + D + 284 + + + 5002 + 40000 + 0 + + + D + 284 + + + 5002 + 40302 + 0 + + + D + 284 + + + 5002 + 51104 + - + + + + + + + 5002 + 52100 + 0 + + + D + 284 + + + 5002 + 53100 + - + + + + + + + 5002 + 54101 + 0 + + + D + 284 + + + 5002 + 55100 + 0 + + + D + 284 + + + 5002 + 56100 + 0,007 + + + D + 284 + + + 5002 + 56200 + 0,03 + + + D + 284 + + + 5002 + 56310 + 0,47 + + + D + 284 + + + 5002 + 56500 + 0,045 + + + D + 284 + + + 5002 + 56600 + 0,02 + + + D + 284 + + + 5002 + 56700 + 2,6 + + + D + 284 + + + 5002 + 56702 + - + + + + + + + 5002 + 60000 + 6 + 5,5 + 6,2 + D + 284 + + + 5002 + 71010 + 0 + + + D + 284 + + + 7603 + 327 + 1750 + + + D + 443 + + + 7603 + 328 + 417 + + + D + 443 + + + 7603 + 332 + 1740 + + + D + 443 + + + 7603 + 333 + 415 + + + D + 443 + + + 7603 + 400 + 21,2 + + + D + 443 + + + 7603 + 10004 + 1,19 + + + D + 443 + + + 7603 + 10110 + 478 + + + D + 443 + + + 7603 + 10120 + 15,7 + + + D + 443 + + + 7603 + 10150 + 80,9 + + + D + 443 + + + 7603 + 10190 + 123 + + + D + 443 + + + 7603 + 10200 + 23,5 + + + D + 443 + + + 7603 + 10260 + 0,74 + + + D + 443 + + + 7603 + 10300 + 0,56 + + + D + 443 + + + 7603 + 10340 + 9,7 + + + D + 443 + + + 7603 + 25000 + 6,56 + + + D + 443 + + + 7603 + 25003 + 7,19 + + + D + 443 + + + 7603 + 31000 + 46,2 + + + D + 443 + + + 7603 + 32000 + 7,49 + + + D + 443 + + + 7603 + 34100 + 2,41 + + + D + 443 + + + 7603 + 40000 + 22,1 + + + D + 443 + + + 7603 + 40302 + 14 + + + D + 443 + + + 7603 + 51104 + 149 + + + D + 443 + + + 7603 + 52100 + < 0,24 + + + D + 443 + + + 7603 + 53100 + - + + + + + + + 7603 + 54101 + 2,41 + + + D + 443 + + + 7603 + 55100 + 0,61 + + + D + 443 + + + 7603 + 56100 + 0,073 + + + D + 443 + + + 7603 + 56200 + 0,031 + + + D + 443 + + + 7603 + 56310 + 0,17 + + + D + 443 + + + 7603 + 56500 + 0,033 + + + D + 443 + + + 7603 + 56600 + 0,12 + + + D + 443 + + + 7603 + 56700 + 21,3 + + + D + 443 + + + 7603 + 56702 + - + + + + + + + 7603 + 60000 + 0 + + + D + 443 + + + 7603 + 71010 + 0,9 + + + D + 443 + + + 25601 + 327 + 489 + + + D + 444 + + + 25601 + 328 + 117 + + + D + 444 + + + 25601 + 332 + 489 + + + D + 444 + + + 25601 + 333 + 117 + + + D + 444 + + + 25601 + 400 + 76,5 + 76,3 + 76,8 + A + 1921 + + + 25601 + 10004 + 1,11 + + + A + 187 + + + 25601 + 10110 + 445 + + + A + 187 + + + 25601 + 10120 + 25,1 + + + A + 187 + + + 25601 + 10150 + 88,4 + + + A + 187 + + + 25601 + 10190 + 232 + + + A + 187 + + + 25601 + 10200 + 20,7 + + + A + 187 + + + 25601 + 10260 + 1,1 + 0,1 + + A + 187 + + + 25601 + 10300 + 0,6 + 0,1 + + A + 187 + + + 25601 + 10340 + - + + + + + + + 25601 + 25000 + 9,15 + + + A + 444 + + + 25601 + 25003 + 9,15 + + + A + 444 + + + 25601 + 31000 + 8,13 + 4,5 + 13 + C + 444 + + + 25601 + 32000 + 3,63 + 2 + 4,5 + C + 355 + + + 25601 + 34100 + 2,7 + 1 + + A + 187 + + + 25601 + 40000 + 4,7 + 0,05 + 5,3 + A + 1922 + + + 25601 + 40302 + 0,56 + 0,05 + 0,62 + A + 194 + + + 25601 + 51104 + - + + + + + + + 25601 + 52100 + < 0,5 + + + A + 187 + + + 25601 + 53100 + 1,6 + + + A + 187 + + + 25601 + 54101 + - + + + + + + + 25601 + 55100 + 2,75 + 0,5 + + A + 187 + + + 25601 + 56100 + < 0,04 + + + A + 187 + + + 25601 + 56200 + 0,053 + 0,04 + + A + 187 + + + 25601 + 56310 + 4,45 + + + A + 187 + + + 25601 + 56500 + 0,29 + 0,04 + + A + 187 + + + 25601 + 56600 + 1,45 + 0,08 + + A + 187 + + + 25601 + 56700 + 31 + + + A + 187 + + + 25601 + 56702 + - + + + + + + + 25601 + 60000 + 0 + + + B + 444 + + + 25601 + 71010 + - + + + + + + + 40109 + 327 + 687 + + + D + 444 + + + 40109 + 328 + 164 + + + D + 444 + + + 40109 + 332 + 687 + + + D + 444 + + + 40109 + 333 + 164 + + + D + 444 + + + 40109 + 400 + 65,4 + + + A + 389 + + + 40109 + 10004 + 0,25 + + + A + 389 + + + 40109 + 10110 + 99 + + + A + 389 + + + 40109 + 10120 + 24 + + + A + 389 + + + 40109 + 10150 + 380 + + + A + 389 + + + 40109 + 10190 + 340 + + + A + 389 + + + 40109 + 10200 + 6,6 + + + A + 389 + + + 40109 + 10260 + 12 + + + A + 389 + + + 40109 + 10300 + 3,9 + + + A + 389 + + + 40109 + 10340 + 90 + + + A + 389 + + + 40109 + 25000 + 25,8 + + + A + 444 + + + 40109 + 25003 + 25,8 + + + A + 444 + + + 40109 + 31000 + 0 + + + A + 444 + + + 40109 + 32000 + - + + + + + + + 40109 + 34100 + 0 + + + B + 444 + + + 40109 + 40000 + 6,4 + + + A + 389 + + + 40109 + 40302 + 2,5 + + + A + 389 + + + 40109 + 51104 + - + + + + + + + 40109 + 52100 + 1,29 + + 2,32 + A + 444 + + + 40109 + 53100 + - + + + + + + + 40109 + 54101 + 3,2 + + + A + 389 + + + 40109 + 55100 + < 0,5 + + + A + 389 + + + 40109 + 56100 + 0,28 + + + A + 389 + + + 40109 + 56200 + 1,4 + + + A + 389 + + + 40109 + 56310 + 32,6 + + + A + 389 + + + 40109 + 56500 + 0,59 + + + A + 389 + + + 40109 + 56600 + 50,5 + + + A + 389 + + + 40109 + 56700 + 1440 + + + A + 389 + + + 40109 + 56702 + - + + + + + + + 40109 + 60000 + 0 + + + B + 444 + + + 40109 + 71010 + 1,51 + + + A + 389 + + + 1000 + 51200 + 0 + + + D + 74 + + + 1000 + 51330 + 0 + + + D + 444 + + + 1007 + 51200 + 0 + + + D + 1380 + + + 1007 + 51330 + 0 + + + D + 106 + + + 1010 + 51200 + 0 + + + B + 392 + + + 1010 + 51330 + 0 + + + B + 392 + + + 1018 + 51200 + 0 + + + D + 240 + + + 1018 + 51330 + 8,7 + + + D + 240 + + + 2023 + 51200 + 0 + + + D + 444 + + + 2023 + 51330 + 375 + + + D + 243 + + + 5002 + 51200 + 0 + + + D + 284 + + + 5002 + 51330 + - + + + + + + + 7603 + 51200 + 143 + + + D + 443 + + + 7603 + 51330 + 67,4 + + + D + 443 + + + 25601 + 51200 + < 2 + + + A + 187 + + + 25601 + 51330 + - + + + + + + + 40109 + 51200 + 18700 + + + A + 389 + + + 40109 + 51330 + - + + + + + +
diff --git a/packages/food-data/fixtures/cnf/CONVERSION FACTOR.csv b/packages/food-data/fixtures/cnf/CONVERSION FACTOR.csv new file mode 100644 index 0000000..3da4282 --- /dev/null +++ b/packages/food-data/fixtures/cnf/CONVERSION FACTOR.csv @@ -0,0 +1,26 @@ +FoodID,MeasureID,ConversionFactorValue,ConvFactorDateOfEntry +2,341,0.40152,1997-05-01 +2,383,0.50190,2003-08-12 +2,415,1.00380,2003-08-12 +55,341,1.07354,1999-06-16 +55,383,1.34193,2004-02-13 +55,415,2.68385,2003-03-07 +55,502468,0.90000,2012-08-14 +61,341,1.03128,1999-06-02 +61,415,2.57819,2003-03-07 +534,341,1.03550,1999-06-09 +534,385,0.15533,1997-05-01 +534,415,2.58875,2003-04-15 +534,428,0.31065,2004-07-09 +2000,243,1.44000,1997-05-01 +2000,363,0.50719,1997-05-01 +2000,1145,0.63398,2003-06-02 +2000,1146,1.26796,2003-06-02 +2000,1470,0.85000,2004-02-25 +4000,305,0.75000,1997-05-01 +4000,573,0.50000,1997-05-01 +4000,1496,0.75000,2004-03-25 +501999,341,0.66000,2009-07-20 +501999,383,0.82500,2009-07-20 +501999,415,1.65000,2009-07-20 +501999,1607,1.95000,2009-07-20 diff --git a/packages/food-data/fixtures/cnf/FOOD GROUP.csv b/packages/food-data/fixtures/cnf/FOOD GROUP.csv new file mode 100644 index 0000000..a91b327 --- /dev/null +++ b/packages/food-data/fixtures/cnf/FOOD GROUP.csv @@ -0,0 +1,25 @@ +FoodGroupID,FoodGroupCode,FoodGroupName,FoodGroupNameF +1,1,Dairy and Egg Products,"Produits laitiers et d'oeufs +" +2,2,Spices and Herbs,Épices et fines herbes +3,3,Babyfoods,Aliments pour bébés +4,4,Fats and Oils,Matières grasses et huiles +5,5,Poultry Products,Produits de volaille +6,6,"Soups, Sauces and Gravies",Potages et sauces +7,7,Sausages and Luncheon meats,Saucisses et viandes froides +8,8,Breakfast cereals,Céréales à déjeuner +9,9,Fruits and fruit juices,Fruits et jus de fruits +10,10,Pork Products,Produits de porc +11,11,Vegetables and Vegetable Products,Légumes et produits végétaux +12,12,Nuts and Seeds,Noix et graines +13,13,Beef Products,Produits de boeuf +14,14,Beverages,Boissons +15,15,Finfish and Shellfish Products,"Produits de poissons, mollusques et crustacés" +16,16,Legumes and Legume Products,Légumineuses et produits de légumineuses +17,17,"Lamb, Veal and Game","Ageau, veau et gibier" +18,18,Baked Products,Produits de boulangerie +19,19,Sweets,Sucreries +20,20,"Cereals, Grains and Pasta","Céréales, grains et pâtes" +21,21,Fast Foods,Aliments prêts-à-manger +22,22,Mixed Dishes,Mets composés +25,25,Snacks,Grignotises diff --git a/packages/food-data/fixtures/cnf/FOOD NAME.csv b/packages/food-data/fixtures/cnf/FOOD NAME.csv new file mode 100644 index 0000000..3ebe604 --- /dev/null +++ b/packages/food-data/fixtures/cnf/FOOD NAME.csv @@ -0,0 +1,8 @@ +FoodID,FoodCode,FoodGroupID,FoodSourceID,FoodDescription,FoodDescriptionF,FoodDateOfEntry,FoodDateOfPublication,CountryCode,ScientificName +2,2,22,20,Cheese souffle,Soufflé au fromage,1981-01-01,,, +55,55,1,0,"Eggnog, 7% M.F., Canadian product, 4% to 8% M.F.","Lait de poule, 7% M.G., produit canadien, 4% à 8% M.G.",1981-01-01,,01057, +61,61,1,0,"Milk, fluid, partly skimmed, 2% M.F.","Lait, partiellement écrémé, liquide, 2% M.G.",1981-01-01,,01079, +534,534,4,0,"Salad dressing, blue or roquefort cheese, commercial, regular","Vinaigrette, fromage bleu ou roquefort, commerciale, régulière",1981-01-01,,04539, +2000,2000,11,0,"Bamboo shoots, boiled, drained","Bambou, pousses, bouillies, égouttées",1985-01-01,,11027, +4000,4000,18,0,"Waffle, plain, homemade","Gaufre, nature, faite maison",1995-01-01,,18367, +501999,6772,22,36,Poutine,Poutine,2009-07-20,,, diff --git a/packages/food-data/fixtures/cnf/MEASURE NAME.csv b/packages/food-data/fixtures/cnf/MEASURE NAME.csv new file mode 100644 index 0000000..7df88cb --- /dev/null +++ b/packages/food-data/fixtures/cnf/MEASURE NAME.csv @@ -0,0 +1,15 @@ +MeasureID,MeasureDescription,MeasureDescriptionF,, +243,1 shoot,1 pousse,, +305,1 waffle (17.8cm dia),1 gaufre (17.8cm dia),, +341,100ml,100ml,, +363,100ml pieces,100ml morceaux,, +383,125ml,125ml,, +385,15ml,15ml,, +415,250ml,250ml,, +428,30ml,30ml,, +573,1 waffle (11.4cm x 11.4cm),1 gauffre (11.4cm x 11.4cm),, +1145,125ml pieces,125ml morceaux,, +1146,250ml pieces,250ml morceaux,, +1470,85g,85g,, +1496,75g,75g,, +1607,195g,195g,, diff --git a/packages/food-data/fixtures/cnf/NUTRIENT AMOUNT.csv b/packages/food-data/fixtures/cnf/NUTRIENT AMOUNT.csv new file mode 100644 index 0000000..599af43 --- /dev/null +++ b/packages/food-data/fixtures/cnf/NUTRIENT AMOUNT.csv @@ -0,0 +1,635 @@ +FoodID,NutrientID,NutrientValue,StandardError,NumberofObservations,NutrientSourceID,NutrientDateOfEntry +2,203,9.54,0,0,102,2010-04-16 +2,204,15.7,0,0,102,2010-04-16 +2,205,5.91,0,0,102,2010-04-16 +2,207,1.67,0,0,102,2010-04-16 +2,208,204,0,0,102,2010-04-16 +2,221,0,,0,12,2004-09-13 +2,255,67.17,0,0,102,2010-04-16 +2,262,0,,0,12,2004-09-13 +2,263,0,,0,12,2004-09-13 +2,268,853,0,0,4,2010-04-16 +2,269,2.66,,,102,2010-04-16 +2,291,0.1,0,0,102,2010-04-16 +2,301,184,0,0,102,2010-04-16 +2,303,0.74,0,0,102,2010-04-16 +2,304,13,,,102,2010-04-16 +2,305,167,0,0,102,2010-04-16 +2,306,119,0,0,102,2010-04-16 +2,307,318,0,0,102,2010-04-16 +2,309,1.1,0,0,102,2010-04-16 +2,312,0.031,0,0,102,2010-04-16 +2,315,0.043,,,102,2010-04-16 +2,317,15.8,,,102,2010-04-16 +2,319,188,,,102,2010-04-16 +2,321,64,,,102,2010-04-16 +2,323,2.03,0,0,102,2010-04-16 +2,324,79,,,102,2010-04-16 +2,339,2,0,0,102,2010-04-16 +2,401,0,0,0,102,2010-04-16 +2,404,0.052,0,0,102,2010-04-16 +2,405,0.296,0,0,102,2010-04-16 +2,406,0.317,0,0,102,2010-04-16 +2,409,2.55,0,0,4,2010-04-16 +2,410,0.971,0,0,102,2010-04-16 +2,415,0.038,0,0,102,2010-04-16 +2,417,27,0,0,102,2010-04-16 +2,418,0.604,0,0,102,2010-04-16 +2,430,8,,,102,2010-04-16 +2,431,6,,,102,2010-04-16 +2,501,0.134,,,102,2010-04-16 +2,502,0.366,0,0,102,2010-04-16 +2,503,0.538,,,102,2010-04-16 +2,504,0.889,,,102,2010-04-16 +2,505,0.717,,,102,2010-04-16 +2,506,0.266,0,0,102,2010-04-16 +2,507,0.155,,,102,2010-04-16 +2,508,0.517,,,102,2010-04-16 +2,509,0.428,0,0,102,2010-04-16 +2,510,0.621,,,102,2010-04-16 +2,511,0.449,0,0,102,2010-04-16 +2,512,0.237,0,0,102,2010-04-16 +2,513,0.391,0,0,102,2010-04-16 +2,514,0.781,,,102,2010-04-16 +2,515,2.017,,,102,2010-04-16 +2,516,0.233,,,102,2010-04-16 +2,517,0.825,,,102,2010-04-16 +2,518,0.623,,,102,2010-04-16 +2,601,129,0,0,102,2010-04-16 +2,605,1.239,,,102,2010-04-16 +2,606,5.742,0,0,102,2010-04-16 +2,609,0.044,0,0,102,2010-04-16 +2,610,0.103,,,102,2010-04-16 +2,611,0.136,,,102,2010-04-16 +2,612,0.62,,,102,2010-04-16 +2,613,2.968,,,102,2010-04-16 +2,614,1.389,0,0,102,2010-04-16 +2,617,5.383,0,0,102,2010-04-16 +2,618,2.204,0,0,102,2010-04-16 +2,619,0.484,0,0,102,2010-04-16 +2,620,0.047,,,102,2010-04-16 +2,621,0.022,,0,102,2010-04-16 +2,626,0.274,0,0,102,2010-04-16 +2,627,0,,,102,2010-04-16 +2,629,0.001,8,0,102,1997-05-01 +2,630,0.002,,,102,2010-04-16 +2,631,0.003,,0,102,2010-04-16 +2,645,5.82,0,0,102,2010-04-16 +2,646,2.77,0,0,102,2010-04-16 +2,806,21,,,102,2010-04-16 +2,814,194,,,102,2010-04-16 +2,815,30,,,4,2010-04-16 +2,825,2.01,,,102,2010-04-16 +2,827,0.006,,0,102,2010-04-16 +2,831,0.452,,0,102,2010-04-16 +2,832,0.03,,0,102,2010-04-16 +2,835,0,,,12,2010-04-16 +2,836,0,,,12,2010-04-16 +2,837,99,,,102,2012-05-28 +2,854,0.006,,0,2,2010-04-27 +2,855,0.047,,,102,2010-04-16 +2,861,0,,0,12,2009-07-14 +2,874,0,,,12,2015-02-27 +2,875,0,,,12,2015-02-27 +2,876,0,,,12,2015-02-27 +55,203,4.55,,0,0,2010-03-22 +55,204,4.19,,0,0,2010-03-22 +55,205,8.05,,0,0,2010-03-22 +55,207,0.67,,0,0,2010-03-22 +55,208,88,,0,0,2010-03-22 +55,210,0.04,,0,0,2013-05-22 +55,211,0.07,,0,0,2013-05-22 +55,212,0.04,,0,0,2013-05-22 +55,213,7.84,,0,0,2013-05-22 +55,214,0.04,,0,0,2013-05-22 +55,221,0,,0,0,1997-05-01 +55,255,82.54,,0,0,2010-03-22 +55,262,0,,0,0,2004-04-02 +55,263,0,,0,0,2004-04-02 +55,268,367,,0,0,2010-03-22 +55,269,8.05,,0,0,2013-05-22 +55,287,0.04,,0,0,2013-05-22 +55,291,0,,0,0,1997-05-01 +55,301,130,4.803,7,0,2009-07-02 +55,303,0.2,,3,0,1997-05-01 +55,304,19,,2,0,2002-12-04 +55,305,109,4.561,6,0,2009-07-02 +55,306,165,9.997,6,0,2009-07-02 +55,307,54,2.014,6,0,2009-07-02 +55,309,0.46,,0,0,1997-05-01 +55,312,0.013,,0,0,2009-07-02 +55,315,0.005,,0,0,1997-05-01 +55,317,4.2,,0,0,2001-02-22 +55,319,58,,0,0,2010-03-22 +55,321,7,,0,0,2010-03-22 +55,323,0.21,,0,0,2010-03-22 +55,324,49,,0,0,2010-03-25 +55,339,1.2,,0,0,2010-03-25 +55,401,1.5,0.289,3,0,2009-07-02 +55,404,0.034,0.002,6,0,2009-07-02 +55,405,0.19,0.007,7,0,1997-05-01 +55,406,0.105,0.005,4,0,2009-07-02 +55,409,1.522,0,0,4,2010-04-22 +55,410,0.417,,0,0,2009-07-02 +55,415,0.05,,0,0,1997-05-01 +55,417,1,0.153,3,0,2009-07-02 +55,418,0.45,,0,0,1997-05-01 +55,430,0.3,,0,0,2010-03-22 +55,431,0,,0,0,2002-08-22 +55,501,0.085,,0,0,2010-03-22 +55,502,0.201,,0,0,2010-03-22 +55,503,0.237,,0,0,2010-03-22 +55,504,0.383,,0,0,2010-03-22 +55,505,0.257,,0,0,2010-03-22 +55,506,0.12,,0,0,2010-03-22 +55,507,0.057,,0,0,2010-03-22 +55,508,0.225,,0,0,2010-03-22 +55,509,0.199,,0,0,2010-03-22 +55,510,0.289,,0,0,2010-03-22 +55,511,0.191,,0,0,2010-03-22 +55,512,0.108,,0,0,2010-03-22 +55,513,0.199,,0,0,2010-03-22 +55,514,0.4,,0,0,2010-03-22 +55,515,0.775,,0,0,2010-03-22 +55,516,0.128,,0,0,2010-03-22 +55,517,0.349,,0,0,2010-03-22 +55,518,0.241,,0,0,2010-03-22 +55,601,59,,0,0,2002-12-04 +55,606,2.591,,0,0,2010-03-22 +55,607,0.129,,0,0,2010-03-22 +55,608,0.076,,0,0,2010-03-22 +55,609,0.044,,0,0,2010-03-22 +55,610,0.1,,0,0,2010-03-22 +55,611,0.112,,0,0,2010-03-22 +55,612,0.401,,0,0,2010-03-22 +55,613,1.131,,0,0,2010-03-22 +55,614,0.511,,0,0,2010-03-22 +55,617,1.142,,0,0,2010-03-22 +55,618,0.132,,0,0,2010-03-22 +55,619,0.059,,0,0,2010-03-22 +55,620,0.003,,0,0,2010-03-22 +55,621,0,,0,0,2001-07-10 +55,626,0.101,,0,0,2010-03-22 +55,627,0,,0,0,2001-07-10 +55,628,0,,0,0,2001-07-10 +55,629,0,,0,0,2001-07-10 +55,630,0,,0,0,2001-07-10 +55,631,0,,0,0,2001-07-10 +55,645,1.302,,0,0,2010-03-22 +55,646,0.198,,0,0,2010-03-22 +55,806,1,0.153,3,0,2009-07-02 +55,811,0,,0,0,2010-03-25 +55,812,0.08,,0,0,2010-03-25 +55,813,0,,0,0,2010-03-25 +55,814,59,,0,0,2010-03-22 +55,815,1,,0,4,2005-01-17 +55,827,0,,0,12,2009-07-16 +55,831,0.1,,,4,2009-07-16 +55,832,0,,,12,2008-12-11 +55,834,0,,0,0,2009-07-02 +55,835,0,,0,0,2010-03-22 +55,836,0,,0,0,2009-07-02 +55,837,54,,0,0,2013-05-22 +55,840,0,,,12,2010-06-02 +55,852,0,,,12,2010-06-02 +55,854,0,,0,12,2009-04-27 +55,855,0.003,,0,4,2010-04-27 +55,861,0,,0,12,2009-04-27 +55,862,52.2,,0,0,2009-07-02 +61,203,3.3,0.033,13,0,2009-07-02 +61,204,1.98,0.008,14,0,2010-03-22 +61,205,4.8,,0,0,2010-03-22 +61,207,0.71,0.035,13,0,2009-07-02 +61,208,50,,0,0,1997-05-01 +61,210,0.01,0,13,0,2004-04-02 +61,211,0.01,0,13,0,2004-04-02 +61,212,0.01,0,13,0,2004-04-02 +61,213,5.01,0.062,13,0,2009-07-02 +61,214,0.01,0,13,0,2004-04-02 +61,221,0,,0,0,1997-05-01 +61,255,89.21,0.193,17,0,2010-03-22 +61,262,0,,0,0,2002-08-22 +61,263,0,,0,0,2002-08-22 +61,268,210,,0,0,2010-03-22 +61,269,5.06,0.06,13,0,2009-07-02 +61,287,0.02,0.008,13,0,2004-04-02 +61,291,0,,0,0,1997-05-01 +61,301,120,0.707,4,0,2010-03-22 +61,303,0.02,0.002,4,0,2010-03-22 +61,304,11,0.098,31,0,2010-03-22 +61,305,92,0.526,28,0,2010-03-22 +61,306,140,2.114,31,0,2010-03-22 +61,307,47,0.832,31,0,2010-03-22 +61,309,0.48,0.015,29,0,2010-03-22 +61,312,0.006,0,30,0,2010-03-22 +61,315,0.014,0,30,0,2010-03-22 +61,317,2.5,0.174,30,0,2009-07-02 +61,319,63,,,1,2009-01-14 +61,321,4,,0,0,2010-03-22 +61,323,0.03,0.003,12,0,2004-04-02 +61,324,40,,,1,2010-04-15 +61,339,1,,0,1,2010-04-15 +61,401,0.2,0,5,0,2004-03-31 +61,404,0.039,0.005,13,0,2009-07-02 +61,405,0.185,0.003,13,0,2009-07-02 +61,406,0.092,0.002,12,0,2009-07-02 +61,409,0.792,0,0,4,2013-05-22 +61,410,0.356,0.019,5,0,2009-07-02 +61,415,0.038,0.001,13,0,2009-07-02 +61,417,5,0.149,12,0,2009-07-02 +61,418,0.53,0.033,4,0,2010-03-22 +61,430,0.2,0.048,4,0,2009-07-02 +61,431,0,,0,0,2002-08-22 +61,501,0.042,,0,0,2013-05-22 +61,502,0.141,,0,0,2013-05-22 +61,503,0.171,,0,0,2013-05-22 +61,504,0.313,,0,0,2013-05-22 +61,505,0.276,,0,0,2013-05-22 +61,506,0.087,,0,0,2013-05-22 +61,507,0.02,,0,0,2013-05-22 +61,508,0.171,,0,0,2013-05-22 +61,509,0.167,,0,0,2013-05-22 +61,510,0.216,,0,0,2013-05-22 +61,511,0.094,,0,0,2013-05-22 +61,512,0.1,,0,0,2013-05-22 +61,513,0.112,,0,0,2013-05-22 +61,514,0.283,,0,0,2013-05-22 +61,515,0.742,,0,0,2013-05-22 +61,516,0.065,,0,0,2013-05-22 +61,517,0.326,,0,0,2013-05-22 +61,518,0.199,,0,0,2010-03-25 +61,601,8,0.09,5,0,2002-12-04 +61,605,0.085,,0,0,2012-11-04 +61,606,1.257,,0,0,2012-09-05 +61,607,0.077,0.001,5,0,2012-09-06 +61,608,0.04,0.002,4,0,2012-09-06 +61,609,0.02,0.001,5,0,2012-09-05 +61,610,0.049,0.002,5,0,2012-09-05 +61,611,0.006,0.002,5,0,2012-09-05 +61,612,0.175,0.003,5,0,2012-09-05 +61,613,0.558,0.009,5,0,2012-09-05 +61,614,0.243,0.004,5,0,2012-09-05 +61,615,0.004,0,4,0,2012-09-05 +61,617,0.508,,0,0,2012-11-04 +61,618,0.062,,0,0,2012-11-04 +61,619,0.008,,0,0,2012-11-04 +61,620,0,0,4,0,2012-09-06 +61,621,0,0,4,0,2007-08-13 +61,624,0.002,,1,0,2012-09-05 +61,625,0.015,0.001,5,0,2012-09-05 +61,626,0.027,,0,0,2012-11-04 +61,627,0,0,4,0,2009-07-02 +61,628,0.008,,1,3,2009-06-17 +61,629,0,0,4,0,2007-08-13 +61,630,0,0,5,0,2012-09-05 +61,631,0,0,4,0,2012-02-21 +61,636,0,,,4,2008-09-19 +61,638,0,0,4,0,2004-04-02 +61,645,0.56,,0,0,2012-11-04 +61,646,0.073,,0,0,2012-11-04 +61,652,0.02,0,5,0,2012-09-05 +61,653,0.011,0,5,0,2012-09-05 +61,806,5,0.149,12,0,2009-07-02 +61,811,0,0,12,0,2004-04-02 +61,812,0,0,12,0,2004-04-02 +61,813,0,0,12,0,2004-04-02 +61,814,63,,,1,2009-01-26 +61,815,5,,0,4,2005-01-17 +61,816,0,0,4,0,2005-03-22 +61,818,0.078,0.005,4,0,2012-09-05 +61,819,0.007,0,4,0,2012-09-05 +61,821,0.027,,4,0,2012-09-05 +61,824,0.43,0.005,4,0,2012-09-05 +61,825,0.055,0.003,4,0,2012-09-05 +61,826,0.005,0,5,0,2012-09-05 +61,827,0.003,,1,0,2012-09-05 +61,828,0,0,4,0,2005-03-22 +61,829,0.078,,0,0,2012-11-04 +61,831,0.008,0,4,0,2012-09-05 +61,833,0.004,0,5,0,2012-09-05 +61,834,0,,0,0,2005-03-22 +61,835,0,,0,0,2005-03-22 +61,836,0,,0,0,2005-03-22 +61,837,0,,0,0,2005-03-22 +61,855,0,0,4,0,2012-09-06 +61,859,0.007,,0,0,2012-11-04 +61,861,0,,,12,2009-04-27 +61,862,16.4,,0,0,2009-07-02 +61,863,0.9,,2,0,2010-06-11 +61,874,0,,,12,2015-02-19 +61,875,0,,,12,2015-02-19 +61,876,0,,,12,2015-04-16 +534,203,1.37,,2,0,2009-07-02 +534,204,51.1,,2,0,2009-07-02 +534,205,4.77,,0,0,2015-01-16 +534,207,3.2,,1,0,1997-05-01 +534,208,484,,0,0,2015-04-28 +534,221,0,,0,0,2009-07-02 +534,255,39.71,,0,0,2009-07-02 +534,262,0,,0,0,2009-07-02 +534,263,0,,0,0,2009-07-02 +534,268,2024,,0,4,2015-04-28 +534,269,3.48,,2,0,2009-07-02 +534,291,0.4,,2,0,2009-07-02 +534,301,37,,2,0,2009-07-02 +534,303,0.09,,2,0,2009-07-02 +534,304,8,,0,0,2009-07-02 +534,305,74,,0,0,1997-05-01 +534,306,88,,0,0,2009-07-02 +534,307,642,,0,0,2015-01-16 +534,309,0.21,,0,0,2009-07-02 +534,312,0.009,,0,0,2009-07-02 +534,315,0.035,,0,0,2010-05-31 +534,317,1,,2,0,2001-02-22 +534,319,14,,0,0,2015-01-16 +534,321,4,,0,0,2009-07-02 +534,323,4.28,,0,0,2009-07-02 +534,324,3,,,0,2015-05-15 +534,328,0.1,,,0,2015-05-15 +534,401,0.7,,2,0,2009-07-02 +534,404,0.01,,0,0,1997-05-01 +534,405,0.1,,0,0,1997-05-01 +534,406,0.1,,0,0,1997-05-01 +534,409,1.267,,0,4,2005-04-04 +534,410,0.388,,0,0,2009-07-02 +534,415,0.037,,0,0,2009-07-02 +534,417,5,,0,0,2015-01-27 +534,418,0.27,,0,0,2015-01-16 +534,430,85.9,,0,0,2009-07-02 +534,431,0,,0,0,2009-07-02 +534,501,0.07,,0,0,2005-03-22 +534,502,0.176,,0,0,2005-03-22 +534,503,0.253,,0,0,2005-03-22 +534,504,0.431,,0,0,2005-03-22 +534,505,0.416,,0,0,2005-03-22 +534,506,0.131,,0,0,2005-03-22 +534,507,0.024,,0,0,2005-03-22 +534,508,0.244,,0,0,2005-03-22 +534,509,0.29,,0,0,2005-03-22 +534,510,0.349,,0,0,2005-03-22 +534,511,0.159,,0,0,2005-03-22 +534,512,0.17,,0,0,2005-03-22 +534,513,0.144,,0,0,2005-03-22 +534,514,0.322,,0,0,2005-03-22 +534,515,1.164,,0,0,2005-03-22 +534,516,0.091,,0,0,2005-03-22 +534,517,0.472,,0,0,2005-03-22 +534,518,0.256,,0,0,2005-03-22 +534,601,31,,0,0,2009-07-02 +534,605,1.34,0,0,0,2015-04-24 +534,606,8.275,,2,0,2009-07-02 +534,607,0.017,,0,0,2009-07-02 +534,608,0.008,,0,0,2009-07-02 +534,609,0.006,,0,0,2009-07-02 +534,610,0.014,,0,0,2009-07-02 +534,611,0.013,,0,0,2009-07-02 +534,612,0.084,,0,0,2009-07-02 +534,613,5.319,,0,0,2009-07-02 +534,614,2.437,,0,0,2009-07-02 +534,617,13.112,,0,0,2009-07-02 +534,618,24.317,,0,0,2009-07-02 +534,619,3.196,,0,0,2009-07-02 +534,620,0.01,,0,0,2009-07-02 +534,621,0.003,,0,0,2009-07-02 +534,626,0.045,,0,0,2009-07-02 +534,627,0,,0,0,2009-07-02 +534,628,0.113,,0,0,2009-07-02 +534,629,0,,0,0,2009-07-02 +534,630,0,,0,0,2009-07-02 +534,631,0,,0,0,2009-07-02 +534,645,13.279,,0,0,2009-07-02 +534,646,27.545,,0,0,2009-07-02 +534,806,5,,0,0,2015-01-16 +534,814,14,,0,0,2015-01-16 +534,815,5,,0,0,2015-01-16 +534,825,24.31,,0,14,2009-07-17 +534,827,0,,0,12,2009-07-17 +534,831,3.19,,0,14,2009-07-17 +534,832,0,,0,12,2008-12-11 +534,834,1,,0,0,2009-07-02 +534,835,1,,0,0,2009-07-02 +534,836,0,,0,0,2009-07-02 +534,837,26,,0,0,2009-07-02 +534,840,0,,,12,2010-06-03 +534,852,0,,,12,2010-06-03 +534,854,0,,0,12,2009-05-01 +534,855,0.01,,0,0,2009-07-17 +534,861,0,,0,12,2009-05-01 +534,862,17.9,,0,0,2010-06-11 +534,863,2.5,,0,0,2010-06-11 +534,868,3.19,,,2,2009-09-17 +534,869,24.32,,,2,2009-09-17 +534,874,0,,0,0,2015-01-16 +2000,203,1.53,,0,0,1997-05-01 +2000,204,0.22,,0,0,1997-05-01 +2000,205,1.92,,0,0,1997-05-01 +2000,207,0.57,,,106,2008-11-05 +2000,208,12,,0,0,1997-05-01 +2000,221,0,,,12,2004-10-05 +2000,255,95.92,,0,0,1997-05-01 +2000,262,0,,,12,2004-10-05 +2000,263,0,,,12,2004-10-05 +2000,268,50,,0,0,2002-12-20 +2000,291,1,,0,0,2001-06-14 +2000,301,12,,0,0,1997-05-01 +2000,303,0.24,,0,0,1997-05-01 +2000,304,3,,0,0,1997-05-01 +2000,305,20,,0,0,1997-05-01 +2000,306,533,45.174,7,0,2009-07-02 +2000,307,4,,0,0,1997-05-01 +2000,309,0.47,,0,0,1997-05-01 +2000,312,0.082,,0,0,2009-07-02 +2000,315,0.113,,0,0,2009-07-02 +2000,317,0.4,,0,0,2001-02-26 +2000,319,0,,,2,2002-11-13 +2000,321,0,,,2,2002-11-13 +2000,323,0.63,,,5,2005-12-19 +2000,324,0,,0,0,2010-03-25 +2000,339,0,,0,0,2010-03-25 +2000,401,0,,0,0,1997-05-01 +2000,404,0.02,,0,0,1997-05-01 +2000,405,0.05,,0,0,1997-05-01 +2000,406,0.3,,0,0,1997-05-01 +2000,409,0.567,0,0,4,2009-07-24 +2000,410,0.066,,0,0,2009-07-02 +2000,415,0.098,,0,0,2009-07-02 +2000,417,2,,0,0,2002-08-29 +2000,418,0,,0,0,1997-05-01 +2000,431,0,,0,0,2002-08-29 +2000,501,0.016,,0,0,2009-07-02 +2000,502,0.05,,0,0,1997-05-01 +2000,503,0.051,,0,0,2009-07-02 +2000,504,0.082,,0,0,2009-07-02 +2000,505,0.079,,0,0,2009-07-02 +2000,506,0.017,,0,0,2009-07-02 +2000,507,0.013,,0,0,2009-07-02 +2000,508,0.053,,0,0,2009-07-02 +2000,510,0.062,,0,0,2009-07-02 +2000,511,0.057,,0,0,2009-07-02 +2000,512,0.025,,0,0,2009-07-02 +2000,513,0.072,,0,0,2009-07-02 +2000,514,0.249,,0,0,2009-07-02 +2000,515,0.145,,0,0,2009-07-02 +2000,516,0.051,,0,0,2009-07-02 +2000,517,0.129,,0,0,2009-07-02 +2000,518,0.075,,0,0,2009-07-02 +2000,601,0,,0,0,1997-05-01 +2000,606,0.051,,0,0,2009-07-02 +2000,611,0.001,,0,0,1997-05-01 +2000,612,0.002,,0,0,1997-05-01 +2000,613,0.038,,0,0,2009-07-02 +2000,614,0.004,,0,0,1997-05-01 +2000,617,0.005,,0,0,1997-05-01 +2000,618,0.083,,0,0,2009-07-02 +2000,619,0.015,,0,0,2009-07-02 +2000,621,0,,,12,2009-04-09 +2000,631,0,,,12,2009-06-02 +2000,645,0.005,,0,0,1997-05-01 +2000,646,0.098,,0,0,2009-07-02 +2000,806,2,,0,0,2002-08-29 +2000,814,0,,0,0,2004-04-26 +2000,815,2,,0,4,2005-01-17 +2000,831,0.015,,,14,2009-06-02 +2000,832,0,,,12,2009-06-02 +2000,854,0,,,12,2009-06-02 +2000,861,0,,,12,2009-06-02 +4000,203,7.9,,0,0,1997-05-01 +4000,204,14.1,,0,0,1997-05-01 +4000,205,32.9,,0,0,1997-05-01 +4000,207,3.1,,0,0,1997-05-01 +4000,208,291,,0,0,1997-05-01 +4000,221,0,,,12,2004-10-05 +4000,255,42,,0,0,1997-05-01 +4000,262,0,,,12,2004-10-05 +4000,263,0,,,12,2004-10-05 +4000,268,1218,,0,0,2009-07-02 +4000,291,1.5,,,102,2005-07-14 +4000,301,255,,0,0,1997-05-01 +4000,303,2.31,,0,0,1997-05-01 +4000,304,19,,0,0,1997-05-01 +4000,305,190,,0,0,1997-05-01 +4000,306,159,,0,0,1997-05-01 +4000,307,511,,0,0,1997-05-01 +4000,309,0.68,,0,0,1997-05-01 +4000,312,0.062,,0,0,2009-07-02 +4000,315,0.265,,0,0,2009-07-02 +4000,317,46.2,,0,0,2001-03-13 +4000,319,64,,,0,2004-06-15 +4000,321,10,,,2,2002-11-13 +4000,324,14,,,102,2004-11-30 +4000,339,0.4,,,102,2004-11-30 +4000,401,0.4,,0,0,1997-05-01 +4000,404,0.263,,0,0,2009-07-02 +4000,405,0.347,,0,0,2009-07-02 +4000,406,2.073,,0,0,2009-07-02 +4000,409,3.723,0,0,4,2009-07-24 +4000,410,0.485,,0,0,2009-07-02 +4000,415,0.056,,0,0,2009-07-02 +4000,417,46,,0,0,2001-07-12 +4000,418,0.25,,0,0,1997-05-01 +4000,431,31,,0,0,2001-12-10 +4000,501,0.099,,0,0,2009-07-02 +4000,502,0.289,,0,0,2009-07-02 +4000,503,0.362,,0,0,2009-07-02 +4000,504,0.63,,0,0,1997-05-01 +4000,505,0.384,,0,0,2009-07-02 +4000,506,0.179,,0,0,2009-07-02 +4000,507,0.145,,0,0,2009-07-02 +4000,508,0.395,,0,0,2009-07-02 +4000,509,0.293,,0,0,2009-07-02 +4000,510,0.409,,0,0,2009-07-02 +4000,511,0.345,,0,0,2009-07-02 +4000,512,0.187,,0,0,2009-07-02 +4000,513,0.301,,0,0,2009-07-02 +4000,514,0.509,,0,0,2009-07-02 +4000,515,1.989,,0,0,2009-07-02 +4000,516,0.247,,0,0,2009-07-02 +4000,517,0.726,,0,0,2009-07-02 +4000,518,0.447,,0,0,2009-07-02 +4000,601,69,,0,0,1997-05-01 +4000,606,2.866,,0,0,2009-07-02 +4000,607,0.041,,0,0,2009-07-02 +4000,608,0.025,,0,0,2009-07-02 +4000,609,0.014,,0,0,2009-07-02 +4000,610,0.032,,0,0,2009-07-02 +4000,611,0.036,,0,0,2009-07-02 +4000,612,0.145,,0,0,2009-07-02 +4000,613,1.865,,0,0,2009-07-02 +4000,614,0.696,,0,0,2009-07-02 +4000,617,3.395,,0,0,2009-07-02 +4000,618,5.975,,0,0,2009-07-02 +4000,619,0.782,,0,0,2009-07-02 +4000,620,0.021,,0,0,2009-07-02 +4000,621,0.006,,0,0,1997-05-01 +4000,626,0.096,,0,0,2009-07-02 +4000,627,0,,0,0,1997-05-01 +4000,628,0.026,,0,0,2009-07-02 +4000,629,0.001,,0,0,1997-05-01 +4000,630,0,,0,0,1997-05-01 +4000,631,0,,0,0,1997-05-01 +4000,645,3.521,,0,0,2009-07-02 +4000,646,6.785,,0,0,2009-07-02 +4000,806,15,,0,0,2001-11-15 +4000,814,65,,0,0,2004-04-26 +4000,815,68,,0,4,2010-04-27 +4000,827,0,,0,12,2009-07-10 +4000,831,0.78,,0,14,2009-07-10 +4000,832,0,,0,12,2009-07-10 +4000,854,0,,0,12,2009-07-10 +4000,861,0,,0,12,2009-07-10 +501999,203,7.49,,,102,2009-07-20 +501999,204,15.31,,,102,2009-07-20 +501999,205,15.25,,,102,2009-07-20 +501999,207,2.57,,,102,2009-07-20 +501999,208,226,,,102,2009-07-20 +501999,221,0,,,102,2009-07-20 +501999,255,59.39,,,102,2009-07-20 +501999,262,0,,,102,2009-07-20 +501999,263,0,,,102,2009-07-20 +501999,268,945,,0,2,2009-07-20 +501999,291,1.1,,,102,2009-07-20 +501999,301,176,,,102,2009-07-20 +501999,303,0.67,,,102,2009-07-20 +501999,304,18,,,102,2009-07-20 +501999,305,168,,,102,2009-07-20 +501999,306,277,,,102,2009-07-20 +501999,307,614,,,102,2009-07-20 +501999,309,1.22,,,102,2009-07-20 +501999,312,0.097,,,102,2009-07-20 +501999,315,0.168,,,102,2009-07-20 +501999,317,3.4,,,102,2009-07-20 +501999,319,57,,,102,2009-07-20 +501999,321,20,,,102,2009-07-20 +501999,323,0.71,,,102,2009-07-20 +501999,324,3,,,102,2010-04-19 +501999,339,0,,,102,2010-04-19 +501999,401,7,,,102,2009-07-20 +501999,404,0.048,,,102,2009-07-20 +501999,405,0.119,,,102,2009-07-20 +501999,406,1.189,,,102,2009-07-20 +501999,409,2.563,,,2,2009-07-20 +501999,410,0.337,,,102,2009-07-20 +501999,415,0.102,,,102,2009-07-20 +501999,417,19,,,102,2009-07-20 +501999,418,0.228,,,102,2009-07-20 +501999,431,0,,,102,2009-07-20 +501999,601,24,,,102,2009-07-20 +501999,605,1.884,,,102,2009-07-20 +501999,606,6.02,,,102,2009-07-20 +501999,613,3.003,,,102,2009-07-20 +501999,614,1.335,,,102,2009-07-20 +501999,617,6.283,,,102,2009-07-20 +501999,618,1.478,,,102,2009-07-20 +501999,619,0.398,,,102,2009-07-20 +501999,621,0,,,102,2009-07-20 +501999,628,0.059,,,102,2009-07-20 +501999,631,0,,,102,2009-07-20 +501999,645,6.763,,,102,2009-07-20 +501999,646,1.898,,,102,2009-07-20 +501999,806,19,,,102,2009-07-20 +501999,814,59,,,102,2009-07-20 +501999,815,19,,,2,2009-07-20 +501999,831,0.399,,,102,2009-07-20 +501999,832,0,,,102,2009-07-20 +501999,854,0,,,102,2009-07-20 +501999,861,0,,,102,2009-07-20 diff --git a/packages/food-data/fixtures/fineli/component_value.csv b/packages/food-data/fixtures/fineli/component_value.csv new file mode 100644 index 0000000..90c7622 --- /dev/null +++ b/packages/food-data/fixtures/fineli/component_value.csv @@ -0,0 +1,476 @@ +FOODID;EUFDNAME;BESTLOC;ACQTYPE;METHTYPE;METHIND +1;ENERC;1698,30;S;S;MI0107 +1;FAT;0;F;E;MIR003 +1;CHOAVL;99,900;S;S;MI0181 +1;CHOCDF;99,880;S;S;MI0131 +1;PROT;0;L;P;MIR003 +1;ALC;0;F;U;MIR007 +1;ASH;0,020;D;AG;MI1018 +1;WATER;0,10;F;E;MIR003 +1;OA;0;S;IG;MIR003 +1;SUGOH;0;S;U;MIR007 +1;SUGAR;99,900;S;S;MI0151 +1;FRUS;0;S;IG;MIR003 +1;GALS;0;S;U;MIR007 +1;GLUS;0;S;IG;MIR003 +1;LACS;0;S;U;MIR003 +1;MALS;0;S;IG;MIR007 +1;SUCS;99,900;S;CG;MIR002 +1;STARCH;0;S;U;MIR003 +1;FIBC;0;S;U;MIR003 +1;FIBT;0;S;S;MI0172 +1;FIBINS;0;S;S;MIR006 +1;PSACNCS;0;S;U;MIR003 +1;FOL;0;F;E;MIR003 +1;NIAEQ;0;F;E;MIR003 +1;NIA;0;S;I;MIR003 +1;VITPYRID;0;S;S;MIR005 +1;RIBF;0;F;E;MIR003 +1;THIA;0;F;E;MIR003 +1;VITA;0;S;S;MI0324 +1;RETOL;0;S;U;MIR003 +1;CAROTENS;0;S;S;MI0302 +1;CARTB;0;S;U;MIR003 +1;VITB12;0;F;E;MIR003 +1;VITC;0;F;E;MIR003 +1;VITD;0;F;E;MIR003 +1;VITE;0;S;S;MI0368 +1;VITK;0;S;IG;MIR003 +1;CA;0,40;F;E;MIR003 +1;CR;1,00;F;E;MIR003 +1;CU;0,0100;F;E;MIR003 +1;FD;0,050;F;E;MIR003 +1;FE;0,060;F;E;MIR003 +1;ID;5,00;F;E;MIR003 +1;K;2,00;F;E;MIR003 +1;MG;0,100;F;E;MIR003 +1;MN;0,0100;F;E;MIR003 +1;MO;0,0100;F;E;MIR003 +1;NA;0,10;F;E;MIR003 +1;NACL;0,25;S;T;MIR005 +1;NT;0;S;U;MIR007 +1;P;0,1;F;E;MIR003 +1;SE;0,500;D;AG;MI1006 +1;ZN;0,010;F;E;MIR003 +1;FAFRE;0;S;S;MI0202 +1;FACIDCTG;0;S;S;MIR005 +1;FAPU;0;S;S;MI0213 +1;FAMCIS;0;S;S;MI0210 +1;FASAT;0;S;S;MI0209 +1;FATRN;0;S;S;MIR006 +1;FAPUN3;0;S;S;MI0216 +1;FAPUN6;0;S;S;MIR006 +1;FAS18;0;S;S;MIR006 +1;F16D0T;0;S;S;MIR006 +1;F18D1T;0;S;S;MIR006 +1;F18D2CN6;0;S;U;MIR003 +1;F18D3N3;0;S;U;MIR003 +1;F20D4N6;0;S;U;MIR003 +1;F20D5N3;0;S;U;MIR003 +1;F22D6N3;0;S;U;MIR003 +1;CHOLE;0;S;IG;MIR003 +1;STERT;0;S;S;MIR006 +1;TRP;0;S;IG;MIR003 +1;MYRIC;0;S;IG;MIR003 +1;QUERCE;0;S;IG;MIR003 +1013;ENERC;620,87;S;R;MI0002 +1013;FAT;3,202;S;R;MI0002 +1013;CHOAVL;24,277;S;R;MI0002 +1013;CHOCDF;27,482;S;R;MI0002 +1013;PROT;4,22;S;R;MI0002 +1013;ALC;0;S;R;MI0002 +1013;ASH;1,369;S;R;MI0002 +1013;WATER;82,30;S;R;MI0002 +1013;OA;0,111;S;R;MI0002 +1013;SUGOH;0;S;R;MI0002 +1013;SUGAR;2,998;S;R;MI0002 +1013;FRUS;0,038;S;R;MI0002 +1013;GALS;0,000;S;R;MI0002 +1013;GLUS;0,044;S;R;MI0002 +1013;LACS;2,667;S;R;MI0002 +1013;MALS;0,10;S;R;MI0002 +1013;SUCS;0,150;S;R;MI0002 +1013;STARCH;21,28;S;R;MI0002 +1013;FIBC;2,062;S;R;MI0002 +1013;FIBT;2,028;S;R;MI0002 +1013;FIBINS;1,71;S;R;MI0002 +1013;PSACNCS;0,32;S;R;MI0002 +1013;FOL;8,45;S;R;MI0002 +1013;NIAEQ;1,191;S;R;MI0002 +1013;NIA;0,332;S;R;MI0002 +1013;VITPYRID;0,06;S;R;MI0002 +1013;RIBF;0,125;S;R;MI0002 +1013;THIA;0,0561;S;R;MI0002 +1013;VITA;14,924;S;R;MI0002 +1013;RETOL;14,28;S;R;MI0002 +1013;CAROTENS;31,5;S;R;MI0002 +1013;CARTB;7,78;S;R;MI0002 +1013;VITB12;0,22;S;R;MI0002 +1013;VITC;0,61;S;R;MI0002 +1013;VITD;0,657;S;R;MI0002 +1013;VITE;0,505;S;R;MI0002 +1013;VITK;2,980;S;R;MI0002 +1013;CA;74,61;S;R;MI0002 +1013;CR;0,95;S;R;MI0002 +1013;CU;0,0970;S;R;MI0002 +1013;FD;0,030;S;R;MI0002 +1013;FE;0,627;S;R;MI0002 +1013;ID;26,86;S;R;MI0002 +1013;K;160,39;S;R;MI0002 +1013;MG;23,685;S;R;MI0002 +1013;MN;0,3931;S;R;MI0002 +1013;MO;0,0074;S;R;MI0002 +1013;NA;297,51;S;R;MI0002 +1013;NACL;758,07;S;R;MI0002 +1013;NT;0,675;S;R;MI0002 +1013;P;107,7;S;R;MI0002 +1013;SE;4,852;S;R;MI0002 +1013;ZN;0,786;S;R;MI0002 +1013;FAFRE;2,970;S;R;MI0002 +1013;FACIDCTG;3,094;S;R;MI0002 +1013;FAPU;0,713;S;R;MI0002 +1013;FAMCIS;1,2116;S;R;MI0002 +1013;FASAT;1,0093;S;R;MI0002 +1013;FATRN;0,0210;S;R;MI0002 +1013;FAPUN3;0,1657;S;R;MI0002 +1013;FAPUN6;0,538;S;R;MI0002 +1013;FAS18;0,1677;S;R;MI0002 +1013;F16D0T;484,525;S;R;MI0002 +1013;F18D1T;1140,919;S;R;MI0002 +1013;F18D2CN6;537,706;S;R;MI0002 +1013;F18D3N3;165,654;S;R;MI0002 +1013;F20D4N6;0;S;R;MI0002 +1013;F20D5N3;0;S;R;MI0002 +1013;F22D6N3;0;S;R;MI0002 +1013;CHOLE;4,42;S;R;MI0002 +1013;STERT;28,25;S;R;MI0002 +1013;TRP;56,2;S;R;MI0002 +1013;MYRIC;0;S;R;MI0002 +1013;QUERCE;0;S;R;MI0002 +1036;ENERC;1046,29;S;R;MI0002 +1036;FAT;1,325;S;R;MI0002 +1036;CHOAVL;46,971;S;R;MI0002 +1036;CHOCDF;57,138;S;R;MI0002 +1036;PROT;7,88;S;R;MI0002 +1036;ALC;0;S;R;MI0002 +1036;ASH;2,140;S;R;MI0002 +1036;WATER;25,91;S;R;MI0002 +1036;OA;0;S;R;MI0002 +1036;SUGOH;0;S;R;MI0002 +1036;SUGAR;1,060;S;R;MI0002 +1036;FRUS;0,174;S;R;MI0002 +1036;GALS;0;S;R;MI0002 +1036;GLUS;0,179;S;R;MI0002 +1036;LACS;0;S;R;MI0002 +1036;MALS;0,25;S;R;MI0002 +1036;SUCS;0,461;S;R;MI0002 +1036;STARCH;45,91;S;R;MI0002 +1036;FIBC;8,108;S;R;MI0002 +1036;FIBT;7,907;S;R;MI0002 +1036;FIBINS;6,54;S;R;MI0002 +1036;PSACNCS;1,37;S;R;MI0002 +1036;FOL;36,32;S;R;MI0002 +1036;NIAEQ;1,864;S;R;MI0002 +1036;NIA;0,562;S;R;MI0002 +1036;VITPYRID;0,12;S;R;MI0002 +1036;RIBF;0,120;S;R;MI0002 +1036;THIA;0,1497;S;R;MI0002 +1036;VITA;0,325;S;R;MI0002 +1036;RETOL;0;S;R;MI0002 +1036;CAROTENS;159,0;S;R;MI0002 +1036;CARTB;3,90;S;R;MI0002 +1036;VITB12;0;S;R;MI0002 +1036;VITC;0;S;R;MI0002 +1036;VITD;0;S;R;MI0002 +1036;VITE;0,613;S;R;MI0002 +1036;VITK;3,247;S;R;MI0002 +1036;CA;23,58;S;R;MI0002 +1036;CR;1,28;S;R;MI0002 +1036;CU;0,2472;S;R;MI0002 +1036;FD;0,043;S;R;MI0002 +1036;FE;2,014;S;R;MI0002 +1036;ID;5,07;S;R;MI0002 +1036;K;275,89;S;R;MI0002 +1036;MG;56,748;S;R;MI0002 +1036;MN;1,1665;S;R;MI0002 +1036;MO;0,0077;S;R;MI0002 +1036;NA;465,46;S;R;MI0002 +1036;NACL;1185,98;S;R;MI0002 +1036;NT;1,260;S;R;MI0002 +1036;P;189,4;S;R;MI0002 +1036;SE;4,423;S;R;MI0002 +1036;ZN;1,760;S;R;MI0002 +1036;FAFRE;0,938;S;R;MI0002 +1036;FACIDCTG;0,975;S;R;MI0002 +1036;FAPU;0,600;S;R;MI0002 +1036;FAMCIS;0,1738;S;R;MI0002 +1036;FASAT;0,1635;S;R;MI0002 +1036;FATRN;0;S;R;MI0002 +1036;FAPUN3;0,0685;S;R;MI0002 +1036;FAPUN6;0,532;S;R;MI0002 +1036;FAS18;0,0071;S;R;MI0002 +1036;F16D0T;147,603;S;R;MI0002 +1036;F18D1T;154,409;S;R;MI0002 +1036;F18D2CN6;531,962;S;R;MI0002 +1036;F18D3N3;68,462;S;R;MI0002 +1036;F20D4N6;0;S;R;MI0002 +1036;F20D5N3;0;S;R;MI0002 +1036;F22D6N3;0;S;R;MI0002 +1036;CHOLE;0;S;R;MI0002 +1036;STERT;60,39;S;R;MI0002 +1036;TRP;90,3;S;R;MI0002 +1036;MYRIC;0;S;R;MI0002 +1036;QUERCE;0;S;R;MI0002 +3327;ENERC;414,78;S;R;MI0002 +3327;FAT;5,370;S;R;MI0002 +3327;CHOAVL;7,556;S;R;MI0002 +3327;CHOCDF;9,530;S;R;MI0002 +3327;PROT;4,28;S;R;MI0002 +3327;ALC;0;S;R;MI0002 +3327;ASH;1,170;S;R;MI0002 +3327;WATER;81,83;S;R;MI0002 +3327;OA;0,352;S;R;MI0002 +3327;SUGOH;0;S;R;MI0002 +3327;SUGAR;3,237;S;R;MI0002 +3327;FRUS;0,949;S;R;MI0002 +3327;GALS;0,000;S;R;MI0002 +3327;GLUS;0,813;S;R;MI0002 +3327;LACS;1,303;S;R;MI0002 +3327;MALS;0,03;S;R;MI0002 +3327;SUCS;0,142;S;R;MI0002 +3327;STARCH;4,32;S;R;MI0002 +3327;FIBC;1,278;S;R;MI0002 +3327;FIBT;1,295;S;R;MI0002 +3327;FIBINS;0,92;S;R;MI0002 +3327;PSACNCS;0,37;S;R;MI0002 +3327;FOL;17,07;S;R;MI0002 +3327;NIAEQ;1,828;S;R;MI0002 +3327;NIA;0,869;S;R;MI0002 +3327;VITPYRID;0,14;S;R;MI0002 +3327;RIBF;0,104;S;R;MI0002 +3327;THIA;0,0743;S;R;MI0002 +3327;VITA;38,244;S;R;MI0002 +3327;RETOL;22,83;S;R;MI0002 +3327;CAROTENS;947,3;S;R;MI0002 +3327;CARTB;180,36;S;R;MI0002 +3327;VITB12;0,30;S;R;MI0002 +3327;VITC;10,30;S;R;MI0002 +3327;VITD;0,458;S;R;MI0002 +3327;VITE;0,693;S;R;MI0002 +3327;VITK;5,990;S;R;MI0002 +3327;CA;69,68;S;R;MI0002 +3327;CR;0,90;S;R;MI0002 +3327;CU;0,0387;S;R;MI0002 +3327;FD;0,015;S;R;MI0002 +3327;FE;0,494;S;R;MI0002 +3327;ID;13,67;S;R;MI0002 +3327;K;275,71;S;R;MI0002 +3327;MG;17,359;S;R;MI0002 +3327;MN;0,0908;S;R;MI0002 +3327;MO;0,0083;S;R;MI0002 +3327;NA;152,51;S;R;MI0002 +3327;NACL;388,59;S;R;MI0002 +3327;NT;0,685;S;R;MI0002 +3327;P;81,7;S;R;MI0002 +3327;SE;4,404;S;R;MI0002 +3327;ZN;0,697;S;R;MI0002 +3327;FAFRE;4,989;S;R;MI0002 +3327;FACIDCTG;5,179;S;R;MI0002 +3327;FAPU;0,822;S;R;MI0002 +3327;FAMCIS;2,1820;S;R;MI0002 +3327;FASAT;1,9170;S;R;MI0002 +3327;FATRN;0,0493;S;R;MI0002 +3327;FAPUN3;0,1904;S;R;MI0002 +3327;FAPUN6;0,612;S;R;MI0002 +3327;FAS18;0,4752;S;R;MI0002 +3327;F16D0T;978,082;S;R;MI0002 +3327;F18D1T;2020,674;S;R;MI0002 +3327;F18D2CN6;601,677;S;R;MI0002 +3327;F18D3N3;187,902;S;R;MI0002 +3327;F20D4N6;7,766;S;R;MI0002 +3327;F20D5N3;0;S;R;MI0002 +3327;F22D6N3;2,463;S;R;MI0002 +3327;CHOLE;17,49;S;R;MI0002 +3327;STERT;17,05;S;R;MI0002 +3327;TRP;56,8;S;R;MI0002 +3327;MYRIC;16,54;S;R;MI0002 +3327;QUERCE;57,82;S;R;MI0002 +11049;ENERC;366,42;S;S;MI0107 +11049;FAT;0,400;F;E;MIR003 +11049;CHOAVL;18,300;S;S;MI0181 +11049;CHOCDF;23,010;S;S;MI0131 +11049;PROT;1,20;D;AG;MI0123 +11049;ALC;0;F;E;MIR003 +11049;ASH;0,8;D;AG;MI1018 +11049;WATER;74,6;D;AG;MI1017 +11049;OA;0,440;S;S;MIR006 +11049;SUGOH;0;S;IG;MIR003 +11049;SUGAR;13,500;S;S;MI0151 +11049;FRUS;2,700;D;AG;MI1063 +11049;GLUS;4,400;D;AG;MI1063 +11049;LACS;0;S;U;MIR003 +11049;MALS;0;S;U;MIR003 +11049;SUCS;6,400;D;AG;MI1063 +11049;STARCH;4,80;D;AG;MI1063 +11049;FIBC;1,800;D;AG;MI1307 +11049;FIBT;1,700;S;S;MI0172 +11049;FIBINS;1,00;S;S;MIR006 +11049;PSACNCS;0,70;D;AG;MI1063 +11049;FOL;12,54;S;S;MIR005 +11049;NIAEQ;0,917;S;S;MI0421 +11049;NIA;0,7;F;E;MIR003 +11049;VITPYRID;0,50;F;E;MIR003 +11049;RIBF;0,060;F;E;MIR003 +11049;THIA;0,0400;F;E;MIR003 +11049;VITA;1,68;S;S;MI0324 +11049;RETOL;0;S;U;MIR003 +11049;CAROTENS;29,7;S;S;MI0302 +11049;CARTB;14,20;D;AG;MI1137 +11049;VITB12;0;F;E;MIR003 +11049;VITC;10,00;F;E;MIR003 +11049;VITD;0;F;E;MIR003 +11049;VITE;0,210;S;S;MI0368 +11049;VITK;0,500;F;E;MIR003 +11049;CA;6,20;D;AG;MI1144 +11049;CR;3,00;F;E;MIR003 +11049;CU;0,108;D;AG;MI1144 +11049;FD;0,010;F;E;MIR003 +11049;FE;1,00;D;AG;MI1144 +11049;ID;1,00;F;E;MIR003 +11049;K;358,4;D;AG;MI1144 +11049;MG;31,32;D;AG;MI1144 +11049;MN;0,2400;F;E;MIR003 +11049;MO;0,0050;F;E;MIR003 +11049;NA;5,0;D;AG;MI1144 +11049;NACL;12,74;S;T;MIR005 +11049;NT;0,19;D;AG;MI1039 +11049;P;24,9;D;AG;MI1144 +11049;SE;0,32;D;AG;MI1144 +11049;ZN;0,19;D;AG;MI1144 +11049;FAFRE;0,1078;S;S;MI0202 +11049;FACIDCTG;0,1127;S;S;MIR005 +11049;FAPU;0,0477;S;S;MI0213 +11049;FAMCIS;0,0140;S;S;MI0210 +11049;FASAT;0,0461;S;S;MI0209 +11049;FATRN;0;S;S;MIR006 +11049;FAPUN3;0,0196;S;S;MI0216 +11049;FAPUN6;0,0264;S;S;MIR006 +11049;FAS18;0,0020;S;S;MIR006 +11049;F16D0T;40,402;S;S;MIR006 +11049;F18D1T;10,578;S;S;MIR006 +11049;F18D2CN6;26,417;D;AG;MIR003 +11049;F18D3N3;19,638;D;AG;MIR003 +11049;F20D4N6;0;D;AG;MIR003 +11049;F20D5N3;0;D;AG;MIR003 +11049;F22D6N3;0;D;AG;MIR003 +11049;CHOLE;0;D;AG;MI1205 +11049;STERT;11,60;D;AG;MI1182 +11049;TRP;13,0;S;IG;MIR003 +11049;MYRIC;0;E;E;MIR003 +11049;QUERCE;0;E;E;MIR003 +35594;ENERC;93,67;S;S;MI0107 +35594;FAT;0,1;D;AG;MI1302 +35594;CHOAVL;4,810;S;S;MI0181 +35594;CHOCDF;57,600;S;S;MI0131 +35594;PROT;0,2;D;S;MI0123 +35594;ALC;0;S;U;MIR007 +35594;ASH;0,6;D;AG;MI1018 +35594;WATER;41,5;D;AG;MI1103 +35594;SUGAR;1,010;S;S;MI0151 +35594;FRUS;0,23;D;AG;MI1137 +35594;GALS;0,02;D;AG;MI1137 +35594;GLUS;0,24;D;AG;MI1137 +35594;LACS;0;D;AG;MI1137 +35594;MALS;0,02;D;AG;MI1137 +35594;SUCS;0,5;D;AG;MI1137 +35594;STARCH;3,8;D;AG;MI1302 +35594;FIBC;0,6;D;AG;MI1307 +35594;VITB12;0;S;U;MIR007 +35594;VITC;0,25;D;AG;MI1137 +35594;VITD;0;S;U;MIR007 +35594;CA;79;D;AG;MI1305 +35594;CU;0,05;D;AG;MI1305 +35594;FE;0,88;D;AG;MI1305 +35594;K;160;D;AG;MI1305 +35594;MG;48;D;AG;MI1305 +35594;NA;1,6;D;AG;MI1305 +35594;NACL;4,08;S;T;MIR005 +35594;NT;0,032;D;AG;MIR002 +35594;P;11;D;AG;MI1305 +35594;SE;10;D;AG;MI1209 +35594;ZN;0,11;D;AG;MI1305 +35594;CHOLE;0;S;U;MIR007 +35629;ENERC;233,32;S;R;MI0002 +35629;FAT;0,207;S;R;MI0002 +35629;CHOAVL;12,035;S;R;MI0002 +35629;CHOCDF;13,103;S;R;MI0002 +35629;PROT;0,55;S;R;MI0002 +35629;ALC;0;S;R;MI0002 +35629;ASH;0,463;S;R;MI0002 +35629;WATER;85,75;S;R;MI0002 +35629;OA;0,423;S;R;MI0002 +35629;SUGOH;0;S;R;MI0002 +35629;SUGAR;10,570;S;R;MI0002 +35629;FRUS;4,701;S;R;MI0002 +35629;GALS;0;S;R;MI0002 +35629;GLUS;2,878;S;R;MI0002 +35629;LACS;0;S;R;MI0002 +35629;MALS;0;S;R;MI0002 +35629;SUCS;2,992;S;R;MI0002 +35629;STARCH;1,46;S;R;MI0002 +35629;FIBC;0,775;S;R;MI0002 +35629;FIBT;0,408;S;R;MI0002 +35629;FIBINS;0,08;S;R;MI0002 +35629;PSACNCS;0,05;S;R;MI0002 +35629;FOL;10,75;S;R;MI0002 +35629;NIAEQ;0,873;S;R;MI0002 +35629;NIA;0,737;S;R;MI0002 +35629;VITPYRID;0,10;S;R;MI0002 +35629;RIBF;0,031;S;R;MI0002 +35629;THIA;0,0313;S;R;MI0002 +35629;VITA;11,547;S;R;MI0002 +35629;RETOL;0;S;R;MI0002 +35629;CAROTENS;174,7;S;R;MI0002 +35629;CARTB;135,44;S;R;MI0002 +35629;VITB12;0;S;R;MI0002 +35629;VITC;12;L;P;MIR003 +35629;VITD;0,75;L;P;MIR003 +35629;VITE;0,327;S;R;MI0002 +35629;VITK;1,739;S;R;MI0002 +35629;CA;9,85;S;R;MI0002 +35629;CR;2,21;S;R;MI0002 +35629;CU;0,0585;S;R;MI0002 +35629;FD;0,005;S;R;MI0002 +35629;FE;0,348;S;R;MI0002 +35629;ID;0,86;S;R;MI0002 +35629;K;157,76;S;R;MI0002 +35629;MG;9,719;S;R;MI0002 +35629;MN;0,2375;S;R;MI0002 +35629;MO;0,0037;S;R;MI0002 +35629;NA;2,65;S;R;MI0002 +35629;NACL;6,75;S;R;MI0002 +35629;NT;0,079;S;R;MI0002 +35629;P;14,8;S;R;MI0002 +35629;SE;0,462;S;R;MI0002 +35629;ZN;0,076;S;R;MI0002 +35629;FAFRE;0,132;S;R;MI0002 +35629;FACIDCTG;0,138;S;R;MI0002 +35629;FAPU;0,067;S;R;MI0002 +35629;FAMCIS;0,0309;S;R;MI0002 +35629;FASAT;0,0342;S;R;MI0002 +35629;FATRN;0;S;R;MI0002 +35629;FAPUN3;0,0158;S;R;MI0002 +35629;FAPUN6;0,051;S;R;MI0002 +35629;FAS18;0,0020;S;R;MI0002 +35629;F16D0T;28,866;S;R;MI0002 +35629;F18D1T;18,901;S;R;MI0002 +35629;F18D2CN6;51,213;S;R;MI0002 +35629;F18D3N3;15,781;S;R;MI0002 +35629;F20D4N6;0;S;R;MI0002 +35629;F20D5N3;0;S;R;MI0002 +35629;F22D6N3;0;S;R;MI0002 +35629;CHOLE;0;S;R;MI0002 +35629;STERT;8,77;S;R;MI0002 +35629;TRP;7,5;S;R;MI0002 +35629;MYRIC;124,95;S;R;MI0002 +35629;QUERCE;1298,81;S;R;MI0002 diff --git a/packages/food-data/fixtures/fineli/food.csv b/packages/food-data/fixtures/fineli/food.csv new file mode 100644 index 0000000..e69202d --- /dev/null +++ b/packages/food-data/fixtures/fineli/food.csv @@ -0,0 +1,9 @@ +FOODID;FOODNAME;FOODTYPE;PROCESS;EDPORT;IGCLASS;IGCLASSP;FUCLASS;FUCLASSP +1;SOKERI;FOOD;IND;100;SUGARSYR;SUGARTOT;SUGADD;SUGARTOT +1013;KARJALANPIIRAKKA, PERINTEINEN, VOIDELTU, RIISI, RUISVEHNÄKUORI;DISH;BAK;100;DISH;NONINGR;BAKSALT;CEBAKTOT +1036;RUISLEIPÄ, RUISTA 51%;DISH;BAK;100;DISH;NONINGR;BRRYE;CEBAKTOT +3327;MOUSSAKA, JAUHELIHA-MUNAKOISOVUOKA, SIKA-NAUTA;DISH;BAK;100;DISH;NONINGR;MEATDISH;MEATDTOT +11049;BANAANI, KUORITTU;FOOD;RAW;100;FRUITOTH;FRUITTOT;FRUFRESH;FRUDITOT +11184;KANELI;FOOD;DRIE;100;FLAVSEED;FLAVTOT;SPICES;MISCTOT +35594;MUSTAHERUKANLEHTIUUTE, ALKOHOLITON KASVIGLYSERIINIUUTE, GROSELLERO;FOOD;IND;100;HERBSUP;DIETTOT;SPECSUPP;SPECTOT +35629;SMOOTHIE, MARLI HEDELMÄINEN SMOOTHIE + D&C-VITAMIINIT;DISH;IND;100;JUICE;FRUITTOT;FRUBJUIC;FRUDITOT diff --git a/packages/food-data/fixtures/fineli/foodaddunit.csv b/packages/food-data/fixtures/fineli/foodaddunit.csv new file mode 100644 index 0000000..a77be66 --- /dev/null +++ b/packages/food-data/fixtures/fineli/foodaddunit.csv @@ -0,0 +1,41 @@ +FOODID;FOODUNIT;MASS +1;PORTM;4,00 +1;PORTL;8,00 +1;KPL_S;2,00 +1;KPL_M;3,00 +1;KPL_L;4,00 +1;DL;85,00 +1;RKL;12,00 +1;TL;4,00 +1;PORTS;2,00 +1013;KPL_S;35,00 +1013;KPL_M;60,00 +1013;KPL_L;90,00 +1013;PORTS;40,00 +1013;PORTM;80,00 +1013;PORTL;130,00 +1036;KPL_S;20,00 +1036;KPL_M;30,00 +1036;KPL_L;40,00 +1036;PORTS;20,00 +1036;PORTM;35,00 +1036;PORTL;50,00 +3327;DL;100,00 +3327;PORTS;220,00 +3327;PORTL;350,00 +3327;PORTM;300,00 +11049;KPL_S;100,00 +11049;KPL_M;125,00 +11049;KPL_L;150,00 +11049;PORTL;250,00 +11049;PORTM;125,00 +11049;PORTS;100,00 +35594;PORTS;0,90 +35594;PORTM;1,80 +35594;PORTL;2,70 +35629;PORTL;300,00 +35629;PORTM;200,00 +35629;TL;5,00 +35629;RKL;15,00 +35629;DL;100,00 +35629;PORTS;100,00 diff --git a/packages/food-data/fixtures/fineli/foodname_EN.csv b/packages/food-data/fixtures/fineli/foodname_EN.csv new file mode 100644 index 0000000..820a63c --- /dev/null +++ b/packages/food-data/fixtures/fineli/foodname_EN.csv @@ -0,0 +1,9 @@ +FOODID;FOODNAME;LANG +1;SUGAR;EN +1013;KARELIAN PASTY, RICE FILLING;EN +1036;RYE BREAD, 51% RYE;EN +3327;MOUSSAKA, PORK BEEF MINCE;EN +11049;BANANA, WITHOUT SKIN;EN +11184;CINNAMON;EN +35594;BLACK CURRANT LEAF EXTRACT, NON-ALCOHOLIC VEGETABLE GLYCERIN EXTRACT, GROSELLERO;EN +35629;SMOOTHIE, MARLI SMOOTHIE, FRUIT +VITAMINS D&C;EN diff --git a/packages/food-data/fixtures/fineli/foodname_FI.csv b/packages/food-data/fixtures/fineli/foodname_FI.csv new file mode 100644 index 0000000..31d5a57 --- /dev/null +++ b/packages/food-data/fixtures/fineli/foodname_FI.csv @@ -0,0 +1,9 @@ +FOODID;FOODNAME;LANG +1;SOKERI;FI +1013;KARJALANPIIRAKKA, PERINTEINEN, VOIDELTU, RIISI, RUISVEHNÄKUORI;FI +1036;RUISLEIPÄ, RUISTA 51%;FI +3327;MOUSSAKA, JAUHELIHA-MUNAKOISOVUOKA, SIKA-NAUTA;FI +11049;BANAANI, KUORITTU;FI +11184;KANELI;FI +35594;MUSTAHERUKANLEHTIUUTE, ALKOHOLITON KASVIGLYSERIINIUUTE, GROSELLERO;FI +35629;SMOOTHIE, MARLI HEDELMÄINEN SMOOTHIE + D&C-VITAMIINIT;FI diff --git a/packages/food-data/fixtures/fineli/foodname_SV.csv b/packages/food-data/fixtures/fineli/foodname_SV.csv new file mode 100644 index 0000000..f04a267 --- /dev/null +++ b/packages/food-data/fixtures/fineli/foodname_SV.csv @@ -0,0 +1,9 @@ +FOODID;FOODNAME;LANG +1;SOCKER;SV +1013;KARELSK PIROG, TRADITIONELL, PENSLAD, RIS, RÅGVETESKAL;SV +1036;RÅGBRÖD, RÅG 51 %;SV +3327;MOUSSAKA, ÄGGPLANTA, GRIS-NÖTFÄRS;SV +11049;BANAN, SKALAD;SV +11184;KANEL;SV +35594;SVARTVINBÄRSLÖV EXTRAKT, ALKOHOLFRITT GLYCERIN EXTRAKT, GROSELLERO;SV +35629;SMOOTHIE, MARLI SMOOTHIE, FRUKT + D&C-VITAMINER;SV diff --git a/packages/food-data/fixtures/fineli/fuclass_EN.csv b/packages/food-data/fixtures/fineli/fuclass_EN.csv new file mode 100644 index 0000000..859268f --- /dev/null +++ b/packages/food-data/fixtures/fineli/fuclass_EN.csv @@ -0,0 +1,176 @@ +THSCODE;DESCRIPT;LANG +FRUDITOT;Fruit and berry dishes;EN +FRUFRESH;Fruits;EN +FRUBSAL;Fruit and berry salads;EN +BERFRESH;Berries;EN +FRUBSOUP;Fruit and berry soups;EN +FRUBDISH;Fruit and berry dishes other than pies;EN +FRUBJUIC;Juices;EN +FRUBPAST;POISTETTU_Berry and fruit pies;EN +LEGUTOT;Pulses and pulse dishes;EN +LEGUMES;Pulses;EN +LEGUPROD;Pulse products;EN +LEGUDISH;Pulse dishes;EN +LEGUSOUP;Pulse soups;EN +LEGUSAUC;Pulse sauces;EN +VEGDITOT;Vegetable dishes;EN +VEGFRESH;Vegetables;EN +VEGPOT;Cooked vegetables;EN +VEGDISH;Vegetable dishes;EN +VEGSOUP;Vegetable soups;EN +VEGSAUC;Vegetable sauces;EN +MUSHRDI;Mushroom dishes;EN +VEGCANN;Canned vegetables;EN +VEGJUICE;Vegetable juices;EN +VEGCASS;POISTETTU_Vegetable casseroles;EN +SALADTOT;Prepared salads;EN +SALADVEG;Vegetable salads;EN +SALADMIX;Mixed salads;EN +SALADMAY;Prepared salads with mayonnaise;EN +POTATOT;Potatoes;EN +POTACOOK;Cooked potatoes;EN +POTADISH;Potato dishes;EN +POTAFRIE;Fried potatoes, French fries;EN +POTAFAT;POISTETTU_Fried or creamy potatoes;EN +CEBAKTOT;Cereals and cereal products;EN +BRMIX;Bread, mixed flour;EN +BRWHITE;Wheat bread;EN +BRRYE;Rye bread;EN +BUN;Buns;EN +BAKSWEET;Sweet bakery;EN +BAKSALT;Savoury bakery;EN +PANCAKE;Panncakes;EN +SANDWICH;Sandwiches and burgers;EN +BISCUSWE;Sweet biscuits;EN +BISCUSAV;Savoury biscuits;EN +RICEADD;Rice;EN +PASTAADD;Pasta;EN +PORR;Porridge;EN +CERBRKF;Breakfast cereals;EN +CERBAR;Cereal bars;EN +PIZZA;Pizza;EN +FLOUR;Flour;EN +BISCUIT;POISTETTU_Biscuits;EN +CERPR;POISTETTU_Pies and other cereal products;EN +MILKDTOT;Milk dishes;EN +MILKFF;Milks skimmed;EN +MILKLF;Milks <2% fat;EN +MILKHF;Milks >2% fat;EN +SMILK;Soured milks;EN +CREAM;Cream;EN +YOGHURT;Yoghurt;EN +MILKCURL;Cultured milks;EN +CURD;Quark;EN +SOUCREAM;Fermented milk products, other;EN +CHEESCUR;Cheese, ripened cheese ;EN +CHEESUNC;Cheese, unripened, fresh cheese;EN +CHEESPRO;Processed cheese ;EN +ICECREAM;Ice cream;EN +MILKPUDD;Milk desserts;EN +MILKSAUC;Milk sauces;EN +CHEESHAR;POISTETTU_Hard cheeses;EN +CHEESOFT;POISTETTU_Processed and fresh cheeses;EN +VEGCHEES;POISTETTU_Modified cheeses;EN +FATTOT;Fat and fat products;EN +BUTTER;Butter, milk fat;EN +FATANIM;Animal fat;EN +BUTTEHIG;Blended spread >= 55 %;EN +BUTTELOW;Blended spread < 55 %;EN +VEGFATLO;Margarine and fat spread < 55%;EN +VEGFATHI;Margarine and fat spread >= 55%;EN +FATCOOK;Cooking and industrial fat;EN +SALADDRE;Salad dressings and mayonnaises;EN +OIL;Oils;EN +BRFBUTT;POISTETTU_Butter and butter spread >60%;EN +BRFMARG;POISTETTU_Margarine and fat spread >55%;EN +BRFLOWF;POISTETTU_Margarine, butter spread and fat spread <55%;EN +DRESSING;POISTETTU_Salad dressings;EN +FATPROD;POISTETTU_Other fat products;EN +FATSAUCE;POISTETTU_Fat sauces;EN +EGGDISH;Egg dishes;EN +EGGS;Egg;EN +EGGMIX;Egg dishes;EN +FISHDTOT;Fish dishes;EN +FISH;Fish;EN +FISHPROD;Fish products;EN +FISHSOUP;Fish soups;EN +FISHDISH;Fish dishes;EN +FISHSAUC;Fish sauces;EN +SEAFOOD;Crustaceans and molluscs;EN +SEAFDISH;Seafood dishes, crustacean and molluscs;EN +SEAFSOUP;Seafood soup;EN +SEAFSAUC;Seafood sauces;EN +INSECT;Edible insects;EN +FISHCASS;POISTETTU_Fish casseroles;EN +FISHDOTH;POISTETTU_Other fish dishes;EN +MEATDTOT;Meat dishes;EN +MSTEAK;Steaks and chops;EN +MEATSOUP;Meat soups;EN +MEATDISH;Meat dishes;EN +POULTRY;Chicken and other birds;EN +POULTDIS;Poultry dishes;EN +POULTSOU;Poultry soups;EN +POULSAUC;Poultry sauces;EN +MEATPROD;Meat products;EN +SAUSCUTS;Cold cuts, sausages;EN +MEATCUTS;Cold cuts, meat;EN +SAUSAGE;Sausages;EN +OFFALDI;Offal dishes;EN +MINCMED;POISTETTU_Minced meat dishes;EN +MEATPOT;POISTETTU_Meat hot-pot;EN +MEATCASS;POISTETTU_Meat casseroles;EN +POULTDI;POISTETTU_Poultry dishes;EN +SAUSDISH;POISTETTU_Sausage dishes;EN +BEVTOT;Beverages;EN +COFFEE;Coffee;EN +TEA;Tea;EN +DRWATER;Drinking water;EN +DRJUICE;Juice drink;EN +DRINKSO;Soft drink with sugar;EN +DRINKART;Drinks with artificial sweeteners;EN +DRSPORT;Sport drink;EN +DRINKOTH;Other drinks;EN +DRINKCO;POISTETTU_Soft drink with caffeine;EN +ALCTOT;Alcoholic beverages;EN +BEER;Beers;EN +CIDER;Ciders;EN +WINE;Wines;EN +SPIRIT;Spirits;EN +ALCOTH;Other alcoholic beverages;EN +SUGARTOT;Sugar and confectionery;EN +SUGADD;Sugar and syrups;EN +SWEET;Confectionery;EN +CHOCOL;Chocolate;EN +JAM;Jams and marmalades;EN +MISCTOT;Miscellaneous;EN +SPICES;Spices;EN +SPISAUCE;Condiments;EN +SAVSAUCE;Savoury sauces;EN +DESSAUCE;Dessert sauces;EN +INGRMISC;Miscellaneous ingredients;EN +SNACK;POISTETTU_Snacks;EN +SNACKTOT;Snacks;EN +SNACKSAV;Savoury snacks;EN +SNACKVEG;Nuts, seeds and dried fruits;EN +BABYFTOT;Babyfood;EN +BABMEATD;Baby meat dish;EN +BABFISHD;Baby fish dish;EN +BABMILPO;Baby porridge with milk;EN +BABWATPO;Baby porridge with water;EN +BABFRUB;Baby fruit and berry product;EN +BABVEGE;Baby vegetable product;EN +BABMIFRU;Baby fruit with milk product;EN +BABOTHER;Baby food, not specified;EN +MMILK;Infant formulas and human milk;EN +INFMILK;Infant formulas and human milk;EN +CASMILK;Casein formulas;EN +PREMILK;Premature formulas;EN +SOYMILK;Soy milk formulas;EN +WHEYMILK;Whey formulas;EN +AMINMILK;Amino acid formulas;EN +SPECTOT;Products for special nutritional use;EN +SPECSUPP;Dietary supplement;EN +MEALREP;Meal replacements;EN +SPORTFOO;Sport food;EN +SPECFOOD;Products for nutritional support;EN +MEATSAUC;Meat sauces;EN diff --git a/packages/food-data/src/archive.ts b/packages/food-data/src/archive.ts index 69a05cd..b1599db 100644 --- a/packages/food-data/src/archive.ts +++ b/packages/food-data/src/archive.ts @@ -50,6 +50,11 @@ async function openDirectory(dir: string): Promise { return fromFiles(dir, files, () => {}); } +/** Separate files (e.g. downloaded one by one) as one archive. */ +export function openFiles(label: string, paths: readonly string[]): Archive { + return fromFiles(label, new Map(paths.map((p) => [key(p), p])), () => {}); +} + function fromFiles( path: string, files: Map, diff --git a/packages/food-data/src/cli.ts b/packages/food-data/src/cli.ts index a529588..6fcb62f 100644 --- a/packages/food-data/src/cli.ts +++ b/packages/food-data/src/cli.ts @@ -3,12 +3,18 @@ import { parseArgs } from 'util'; import { poolFromEnv } from './db'; import { download, fetchText } from './download'; import { + ciqualFiles, + ciqualJob, + cnfFile, + cnfJob, cofidFile, cofidJob, deltaFilesIn, downloadFdc, fdcFilesIn, fdcJobs, + fineliFile, + fineliJob, isOffCsv, offFileInput, offJob, @@ -36,11 +42,14 @@ Sources: off Open Food Facts, a full export (the JSONL by default; or --file a CSV) off-delta Open Food Facts' daily changes since the last import cofid UK CoFID 2021 (McCance and Widdowson's) - (cnf, ciqual and fineli are not written yet) + cnf Canada's Canadian Nutrient File 2015 (kept in data/) + ciqual France's ANSES-CIQUAL 2025 (from Recherche Data Gouv) + fineli Finland's Fineli, release 20 (kept in data/) Options: --file a local file instead of downloading (repeatable for fdc) - --dir a folder of local files (USDA's names; or delta files) + --dir a folder of local files (USDA's names; delta files; an + extracted CNF, Fineli or CIQUAL release) --dataset fdc: foundation,sr,fndds,branded (default foundation,sr,fndds) --limit stop after n records (a sample) --dry-run write nothing; report what would change @@ -269,11 +278,32 @@ async function main(argv: string[]) { log, }); jobs = [cofidJob(path, log)]; - } else if (['cnf', 'ciqual', 'fineli'].includes(source)) { - throw new Error(`The ${source} importer isn't written yet`); + } else if (source === 'cnf' || source === 'fineli') { + if (files.length > 1) throw new Error(`${source} takes one --file`); + const options = { file: files[0], dir: values.dir }; + jobs = [ + source === 'cnf' + ? cnfJob(await cnfFile(options), log) + : fineliJob(await fineliFile(options), log), + ]; + } else if (source === 'ciqual') { + if (files.length > 1) { + throw new Error('ciqual takes one --file (a zip) or --dir'); + } + jobs = [ + ciqualJob( + await ciqualFiles({ + file: files[0], + dir: values.dir, + refresh: values.refresh, + log, + }), + log, + ), + ]; } else { throw new Error( - `Unknown source "${source}": use fdc, off, off-delta or cofid`, + `Unknown source "${source}": use fdc, off, off-delta, cofid, cnf, ciqual or fineli`, ); } diff --git a/packages/food-data/src/import.db-spec.ts b/packages/food-data/src/import.db-spec.ts index 98bf204..0c935f7 100644 --- a/packages/food-data/src/import.db-spec.ts +++ b/packages/food-data/src/import.db-spec.ts @@ -2,7 +2,15 @@ import { mkdtemp, readFile, rm, writeFile } from 'fs/promises'; import { tmpdir } from 'os'; import { join } from 'path'; import type { PoolClient } from 'pg'; -import { cofidJob, fdcJobs, offFileInput, offJob } from './jobs'; +import { + ciqualJob, + cnfJob, + cofidJob, + fdcJobs, + fineliJob, + offFileInput, + offJob, +} from './jobs'; import { runJob, type Job } from './run'; import { testSchema } from './test-db'; import { FIXTURES, writeCofidWorkbook } from './test-fixtures'; @@ -217,3 +225,69 @@ describe('importing the fixtures', () => { expect(changedAnything(stats)).toBe(false); }); }); + +describe('importing the national tables', () => { + const national = () => [ + cnfJob(join(FIXTURES, 'cnf')), + fineliJob(join(FIXTURES, 'fineli')), + ciqualJob(join(FIXTURES, 'ciqual')), + ]; + + it('imports CNF, Fineli and CIQUAL, and a second run changes nothing', async () => { + const first = await runAll(national()); + // CNF 7, Fineli 7 (6 with energy), CIQUAL 9 (8 with energy) + expect(first).toMatchObject({ read: 23, skipped: 2, foodsInserted: 21 }); + const second = await runAll(national()); + expect(second.read).toBe(23); + expect(changedAnything(second)).toBe(false); + }); + + it('stores each table with its country, other names and servings', async () => { + const { rows } = await client.query( + `SELECT f.id, f.name, f.kind, f.countries, f.verified, + (SELECT amount FROM food_nutrients n WHERE n."foodId" = f.id AND nutrient = 'kcal') AS kcal, + (SELECT array_agg(lang || ':' || name ORDER BY lang) FROM food_names m WHERE m."foodId" = f.id) AS names, + (SELECT label FROM food_servings v WHERE v."foodId" = f.id AND typical) AS typical + FROM foods f WHERE f.id IN ('cnf_501999', 'fineli_1036', 'ciqual_7603') + ORDER BY f.id`, + ); + expect(rows).toEqual([ + { + id: 'ciqual_7603', + name: 'Croissant (average)', + kind: 'generic', + countries: ['fr'], + verified: true, + kcal: 417, + names: ['fr:Croissant, sans précision (aliment moyen)'], + typical: null, + }, + { + id: 'cnf_501999', + name: 'Poutine', + kind: 'dish', + countries: ['ca'], + verified: true, + kcal: 226, + names: ['fr:Poutine'], + typical: '1 serving', + }, + { + id: 'fineli_1036', + name: 'Rye bread, 51% rye', + kind: 'generic', + countries: ['fi'], + verified: true, + kcal: 250.1, + names: ['fi:Ruisleipä, ruista 51%', 'sv:Rågbröd, råg 51 %'], + typical: '1 piece', + }, + ]); + // Other names are searched too + expect( + await count( + `SELECT count(*)::int AS n FROM foods WHERE "searchText" LIKE '%ruisleipa%'`, + ), + ).toBe(1); + }); +}); diff --git a/packages/food-data/src/jobs.ts b/packages/food-data/src/jobs.ts index b9cd030..6ca26a8 100644 --- a/packages/food-data/src/jobs.ts +++ b/packages/food-data/src/jobs.ts @@ -4,8 +4,8 @@ import { Readable } from 'stream'; import type { ReadableStream as WebReadableStream } from 'stream/web'; import { createGunzip } from 'zlib'; import type { Pool } from 'pg'; -import { openArchive, type Archive } from './archive'; -import { download, fetchText } from './download'; +import { openArchive, openFiles, type Archive } from './archive'; +import { checkSha256, download, fetchText } from './download'; import type { FoodRecord } from './record'; import type { Job } from './run'; import { @@ -40,6 +40,9 @@ import { COFID_URL, readCofidWorkbook, } from './sources/cofid'; +import { ciqualRecords, CIQUAL_FILES } from './sources/ciqual'; +import { cnfRecords, CNF_FILE, CNF_SHA256 } from './sources/cnf'; +import { fineliRecords, FINELI_FILE, FINELI_SHA256 } from './sources/fineli'; import { removeSources } from './writer'; type Log = (line: string) => void; @@ -356,3 +359,121 @@ export function cofidJob(path: string, log: Log = () => {}): Job { }, }; } + +// ── National tables kept in this package: Canada's CNF, Finland's Fineli ──── + +/** Where the release files that can't be downloaded by a server are kept */ +export const DATA_DIR = join(__dirname, '..', 'data'); + +/** + * A national table's release file: --file as given, else the copy kept in + * data/, checked against the SHA-256 it was added with (so a changed or + * corrupted file is never imported as the release it claims to be). + */ +async function keptFile( + label: string, + name: string, + sha256: string, + options: { file?: string; dir?: string } = {}, +): Promise { + if (options.file) return options.file; + // An extracted release folder + if (options.dir) return options.dir; + const path = join(DATA_DIR, name); + try { + await checkSha256(path, sha256); + } catch (err) { + throw new Error(`${label}: ${(err as Error).message}`); + } + return path; +} + +function tableJob( + name: 'cnf' | 'fineli', + label: string, + path: string, + read: (a: Archive) => Promise, + log: Log, +): Job { + return { + name, + source: name, + prefix: '', + complete: true, + async *records() { + const records = await withArchive(path, read); + log(`${label}: ${records.length} foods (${basename(path)})`); + yield* records; + }, + }; +} + +/** CNF 2015: --file (the zip or its extracted folder), else data/'s copy. */ +export function cnfFile(options: { file?: string; dir?: string } = {}) { + return keptFile('CNF', CNF_FILE, CNF_SHA256, options); +} + +export function cnfJob(path: string, log: Log = () => {}): Job { + return tableJob('cnf', 'CNF', path, cnfRecords, log); +} + +/** Fineli release 20: --file (the zip or its extracted folder), else data/'s copy. */ +export function fineliFile(options: { file?: string; dir?: string } = {}) { + return keptFile('Fineli', FINELI_FILE, FINELI_SHA256, options); +} + +export function fineliJob(path: string, log: Log = () => {}): Job { + return tableJob('fineli', 'Fineli', path, fineliRecords, log); +} + +// ── France's CIQUAL ────────────────────────────────────────────────────────── + +/** + * CIQUAL 2025: --file a zip or folder of its XML files, else downloaded + * from Recherche Data Gouv (and checked). Returns an archive's path or the + * downloaded files. + */ +export async function ciqualFiles( + options: { file?: string; dir?: string; refresh?: boolean; log?: Log } = {}, +): Promise { + const local = options.file ?? options.dir; + if (local) return local; + const paths: string[] = []; + for (const f of Object.values(CIQUAL_FILES)) { + paths.push( + await download(f.url, { + name: f.name, + sha256: f.sha256, + refresh: options.refresh, + log: options.log, + }), + ); + } + return paths; +} + +export function ciqualJob( + files: string | readonly string[], + log: Log = () => {}, +): Job { + return { + name: 'ciqual', + source: 'ciqual', + prefix: '', + complete: true, + async *records() { + const archive = + typeof files === 'string' + ? await openArchive(files) + : openFiles('CIQUAL', files); + let records: FoodRecord[]; + try { + records = await ciqualRecords(archive); + } finally { + archive.close(); + } + log(`CIQUAL: ${records.length} foods`); + yield* records; + }, + }; +} diff --git a/packages/food-data/src/sources/ciqual.spec.ts b/packages/food-data/src/sources/ciqual.spec.ts new file mode 100644 index 0000000..ac33858 --- /dev/null +++ b/packages/food-data/src/sources/ciqual.spec.ts @@ -0,0 +1,177 @@ +import { join } from 'path'; +import { Readable } from 'stream'; +import { openArchive, openFiles } from '../archive'; +import { ciqualJob } from '../jobs'; +import { cleanRecord, type FoodRecord } from '../record'; +import { FIXTURES } from '../test-fixtures'; +import { + ciqualNumber, + ciqualNutrients, + ciqualRecords, + xmlRecords, +} from './ciqual'; + +// Real records of the ANSES-CIQUAL table 2025 (ANSES; Licence Ouverte / +// Etalab 2.0), as Recherche Data Gouv serves them. + +const DIR = join(FIXTURES, 'ciqual'); +let records: FoodRecord[]; +const byId = (id: string) => records.find((r) => r.externalId === id)!; + +beforeAll(async () => { + const archive = await openArchive(DIR); + try { + records = await ciqualRecords(archive); + } finally { + archive.close(); + } +}); + +async function all(items: AsyncIterable) { + const out: T[] = []; + for await (const item of items) out.push(item); + return out; +} + +describe('CIQUAL values', () => { + it('reads decimal commas and traces; unknowns are missing', () => { + expect(ciqualNumber(' 59,7 ')).toBe(59.7); + expect(ciqualNumber('274')).toBe(274); + expect(ciqualNumber('traces')).toBe(0); + // Below what the lab could measure: unknown, not zero + expect(ciqualNumber('< 0,5')).toBeUndefined(); + expect(ciqualNumber('-')).toBeUndefined(); + expect(ciqualNumber(null)).toBeUndefined(); + }); + + it("converts CIQUAL's constituents to GRIT's nutrients", () => { + expect( + ciqualNutrients( + new Map([ + [327, 418.4], // kJ only + [10004, 0.028], // salt in g, no sodium + [51200, 10], // retinol and β-carotene, no RAE + [51330, 120], + [53100, 1.2], // vitamin E, no α-tocopherol + [56700, 27.1], // total folate, no DFE + ]), + ), + ).toEqual({ + kcal: expect.closeTo(100, 6) as number, + sodium_mg: expect.closeTo(11.2, 6) as number, + vit_a_ug: 20, + vit_e_mg: 1.2, + folate_ug: 27.1, + }); + // The preferred constituent wins + expect( + ciqualNutrients( + new Map([ + [328, 274], + [327, 1140], + [10110, 15], + [10004, 1], + [51104, 31.3], + [51200, 10], + [51330, 120], + [71010, 0.5], + [53100, 1.2], + [56702, 40], + [56700, 27.1], + ]), + ), + ).toEqual({ + kcal: 274, + sodium_mg: 15, + vit_a_ug: 31.3, + vit_e_mg: 0.5, + folate_ug: 40, + }); + }); +}); + +describe('CIQUAL XML', () => { + it('reads records split across chunks, with entities and missing values', async () => { + const xml = + '\n\n' + + ' \n 5002 \n' + + ' Beer, strong (>8° alcohol) \n' + + ' \n \n' + + ' \n 7603 \n' + + ' Croissant (average) \n \n' + + '
\n'; + // Three bytes at a time: tags, entities and "°" are all split + const bytes = Buffer.from(xml); + const chunks: Buffer[] = []; + for (let i = 0; i < bytes.length; i += 3) + chunks.push(bytes.subarray(i, i + 3)); + expect(await all(xmlRecords(Readable.from(chunks), 'ALIM'))).toEqual([ + { + alim_code: '5002', + alim_nom_eng: 'Beer, strong (>8° alcohol)', + alim_nom_sci: null, + }, + { alim_code: '7603', alim_nom_eng: 'Croissant (average)' }, + ]); + }); +}); + +describe('CIQUAL foods', () => { + it('reads every food with its French name and subgroup', () => { + expect(records).toHaveLength(9); + expect(byId('7603')).toMatchObject({ + source: 'ciqual', + name: 'Croissant (average)', + kind: 'generic', + category: 'Viennese pastries', + countries: ['fr'], + basis: 'measured', + verified: true, + fetchedAt: new Date('2025-11-19T00:00:00Z'), + names: [ + { name: 'Croissant, sans précision (aliment moyen)', lang: 'fr' }, + ], + }); + expect(cleanRecord(byId('7603'))!.nutrients).toMatchObject({ + kcal: 417, + protein_g: 6.56, + carbs_g: 46.2, + fat_g: 22.1, + sat_fat_g: 14, + sodium_mg: 478, + vit_a_ug: 149, + }); + expect(byId('5002').name).toBe('Beer, strong (>8° alcohol)'); + }); + + it('marks starters and dishes', () => { + expect(byId('25601')).toMatchObject({ + name: 'Tuna salad, with vegetables, canned', + kind: 'dish', + category: 'Mixed salads', + }); + }); + + it('keeps traces as zero and unknown amounts out', () => { + // Kir's selenium is "< 20" µg: not zero, not 20 + expect(byId('1018').nutrients.selenium_ug).toBeUndefined(); + expect(byId('1000').nutrients.alcohol_g).toBe(37.5); + // Fresh mango juice gives salt, not sodium + expect(byId('2023').nutrients.sodium_mg).toBeCloseTo(11.2); + }); + + it("leaves out foods without energy when they're cleaned", () => { + expect(cleanRecord(byId('1010'))).toBeNull(); + expect(records.map(cleanRecord).filter(Boolean)).toHaveLength(8); + }); + + it('reads downloaded files as well as a folder', async () => { + const files = ['alim', 'alim_grp', 'compo'].map((n) => + join(DIR, `${n}_2025_11_03.xml`), + ); + const archive = openFiles('CIQUAL', files); + expect(archive.find(/^compo_/)).toBe('compo_2025_11_03.xml'); + archive.close(); + expect(await all(ciqualJob(files).records())).toHaveLength(9); + }); +}); diff --git a/packages/food-data/src/sources/ciqual.ts b/packages/food-data/src/sources/ciqual.ts new file mode 100644 index 0000000..e0fce50 --- /dev/null +++ b/packages/food-data/src/sources/ciqual.ts @@ -0,0 +1,272 @@ +import type { Readable } from 'stream'; +import type { + NutrientCode, + NutrientValues, +} from '../../../backend/src/food/nutrients'; +import type { Archive } from '../archive'; +import type { FoodRecord } from '../record'; + +/** + * France's CIQUAL: the ANSES-CIQUAL food composition table 2025 (ANSES; + * Licence Ouverte / Etalab 2.0), as deposited by ANSES on Recherche Data + * Gouv (doi:10.57745/RDMHWY), which answers servers when Ciqual's own site + * doesn't. + * + * Flat UTF-8 XML files: alim (foods, French and English names, group + * codes), alim_grp (group names) and compo (one row per food and + * constituent, per 100 g). Values use a decimal comma; "-" is missing, + * "traces" is a trace, "< 0,5" is below what the lab could measure. + */ + +const DATAFILE_URL = + 'https://entrepot.recherche.data.gouv.fr/api/access/datafile/'; + +/** The files read, with Recherche Data Gouv's file ids and their SHA-256 */ +export const CIQUAL_FILES = { + alim: { + name: 'alim_2025_11_03.xml', + url: `${DATAFILE_URL}666252`, + sha256: 'e0b1de25b3039028205e9d54a96892e403e1b313c2efeb41180fabe132627478', + }, + groups: { + name: 'alim_grp_2025_11_03.xml', + url: `${DATAFILE_URL}666250`, + sha256: 'e216928be1001aed15ba1b120405b70a98145da2a1a76026d6e33542bd5e39dc', + }, + compo: { + name: 'compo_2025_11_03.xml', + url: `${DATAFILE_URL}666249`, + sha256: '8c46a9032ece4eab4ffccc9dfcb0c490ec2f416aa664cc1ee013b241c6bdd4af', + }, +} as const; +/** Published on Recherche Data Gouv on 19 November 2025 */ +export const CIQUAL_RELEASE = new Date('2025-11-19T00:00:00Z'); + +/** The files by name pattern, so a newer release's dated names are found */ +export const CIQUAL_PATTERNS = { + alim: /^alim_\d[\d_]*\.xml$/i, + groups: /^alim_grp_\d[\d_]*\.xml$/i, + compo: /^compo_\d[\d_]*\.xml$/i, +}; + +/** CIQUAL constituent codes for each GRIT code, first present wins. */ +const CONSTITUENTS: readonly [NutrientCode, readonly number[]][] = [ + // EU Regulation 1169/2011 (what labels use), else N × Jones' factor + ['kcal', [328, 333]], + ['protein_g', [25000, 25003]], + // Available carbohydrate (excludes fibre), as EU tables give it + ['carbs_g', [31000]], + ['sugars_g', [32000]], + ['fat_g', [40000]], + ['sat_fat_g', [40302]], + ['fibre_g', [34100]], + ['alcohol_g', [60000]], + ['sodium_mg', [10110]], + ['potassium_mg', [10190]], + ['calcium_mg', [10200]], + ['magnesium_mg', [10120]], + ['phosphorus_mg', [10150]], + ['iron_mg', [10260]], + ['zinc_mg', [10300]], + ['selenium_ug', [10340]], + ['vit_a_ug', [51104]], // RAE + ['vit_c_mg', [55100]], + ['vit_d_ug', [52100]], + // α-tocopherol, else vitamin E + ['vit_e_mg', [71010, 53100]], + ['vit_k_ug', [54101]], // K1, as USDA's + ['b1_mg', [56100]], + ['b2_mg', [56200]], + ['b3_mg', [56310]], + ['b6_mg', [56500]], + ['b12_ug', [56600]], + // DFE, else total folate + ['folate_ug', [56702, 56700]], +]; + +const KJ = [327, 332]; +const SALT_G = 10004; +const RETINOL = 51200; +const BETA_CAROTENE = 51330; + +export const CIQUAL_CONSTITUENTS = new Set([ + ...CONSTITUENTS.flatMap(([, c]) => c), + ...KJ, + SALT_G, + RETINOL, + BETA_CAROTENE, +]); + +/** CIQUAL values (constituent → amount per 100 g) in GRIT's codes and units. */ +export function ciqualNutrients( + values: ReadonlyMap, +): NutrientValues { + const out: NutrientValues = {}; + for (const [code, ids] of CONSTITUENTS) { + for (const id of ids) { + const v = values.get(id); + if (v !== undefined) { + out[code] = v; + break; + } + } + } + if (out.kcal === undefined) { + const kj = KJ.map((id) => values.get(id)).find((v) => v !== undefined); + if (kj !== undefined) out.kcal = kj / 4.184; + } + // RAE from its parts when there's no total: retinol + β-carotene / 12 + const retinol = values.get(RETINOL); + const carotene = values.get(BETA_CAROTENE); + if ( + out.vit_a_ug === undefined && + retinol !== undefined && + carotene !== undefined + ) { + out.vit_a_ug = retinol + carotene / 12; + } + // 1 g salt has 400 mg sodium + const salt = values.get(SALT_G); + if (out.sodium_mg === undefined && salt !== undefined) { + out.sodium_mg = salt * 400; + } + return out; +} + +/** + * A CIQUAL value: "59,7" is 59.7 and "traces" is 0. "-" (missing) and + * "< 0,5" (below what the lab could measure, so unknown) are missing, + * never zero. + */ +export function ciqualNumber(s: string | null | undefined): number | undefined { + const t = (s ?? '').trim(); + if (/^traces$/i.test(t)) return 0; + if (!/^-?\d+(?:,\d+)?$/.test(t)) return undefined; + return Number(t.replace(',', '.')); +} + +const ENTITIES: Record = { + lt: '<', + gt: '>', + amp: '&', + apos: "'", + quot: '"', +}; + +function decode(s: string) { + return s.replace(/&(#x[\da-f]+|#\d+|\w+);/gi, (m, e: string) => { + if (e[0] === '#') { + const code = + e[1] === 'x' || e[1] === 'X' + ? parseInt(e.slice(2), 16) + : parseInt(e.slice(1), 10); + return Number.isFinite(code) ? String.fromCodePoint(code) : m; + } + return ENTITIES[e.toLowerCase()] ?? m; + }); +} + +/** One element's children: name → trimmed text, null when marked missing. */ +function fields(body: string) { + const out: Record = {}; + const re = /<(\w+)(?:\s[^>]*?)?(?:\/>|>([^<]*)<\/\1>)/g; + for (let m = re.exec(body); m; m = re.exec(body)) { + out[m[1]] = m[2] === undefined ? null : decode(m[2]).trim(); + } + return out; +} + +/** + * The `` records of a flat XML table (CIQUAL's: one level of + * elements holding text), streamed so the 69 MB compo file never has to + * be in memory at once. + */ +export async function* xmlRecords( + input: Readable, + tag: string, +): AsyncGenerator> { + const open = `<${tag}>`; + const close = ``; + let buffer = ''; + input.setEncoding('utf8'); + for await (const chunk of input) { + buffer += chunk as string; + let from = 0; + for ( + let end = buffer.indexOf(close, from); + end >= 0; + end = buffer.indexOf(close, from) + ) { + const start = buffer.lastIndexOf(open, end); + if (start >= from) yield fields(buffer.slice(start + open.length, end)); + from = end + close.length; + } + buffer = buffer.slice(from); + } +} + +const capitalise = (s: string) => s.charAt(0).toUpperCase() + s.slice(1); + +/** "01" is starters and dishes */ +const DISH_GROUP = '01'; + +/** CIQUAL's foods as records, from an archive holding its XML files. */ +export async function ciqualRecords(archive: Archive): Promise { + const file = (key: keyof typeof CIQUAL_PATTERNS) => { + const name = archive.find(CIQUAL_PATTERNS[key]); + if (!name) throw new Error(`${archive.path} has no CIQUAL ${key} file`); + return name; + }; + + const groups = new Map(); + for await (const r of xmlRecords( + await archive.open(file('groups')), + 'ALIM_GRP', + )) { + const name = r.alim_ssgrp_nom_eng; + if (r.alim_ssgrp_code && name && name !== '-') { + groups.set(r.alim_ssgrp_code, capitalise(name)); + } + if (r.alim_grp_code && r.alim_grp_nom_eng && !groups.has(r.alim_grp_code)) { + groups.set(r.alim_grp_code, capitalise(r.alim_grp_nom_eng)); + } + } + + const values = new Map>(); + for await (const r of xmlRecords( + await archive.open(file('compo')), + 'COMPO', + )) { + const constituent = Number(r.const_code); + if (!r.alim_code || !CIQUAL_CONSTITUENTS.has(constituent)) continue; + const v = ciqualNumber(r.teneur); + if (v === undefined) continue; + let food = values.get(r.alim_code); + if (!food) values.set(r.alim_code, (food = new Map())); + food.set(constituent, v); + } + + const records: FoodRecord[] = []; + for await (const r of xmlRecords(await archive.open(file('alim')), 'ALIM')) { + const code = r.alim_code; + if (!code) continue; + const french = r.alim_nom_fr ?? ''; + const group = r.alim_grp_code ?? ''; + records.push({ + source: 'ciqual', + externalId: code, + fetchedAt: CIQUAL_RELEASE, + name: r.alim_nom_eng || french, + kind: group === DISH_GROUP ? 'dish' : 'generic', + category: + groups.get(r.alim_ssgrp_code ?? '') ?? groups.get(group) ?? null, + countries: ['fr'], + nutrients: ciqualNutrients(values.get(code) ?? new Map()), + basis: 'measured', + names: french ? [{ name: french, lang: 'fr' }] : [], + quality: 1, + verified: true, + }); + } + return records; +} diff --git a/packages/food-data/src/sources/cnf.spec.ts b/packages/food-data/src/sources/cnf.spec.ts new file mode 100644 index 0000000..9d11d67 --- /dev/null +++ b/packages/food-data/src/sources/cnf.spec.ts @@ -0,0 +1,209 @@ +import { join } from 'path'; +import { openArchive } from '../archive'; +import { cnfFile, cnfJob } from '../jobs'; +import { cleanRecord, type FoodRecord } from '../record'; +import { FIXTURES } from '../test-fixtures'; +import { + cnfMeasureLabel, + cnfNutrients, + cnfRecords, + cnfServings, + CNF_SHA256, +} from './cnf'; + +// Real rows of the Canadian Nutrient File 2015 (Health Canada), as the +// release writes them: Latin-1, quoted where needed. + +let records: FoodRecord[]; +const byId = (id: string) => records.find((r) => r.externalId === id)!; + +beforeAll(async () => { + const archive = await openArchive(join(FIXTURES, 'cnf')); + try { + records = await cnfRecords(archive); + } finally { + archive.close(); + } +}); + +describe('CNF measures', () => { + it('names measures without their weight', () => { + expect(cnfMeasureLabel('250ml')).toBe('250 ml'); + expect(cnfMeasureLabel('100ml chopped or diced')).toBe( + '100 ml, chopped or diced', + ); + expect(cnfMeasureLabel('1 waffle (17.8cm dia)')).toBe( + '1 waffle (17.8cm dia)', + ); + // A weight alone isn't a portion's name + expect(cnfMeasureLabel('85g')).toBeNull(); + expect(cnfMeasureLabel(' ')).toBeNull(); + }); + + it('picks a typical serving', () => { + const typical = (measures: [string, number][]) => + cnfServings( + measures.map(([description, grams]) => ({ description, grams })), + ) + .filter((s) => s.typical) + .map((s) => s.label); + // A countable unit over a weight + expect( + typical([ + ['1 shoot', 144], + ['85g', 85], + ['250ml', 127], + ]), + ).toEqual(['1 shoot']); + // A weight is Canada's serving when there's nothing countable + expect( + typical([ + ['100g', 100], + ['85g', 85], + ['250ml', 250], + ]), + ).toEqual(['1 serving']); + // CNF's own serving wins, and the weight isn't added beside it + expect( + cnfServings([ + { description: '1 serving', grams: 195 }, + { description: '30g', grams: 30 }, + ]), + ).toEqual([{ label: '1 serving', grams: 195, typical: true }]); + // Volumes only: the first that isn't 100 ml + expect( + typical([ + ['100ml', 103], + ['15ml', 15.5], + ['250ml', 259], + ]), + ).toEqual(['15 ml']); + expect(cnfServings([])).toEqual([]); + }); +}); + +describe('CNF values', () => { + it("converts CNF's nutrients to GRIT's", () => { + expect( + cnfNutrients( + new Map([ + [268, 418.4], // kJ only + [205, -0.2], // carbs by difference, below zero + [324, 40], // vitamin D in IU only + [417, 30], // total folacin without DFE + ]), + ), + ).toEqual({ + kcal: expect.closeTo(100, 6) as number, + carbs_g: 0, + vit_d_ug: 1, + folate_ug: 30, + }); + // kcal, µg vitamin D and DFE win when present + expect( + cnfNutrients( + new Map([ + [208, 50], + [268, 209], + [339, 1.2], + [324, 48], + [815, 40], + [417, 30], + ]), + ), + ).toEqual({ kcal: 50, vit_d_ug: 1.2, folate_ug: 40 }); + }); +}); + +describe('CNF foods', () => { + it('reads every food with its French name, group and servings', () => { + expect(records).toHaveLength(7); + expect(byId('61')).toMatchObject({ + source: 'cnf', + name: 'Milk, fluid, partly skimmed, 2% M.F.', + kind: 'generic', + category: 'Dairy and Egg Products', + countries: ['ca'], + basis: 'measured', + verified: true, + quality: 1, + fetchedAt: new Date('2015-10-30T00:00:00Z'), + names: [ + { name: 'Lait, partiellement écrémé, liquide, 2% M.G.', lang: 'fr' }, + ], + servings: [ + { + label: '100 ml', + grams: expect.closeTo(103.128, 3) as number, + typical: false, + }, + { + label: '250 ml', + grams: expect.closeTo(257.819, 3) as number, + typical: true, + }, + ], + }); + expect(cleanRecord(byId('61'))!.nutrients).toMatchObject({ + kcal: 50, + protein_g: 3.3, + carbs_g: 4.8, + fat_g: 1.98, + calcium_mg: 120, + vit_a_ug: 63, + vit_d_ug: 1, + b12_ug: 0.53, + caffeine_mg: 0, + }); + }); + + it('marks mixed dishes, and decodes Latin-1', () => { + expect(byId('2')).toMatchObject({ + name: 'Cheese souffle', + kind: 'dish', + category: 'Mixed Dishes', + names: [{ name: 'Soufflé au fromage', lang: 'fr' }], + }); + expect(byId('501999')).toMatchObject({ + name: 'Poutine', + kind: 'dish', + servings: expect.arrayContaining([ + { label: '1 serving', grams: 195, typical: true }, + ]) as unknown, + }); + }); + + it('skips measures the release has no name for', () => { + // Eggnog's factors include a measure missing from MEASURE NAME + expect(byId('55').servings!.map((s) => s.label)).toEqual([ + '100 ml', + '125 ml', + '250 ml', + ]); + }); + + it('reads vitamin D in IU when there are no micrograms', () => { + expect(byId('534').nutrients.vit_d_ug).toBeCloseTo(0.075); + }); +}); + +describe('the CNF release kept in data/', () => { + it('is the file it was added as', async () => { + // Throws if the zip changed (or is a Git LFS pointer, or truncated) + const path = await cnfFile(); + expect(path).toMatch(/data[/\\]cnf-fcen-csv\.zip$/); + expect(CNF_SHA256).toHaveLength(64); + }, 60_000); + + it('imports from the zip as it is', async () => { + const job = cnfJob(await cnfFile()); + let n = 0; + let poutine: FoodRecord | undefined; + for await (const r of job.records()) { + n++; + if (r.externalId === '501999') poutine = r; + } + expect(n).toBe(5690); + expect(poutine).toMatchObject({ name: 'Poutine', kind: 'dish' }); + }, 60_000); +}); diff --git a/packages/food-data/src/sources/cnf.ts b/packages/food-data/src/sources/cnf.ts new file mode 100644 index 0000000..52606db --- /dev/null +++ b/packages/food-data/src/sources/cnf.ts @@ -0,0 +1,235 @@ +import type { + NutrientCode, + NutrientValues, +} from '../../../backend/src/food/nutrients'; +import type { Archive } from '../archive'; +import { csvObjects } from '../csv'; +import type { FoodRecord } from '../record'; + +/** + * Canada's CNF: the Canadian Nutrient File 2015 (Health Canada; Open + * Government Licence – Canada). Health Canada's site refuses servers, so + * the release zip, as downloaded in a browser, is kept in this package + * (data/) and checked by its SHA-256. + * + * Relational CSV files (Latin-1, quoted where needed): FOOD NAME (English + * and French names, food group), NUTRIENT AMOUNT (one row per food and + * nutrient, per 100 g), CONVERSION FACTOR (each measure's weight as a + * multiple of 100 g) and MEASURE NAME. NutrientID is the key, not + * NutrientCode: they differ for newer nutrients (RAE is ID 814, code 320). + */ + +export const CNF_FILE = 'cnf-fcen-csv.zip'; +export const CNF_SHA256 = + 'fb77503d88186844cc2c27b39432d755505f97a789c97fc5973a30d0cd4b0367'; +/** The newest values in the 2015 release (NUTRIENT AMOUNT, 30 Oct 2015) */ +export const CNF_RELEASE = new Date('2015-10-30T00:00:00Z'); + +const FILES = { + foods: 'FOOD NAME.csv', + groups: 'FOOD GROUP.csv', + amounts: 'NUTRIENT AMOUNT.csv', + factors: 'CONVERSION FACTOR.csv', + measures: 'MEASURE NAME.csv', +}; + +/** CNF NutrientIDs for each GRIT code, first present wins. */ +const NUTRIENT_IDS: readonly [NutrientCode, readonly number[]][] = [ + ['kcal', [208]], + ['protein_g', [203]], + // Total carbohydrate by difference: includes fibre, as USDA's does + ['carbs_g', [205]], + ['sugars_g', [269]], + ['fat_g', [204]], + ['sat_fat_g', [606]], + ['fibre_g', [291]], + ['alcohol_g', [221]], + ['sodium_mg', [307]], + ['potassium_mg', [306]], + ['calcium_mg', [301]], + ['magnesium_mg', [304]], + ['phosphorus_mg', [305]], + ['iron_mg', [303]], + ['zinc_mg', [309]], + ['selenium_ug', [317]], + ['vit_a_ug', [814]], // RAE + ['vit_c_mg', [401]], + ['vit_d_ug', [339]], // D2 + D3 + ['vit_e_mg', [323]], // α-tocopherol + ['vit_k_ug', [430]], + ['b1_mg', [404]], + ['b2_mg', [405]], + ['b3_mg', [406]], // preformed niacin + ['b6_mg', [415]], + ['b12_ug', [418]], + // DFE, else total folacin + ['folate_ug', [815, 417]], + ['caffeine_mg', [262]], +]; + +/** Fast Foods and Mixed Dishes */ +const DISH_GROUPS = new Set(['21', '22']); + +const KJ = 268; +const VIT_D_IU = 324; + +export const CNF_NUTRIENT_IDS = new Set([ + ...NUTRIENT_IDS.flatMap(([, ids]) => ids), + KJ, + VIT_D_IU, +]); + +/** CNF values (NutrientID → amount per 100 g) in GRIT's codes and units. */ +export function cnfNutrients( + values: ReadonlyMap, +): NutrientValues { + const out: NutrientValues = {}; + for (const [code, ids] of NUTRIENT_IDS) { + for (const id of ids) { + const v = values.get(id); + if (v !== undefined) { + out[code] = v; + break; + } + } + } + if (out.kcal === undefined && values.has(KJ)) { + out.kcal = values.get(KJ)! / 4.184; + } + // 40 IU = 1 µg + if (out.vit_d_ug === undefined && values.has(VIT_D_IU)) { + out.vit_d_ug = values.get(VIT_D_IU)! * 0.025; + } + // Carbs by difference go slightly negative on some fatty meats + if (out.carbs_g !== undefined && out.carbs_g < 0) out.carbs_g = 0; + return out; +} + +function number(s: string | undefined): number | undefined { + const t = (s ?? '').trim(); + if (!/^-?\d+(?:\.\d+)?$/.test(t)) return undefined; + return Number(t); +} + +const tidy = (s: string | undefined) => (s ?? '').replace(/\s+/g, ' ').trim(); + +/** + * A CNF measure as a serving label: "250ml chopped or diced" → "250 ml, + * chopped or diced", "1 waffle (17.8cm dia)" as it is. A weight alone + * ("85g") returns null: it isn't a portion's name. + */ +export function cnfMeasureLabel(description: string): string | null { + const s = tidy(description); + if (!s) return null; + const m = /^(\d+(?:\.\d+)?)\s*(ml|g)\b\s*(.*)$/i.exec(s); + if (!m) return s; + const [, amount, unit, rest] = m; + if (unit.toLowerCase() === 'g' && !rest) return null; + return `${amount} ${unit.toLowerCase()}${rest ? `, ${rest}` : ''}`; +} + +interface Measure { + label: string; + grams: number; +} + +/** + * Servings from a food's measures, in CNF's order. Weights alone are + * dropped, except that the first one other than 100 g becomes "1 serving" + * when CNF has none (its "85g" for meat is Canada's serving). Typical: + * CNF's own "1 serving", else the first "1 " (a slice, a waffle), + * else that weight, else the first measure other than 100 ml (15 ml of a + * dressing, 250 ml of milk), else the first. + */ +export function cnfServings( + measures: readonly { description: string; grams: number }[], +): NonNullable { + const out: Measure[] = []; + let weight: Measure | undefined; + for (const m of measures) { + if (!(m.grams > 0)) continue; + const label = cnfMeasureLabel(m.description); + if (label) { + out.push({ label, grams: m.grams }); + } else if (!weight && Math.abs(m.grams - 100) > 0.01) { + weight = { label: '1 serving', grams: m.grams }; + } + } + const own = out.find((s) => /^1 serving$/i.test(s.label)); + if (own) weight = undefined; + const typical = + own ?? + out.find((s) => /^1 \D/.test(s.label)) ?? + weight ?? + out.find((s) => !/^100 ml$/.test(s.label)) ?? + out[0]; + // The serving from a weight goes first when it's the typical one + const list = weight + ? weight === typical + ? [weight, ...out] + : [...out, weight] + : out; + return list.map((s) => ({ ...s, typical: s === typical })); +} + +/** The CNF release as records: reads the files it needs from the zip. */ +export async function cnfRecords(archive: Archive): Promise { + const read = async (name: string) => + csvObjects(await archive.open(name), { encoding: 'latin1' }); + + const groups = new Map(); + for await (const r of await read(FILES.groups)) { + groups.set(r.FoodGroupID, tidy(r.FoodGroupName)); + } + const measureNames = new Map(); + for await (const r of await read(FILES.measures)) { + measureNames.set(r.MeasureID, r.MeasureDescription); + } + + const values = new Map>(); + for await (const r of await read(FILES.amounts)) { + const id = Number(r.NutrientID); + if (!CNF_NUTRIENT_IDS.has(id)) continue; + const v = number(r.NutrientValue); + if (v === undefined) continue; + let food = values.get(r.FoodID); + if (!food) values.set(r.FoodID, (food = new Map())); + food.set(id, v); + } + + const measures = new Map(); + for await (const r of await read(FILES.factors)) { + const description = measureNames.get(r.MeasureID); + const factor = number(r.ConversionFactorValue); + // A few factors name measures the release doesn't list + if (!description || factor === undefined) continue; + let list = measures.get(r.FoodID); + if (!list) measures.set(r.FoodID, (list = [])); + list.push({ description, grams: factor * 100 }); + } + + const records: FoodRecord[] = []; + for await (const r of await read(FILES.foods)) { + const id = tidy(r.FoodID); + if (!id) continue; + const french = tidy(r.FoodDescriptionF); + records.push({ + source: 'cnf', + externalId: id, + fetchedAt: CNF_RELEASE, + name: tidy(r.FoodDescription), + kind: DISH_GROUPS.has(tidy(r.FoodGroupID)) ? 'dish' : 'generic', + category: groups.get(r.FoodGroupID) ?? null, + countries: ['ca'], + servings: cnfServings(measures.get(r.FoodID) ?? []), + nutrients: cnfNutrients( + values.get(r.FoodID) ?? new Map(), + ), + basis: 'measured', + names: french ? [{ name: french, lang: 'fr' }] : [], + quality: 1, + verified: true, + }); + } + return records; +} diff --git a/packages/food-data/src/sources/fineli.spec.ts b/packages/food-data/src/sources/fineli.spec.ts new file mode 100644 index 0000000..783fe77 --- /dev/null +++ b/packages/food-data/src/sources/fineli.spec.ts @@ -0,0 +1,170 @@ +import { join } from 'path'; +import { openArchive } from '../archive'; +import { fineliFile, fineliJob } from '../jobs'; +import { cleanRecord, type FoodRecord } from '../record'; +import { FIXTURES } from '../test-fixtures'; +import { + fineliNumber, + fineliNutrients, + fineliRecords, + fineliServings, + sentenceCase, +} from './fineli'; + +// Real rows of Fineli release 20, basic package 2 (Finnish Institute for +// Health and Welfare, THL; CC BY 4.0), as the release writes them: +// semicolons, Latin-1, CRLF, decimal commas. + +let records: FoodRecord[]; +const byId = (id: string) => records.find((r) => r.externalId === id)!; + +beforeAll(async () => { + const archive = await openArchive(join(FIXTURES, 'fineli')); + try { + records = await fineliRecords(archive); + } finally { + archive.close(); + } +}); + +describe('Fineli values', () => { + it('reads decimal commas, and blanks as missing', () => { + expect(fineliNumber('1698,30')).toBe(1698.3); + expect(fineliNumber('0')).toBe(0); + expect(fineliNumber('')).toBeUndefined(); + expect(fineliNumber(undefined)).toBeUndefined(); + }); + + it('writes names in sentence case', () => { + expect(sentenceCase('RYE BREAD, 51% RYE')).toBe('Rye bread, 51% rye'); + expect(sentenceCase('RUISLEIPÄ, RUISTA 51%')).toBe( + 'Ruisleipä, ruista 51%', + ); + expect(sentenceCase('SMOOTHIE, FRUIT +VITAMINS D&C')).toBe( + 'Smoothie, fruit +vitamins D&C', + ); + }); + + it("converts Fineli's components to GRIT's nutrients", () => { + expect( + fineliNutrients( + new Map([ + ['ENERC', 418.4], // kJ only + ['CHOAVL', 18.3], + ['FIBC', 1.8], + ['NACL', 1000], // salt in mg, no sodium + ['VITPYRID', 0.5], + ['WATER', 74.6], // not one of GRIT's + ]), + ), + ).toEqual({ + kcal: expect.closeTo(100, 6) as number, + carbs_g: 18.3, + fibre_g: 1.8, + sodium_mg: 400, + b6_mg: 0.5, + }); + // Sodium wins over salt + expect( + fineliNutrients( + new Map([ + ['NA', 5], + ['NACL', 12.74], + ]), + ).sodium_mg, + ).toBe(5); + }); + + it('turns units into servings, one typical', () => { + expect( + fineliServings( + new Map([ + ['PORTM', 125], + ['KPL_M', 125], + ['KG', 1000], + ['PORT1000KJ', 285], + ['RKL', 15], + ]), + ), + ).toEqual([ + { label: '1 piece', grams: 125, typical: true }, + { label: '1 medium portion', grams: 125, typical: false }, + { label: '1 tbsp', grams: 15, typical: false }, + ]); + // A product's own piece first + expect( + fineliServings( + new Map([ + ['KPL_VALM', 40], + ['KPL_M', 30], + ]), + ).find((s) => s.typical)?.label, + ).toBe('1 piece, as sold'); + expect(fineliServings(new Map())).toEqual([]); + }); +}); + +describe('Fineli foods', () => { + it('reads every food with its Finnish and Swedish names', () => { + // Seven foods; the dietary supplement isn't one + expect(records.map((r) => r.externalId).sort()).toEqual( + ['1', '1013', '1036', '11049', '11184', '3327', '35629'].sort(), + ); + expect(byId('11049')).toMatchObject({ + source: 'fineli', + name: 'Banana, without skin', + kind: 'generic', + category: 'Fruits', + countries: ['fi'], + basis: 'measured', + verified: true, + fetchedAt: new Date('2019-08-08T00:00:00Z'), + names: [ + { name: 'Banaani, kuorittu', lang: 'fi' }, + { name: 'Banan, skalad', lang: 'sv' }, + ], + }); + expect(cleanRecord(byId('11049'))!.nutrients).toMatchObject({ + kcal: 87.58, + protein_g: 1.2, + carbs_g: 18.3, + sugars_g: 13.5, + fibre_g: 1.8, + potassium_mg: 358.4, + vit_c_mg: 10, + folate_ug: 12.54, + }); + }); + + it('calls mixed dishes dishes, and recipes like bread foods', () => { + expect(byId('3327')).toMatchObject({ + name: 'Moussaka, pork beef mince', + kind: 'dish', + category: 'Meat dishes', + }); + // Fineli calls rye bread a dish: it's made from a recipe + expect(byId('1036')).toMatchObject({ + name: 'Rye bread, 51% rye', + kind: 'generic', + category: 'Rye bread', + }); + }); + + it("leaves out foods without energy when they're cleaned", () => { + expect(byId('11184').name).toBe('Cinnamon'); + expect(cleanRecord(byId('11184'))).toBeNull(); + }); +}); + +describe('the Fineli release kept in data/', () => { + it('is the file it was added as, and imports as it is', async () => { + const path = await fineliFile(); + expect(path).toMatch(/data[/\\]Fineli_Rel20_74_ravintotekijaa\.zip$/); + let n = 0; + for await (const r of fineliJob(path).records()) { + n++; + expect(r.countries).toEqual(['fi']); + } + expect(n).toBe(4237); + }, 60_000); +}); diff --git a/packages/food-data/src/sources/fineli.ts b/packages/food-data/src/sources/fineli.ts new file mode 100644 index 0000000..f959d31 --- /dev/null +++ b/packages/food-data/src/sources/fineli.ts @@ -0,0 +1,257 @@ +import type { + NutrientCode, + NutrientValues, +} from '../../../backend/src/food/nutrients'; +import type { Archive } from '../archive'; +import { csvObjects } from '../csv'; +import type { FoodRecord } from '../record'; + +/** + * Finland's Fineli: the national food composition database, release 20, + * basic package 2 (74 components) (Finnish Institute for Health and + * Welfare, THL; CC BY 4.0). Fineli's site refuses servers, so the zip, as + * downloaded in a browser, is kept in this package (data/) and checked by + * its SHA-256. + * + * Semicolon-separated, unquoted, Latin-1 files with CRLF line ends and + * decimal commas: food.csv (type, use class), foodname_EN/FI/SV.csv (names + * in capitals), component_value.csv (one row per food and component, per + * 100 g edible part), foodaddunit.csv (each unit's weight in grams). + */ + +export const FINELI_FILE = 'Fineli_Rel20_74_ravintotekijaa.zip'; +export const FINELI_SHA256 = + 'e7e6bd8d4b9261d751229e763dad436b297d36d48fe853faf49e1fd2a116d262'; +/** Release 20's files are dated 8 August 2019 */ +export const FINELI_RELEASE = new Date('2019-08-08T00:00:00Z'); + +const CSV = { delimiter: ';', quote: false, encoding: 'latin1' } as const; + +/** Fineli component codes (EuroFIR) for each GRIT code, first present wins. */ +const COMPONENTS: readonly [NutrientCode, readonly string[]][] = [ + ['protein_g', ['PROT']], + // Available carbohydrate (excludes fibre), as EU tables give it + ['carbs_g', ['CHOAVL']], + ['sugars_g', ['SUGAR']], + ['fat_g', ['FAT']], + ['sat_fat_g', ['FASAT']], + ['fibre_g', ['FIBC']], + ['alcohol_g', ['ALC']], + ['sodium_mg', ['NA']], + ['potassium_mg', ['K']], + ['calcium_mg', ['CA']], + ['magnesium_mg', ['MG']], + ['phosphorus_mg', ['P']], + ['iron_mg', ['FE']], + ['zinc_mg', ['ZN']], + ['selenium_ug', ['SE']], + ['vit_a_ug', ['VITA']], // RAE + ['vit_c_mg', ['VITC']], + ['vit_d_ug', ['VITD']], + ['vit_e_mg', ['VITE']], // α-tocopherol + ['vit_k_ug', ['VITK']], + ['b1_mg', ['THIA']], + ['b2_mg', ['RIBF']], + ['b3_mg', ['NIA']], // preformed niacin + ['b6_mg', ['VITPYRID']], + ['b12_ug', ['VITB12']], + // Total folate: Fineli has no DFE + ['folate_ug', ['FOL']], +]; + +export const FINELI_COMPONENTS = new Set([ + ...COMPONENTS.flatMap(([, c]) => c), + 'ENERC', + 'NACL', +]); + +/** Fineli values (component → amount per 100 g) in GRIT's codes and units. */ +export function fineliNutrients( + values: ReadonlyMap, +): NutrientValues { + const out: NutrientValues = {}; + for (const [code, components] of COMPONENTS) { + for (const c of components) { + const v = values.get(c); + if (v !== undefined) { + out[code] = v; + break; + } + } + } + // Energy is in kJ only + const kj = values.get('ENERC'); + if (kj !== undefined) out.kcal = kj / 4.184; + // Salt in mg: 1 g salt has 400 mg sodium + const salt = values.get('NACL'); + if (out.sodium_mg === undefined && salt !== undefined) { + out.sodium_mg = salt * 0.4; + } + return out; +} + +/** "1698,30" → 1698.3; blanks and anything else are missing. */ +export function fineliNumber(s: string | undefined): number | undefined { + const t = (s ?? '').trim(); + if (!/^-?\d+(?:,\d+)?$/.test(t)) return undefined; + return Number(t.replace(',', '.')); +} + +/** + * Fineli's capitals in sentence case: "RYE BREAD, 51% RYE" → "Rye bread, + * 51% rye". Words with "&" ("D&C") keep their capitals. + */ +export function sentenceCase(name: string): string { + const s = name + .replace(/\s+/g, ' ') + .trim() + .split(' ') + .map((w) => (w.includes('&') ? w : w.toLocaleLowerCase('fi'))) + .join(' '); + return s.charAt(0).toLocaleUpperCase('fi') + s.slice(1); +} + +/** Fineli's units GRIT shows, in the order shown; kg, l and others aren't portions. */ +const UNITS: readonly [string, string][] = [ + ['KPL_VALM', '1 piece, as sold'], + ['KPL_S', '1 small piece'], + ['KPL_M', '1 piece'], + ['KPL_L', '1 large piece'], + ['PORTS', '1 small portion'], + ['PORTM', '1 medium portion'], + ['PORTL', '1 large portion'], + ['DL', '1 dl'], + ['RKL', '1 tbsp'], + ['TL', '1 tsp'], +]; +/** The typical portion: the product's own piece, a piece, a medium portion */ +const TYPICAL = ['KPL_VALM', 'KPL_M', 'PORTM']; + +/** + * Food use classes that are mixed dishes. Fineli's DISH type means "a + * recipe", which includes breads and porridges, so GRIT's dish is a recipe + * in one of these. + */ +const DISH_CLASSES = new Set([ + 'MEATDISH', + 'POULTDIS', + 'OFFALDI', + 'FISHDISH', + 'SEAFDISH', + 'EGGMIX', + 'LEGUDISH', + 'POTADISH', + 'VEGDISH', + 'MUSHRDI', + 'PIZZA', + 'SANDWICH', + 'SALADMIX', + 'SALADMAY', + 'MEATSOUP', + 'POULTSOU', + 'FISHSOUP', + 'SEAFSOUP', + 'LEGUSOUP', + 'VEGSOUP', + 'MEATSAUC', + 'POULSAUC', + 'FISHSAUC', + 'SEAFSAUC', + 'LEGUSAUC', + 'BABMEATD', + 'BABFISHD', +]); +/** Not foods: the one dietary supplement */ +const NOT_FOOD_CLASSES = new Set(['SPECSUPP']); + +/** A food's units (code → grams) as servings, one typical. */ +export function fineliServings( + units: ReadonlyMap, +): NonNullable { + const typical = TYPICAL.find((u) => (units.get(u) ?? 0) > 0); + return UNITS.filter(([code]) => (units.get(code) ?? 0) > 0).map( + ([code, label]) => ({ + label, + grams: units.get(code)!, + typical: code === typical, + }), + ); +} + +/** Fineli's release as records: reads the files it needs from the zip. */ +export async function fineliRecords(archive: Archive): Promise { + const read = async (name: string) => + csvObjects(await archive.open(name), CSV); + + const names: Record<'EN' | 'FI' | 'SV', Map> = { + EN: new Map(), + FI: new Map(), + SV: new Map(), + }; + for (const lang of ['EN', 'FI', 'SV'] as const) { + for await (const r of await read(`foodname_${lang}.csv`)) { + names[lang].set(r.FOODID, sentenceCase(r.FOODNAME ?? '')); + } + } + const useClasses = new Map(); + for await (const r of await read('fuclass_EN.csv')) { + useClasses.set(r.THSCODE, (r.DESCRIPT ?? '').trim()); + } + + const values = new Map>(); + for await (const r of await read('component_value.csv')) { + if (!FINELI_COMPONENTS.has(r.EUFDNAME)) continue; + const v = fineliNumber(r.BESTLOC); + if (v === undefined) continue; + let food = values.get(r.FOODID); + if (!food) values.set(r.FOODID, (food = new Map())); + food.set(r.EUFDNAME, v); + } + + const units = new Map>(); + for await (const r of await read('foodaddunit.csv')) { + const grams = fineliNumber(r.MASS); + if (grams === undefined) continue; + let food = units.get(r.FOODID); + if (!food) units.set(r.FOODID, (food = new Map())); + food.set(r.FOODUNIT, grams); + } + + const records: FoodRecord[] = []; + for await (const r of await read('food.csv')) { + const id = (r.FOODID ?? '').trim(); + if ( + !id || + r.FOODTYPE === 'SUPPLE' || + NOT_FOOD_CLASSES.has(r.FUCLASS ?? '') + ) { + continue; + } + const other = (['FI', 'SV'] as const) + .map((lang) => ({ + name: names[lang].get(id) ?? '', + lang: lang.toLowerCase(), + })) + .filter((n) => n.name); + records.push({ + source: 'fineli', + externalId: id, + fetchedAt: FINELI_RELEASE, + // Every food has an English name; the Finnish one if not + name: names.EN.get(id) || names.FI.get(id) || '', + kind: + r.FOODTYPE === 'DISH' && DISH_CLASSES.has(r.FUCLASS ?? '') + ? 'dish' + : 'generic', + category: useClasses.get(r.FUCLASS) ?? null, + countries: ['fi'], + servings: fineliServings(units.get(id) ?? new Map()), + nutrients: fineliNutrients(values.get(id) ?? new Map()), + basis: 'measured', + names: other, + quality: 1, + verified: true, + }); + } + return records; +}