-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,305 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# U.S. EPA Food Commodity Intake Database (FCID)\n", | ||
"## [https://fcid.foodrisk.org/](https://fcid.foodrisk.org/)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Ativando uma conexão de banco de dados em memória usando o SGBD H2:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%defaultDatasource jdbc:h2:mem:db" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Importando Tabelas do FCID" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"DROP TABLE IF EXISTS Crop_Group;\n", | ||
"DROP TABLE IF EXISTS FCID_Description;\n", | ||
"DROP TABLE IF EXISTS Recipes;\n", | ||
"DROP TABLE IF EXISTS Intake;\n", | ||
"\n", | ||
"CREATE TABLE Crop_Group (\n", | ||
" CGN VARCHAR(2),\n", | ||
" CGL VARCHAR(6),\n", | ||
" Crop_Group_Description VARCHAR(80),\n", | ||
" PRIMARY KEY (CGL)\n", | ||
") AS SELECT\n", | ||
" CGN, CGL, Crop_Group_Description\n", | ||
"FROM CSVREAD('../../data/food-intake/basics/FCID_Cropgroup_Description.csv');\n", | ||
"\n", | ||
"CREATE TABLE FCID_Description (\n", | ||
" CGN VARCHAR(2),\n", | ||
" CG_Subgroup VARCHAR(6),\n", | ||
" FCID_Code VARCHAR(10),\n", | ||
" FCID_Desc VARCHAR(55),\n", | ||
" PRIMARY KEY (FCID_Code),\n", | ||
") AS SELECT\n", | ||
" cgn, CG_Subgroup, FCID_Code, FCID_Desc\n", | ||
"FROM CSVREAD('../../data/food-intake/basics/FCID_Code_Description.csv');\n", | ||
"\n", | ||
"CREATE TABLE Recipes (\n", | ||
" Food_Code VARCHAR(8),\n", | ||
" Mod_Code VARCHAR(8),\n", | ||
" Ingredient_Num TINYINT,\n", | ||
" FCID_Code VARCHAR(10),\n", | ||
" Cooked_Status TINYINT,\n", | ||
" Food_Form TINYINT,\n", | ||
" Cooking_Method TINYINT,\n", | ||
" Commodity_Weight DECIMAL(5, 2),\n", | ||
" CSFII_9498_IND TINYINT,\n", | ||
" WWEIA_9904_IND TINYINT,\n", | ||
" WWEIA_0510_IND TINYINT,\n", | ||
" PRIMARY KEY(Food_Code, Mod_Code, Ingredient_Num),\n", | ||
" FOREIGN KEY(FCID_Code)\n", | ||
" REFERENCES FCID_Description(FCID_Code)\n", | ||
" ON DELETE NO ACTION\n", | ||
" ON UPDATE NO ACTION\n", | ||
") AS SELECT\n", | ||
" Food_Code, Mod_Code, Ingredient_Num, FCID_Code, Cooked_Status, Food_Form, Cooking_Method,\n", | ||
" Commodity_Weight, CSFII_9498_IND, WWEIA_9904_IND, WWEIA_0510_IND\n", | ||
"FROM CSVREAD('../../data/food-intake/recipes/Recipes_WWEIA_FCID_0510.csv');\n", | ||
"\n", | ||
"CREATE TABLE Intake (\n", | ||
" SeqN INTEGER NOT NULL,\n", | ||
" DayCode TINYINT NOT NULL,\n", | ||
" DraBF TINYINT,\n", | ||
" FCID_Code VARCHAR(10),\n", | ||
" Cooked_Status TINYINT,\n", | ||
" Food_Form TINYINT,\n", | ||
" Cooking_Method TINYINT,\n", | ||
" Intake DECIMAL(13,7),\n", | ||
" Intake_BW DECIMAL(13,10),\n", | ||
" PRIMARY KEY(SeqN, DayCode, FCID_Code, Cooked_Status, Food_Form, Cooking_Method),\n", | ||
" FOREIGN KEY(FCID_Code)\n", | ||
" REFERENCES FCID_Description(FCID_Code)\n", | ||
" ON DELETE NO ACTION\n", | ||
" ON UPDATE NO ACTION\n", | ||
") AS SELECT\n", | ||
" SEQN, DAYCODE, DRABF, FCID_Code, Cooked_Status, Food_Form, Cooking_Method, Intake,Intake_BW\n", | ||
"FROM CSVREAD('../../data/food-intake/consumption/Commodity_CSFFM_Intake_0510-cropped.csv');" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Visualizando as Tabelas" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "e867c52b-05a3-42f5-8825-ff3097d0323c", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"method": "display_data" | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"SELECT * FROM FCID_Description LIMIT 10;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "6ddc57ab-310d-4fbd-8804-9bb985c7a82f", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"method": "display_data" | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"SELECT * FROM Recipes LIMIT 10;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "1e832fb3-c1d5-44f2-bfed-8d1d3d1a3a1e", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"method": "display_data" | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [ | ||
"SELECT * FROM Intake LIMIT 10;" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1) Apresentando uma Receita\n", | ||
"\n", | ||
"* Liste os ingredientes da receita de código `27111300` - Mexican style beef stew, no potatoes, tomato-based sauce (mixture).\n", | ||
"* Não devem aparecer as modificações da receita.\n", | ||
"* Mostre apenas o código da receita, o código de cada ingrediente, sua ordem e a participação no peso." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "f874a738-b2e3-4b4e-8811-61289b1682df", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"method": "display_data" | ||
}, | ||
"metadata": {}, | ||
"output_type": "display_data" | ||
} | ||
], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2) Receita com Nomes de Ingredientes\n", | ||
"* Aprimore a solução (1) para apresentar o nome dos ingredientes junto com seus códigos." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 3) Grupos Alimentares da Receita\n", | ||
"* A partir da receita escolhida em (1), apresente os grupos alimentares dos ingredientes contidos na receita.\n", | ||
"* Cada grupo alimentar só deve aparecer uma vez no resultado.\n", | ||
"* Para se obter o nome do grupo alimentar na tabela `Crop_Group` (não o subgrupo) devem ser considerados os registros em que a coluna `CGN` é igual à `CGL`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 4) Participação nas Receitas\n", | ||
"* Liste o nome de cada um dos produtos alimentares seguido do número de receitas em que ele participa.\n", | ||
"* A lista deve ser apresentada em ordem decrescente de número de participação em receitas." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## 5) Consumo Médio de Grupos de Alimentos\n", | ||
"* Para cada Grupo de Alimentos (cada CGN diferente na tabela Crop_Group), apresente sua descrição e o consumo médio deste grupo de alimentos.\n", | ||
"* O consumo é definido pelo campo `Intake` da tabela `Intake`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "SQL", | ||
"language": "SQL", | ||
"name": "sql" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": "sql", | ||
"file_extension": ".sql", | ||
"mimetype": "", | ||
"name": "SQL", | ||
"nbconverter_exporter": "", | ||
"version": "" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": false, | ||
"sideBar": false, | ||
"skip_h1_title": false, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": {}, | ||
"toc_section_display": false, | ||
"toc_window_display": false | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |