From 66048afbb0233c7758a096b07202672b6590f836 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 11 Nov 2023 15:18:12 +0000 Subject: [PATCH 1/7] Bump axios from 1.5.0 to 1.6.1 Bumps [axios](https://github.com/axios/axios) from 1.5.0 to 1.6.1. - [Release notes](https://github.com/axios/axios/releases) - [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md) - [Commits](https://github.com/axios/axios/compare/v1.5.0...v1.6.1) --- updated-dependencies: - dependency-name: axios dependency-type: indirect ... Signed-off-by: dependabot[bot] --- yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yarn.lock b/yarn.lock index a5b3f5f..caa565f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2957,9 +2957,9 @@ axe-core@^4.6.2: integrity sha512-zIURGIS1E1Q4pcrMjp+nnEh+16G56eG/MUllJH8yEvw7asDo7Ac9uhC9KIH5jzpITueEZolfYglnCGIuSBz39g== axios@^1.4.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.5.0.tgz#f02e4af823e2e46a9768cfc74691fdd0517ea267" - integrity sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ== + version "1.6.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.6.1.tgz#76550d644bf0a2d469a01f9244db6753208397d7" + integrity sha512-vfBmhDpKafglh0EldBEbVuoe7DyAavGSLWhuSm5ZSEKQnHhBf0xAAwybbNH1IkrJNGnS/VG4I5yxig1pCEXE4g== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0" From db3ea76d4e48722406b43e8eb54835e6e5068844 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Mon, 11 Dec 2023 16:22:00 +0000 Subject: [PATCH 2/7] Fix seed, enhance docs --- .env | 1 + .env.local.sample | 1 - README.md | 8 ++++- seeds/003-add-kcal-flows.js | 62 ++++++++++++++++++++----------------- 4 files changed, 42 insertions(+), 30 deletions(-) delete mode 100644 .env.local.sample diff --git a/.env b/.env index e1e810e..bf983c4 100644 --- a/.env +++ b/.env @@ -1 +1,2 @@ DATABASE_URL=postgres://postgres:postgres@localhost:5433/food-twin?sslmode=disable +NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN= diff --git a/.env.local.sample b/.env.local.sample deleted file mode 100644 index 119a192..0000000 --- a/.env.local.sample +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN= \ No newline at end of file diff --git a/README.md b/README.md index 30c75b4..8bec944 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ To set up the development environment for this website, you'll need to install t - [Yarn](https://yarnpkg.com/) package manager - [Docker](https://www.docker.com) +### Initialize `.env.local` File + +The project uses environment variables, which are set by default in the [.env](.env) file. To customize these variables (e.g., to use a custom database), create a `.env.local` file at the root of the repository (`cp .env .env.local`) and modify as needed. + +Note: `.env.local` is ignored by Git. + ### Install Application Dependencies If you use [`nvm`](https://github.com/creationix/nvm), activate the desired Node version: @@ -52,7 +58,7 @@ Start development server: yarn dev ``` -✨ You can now login to the app at [http://localhost:3000](http://localhost:3000) +✨ You can now access the app at [http://localhost:3000](http://localhost:3000) ### API Docs diff --git a/seeds/003-add-kcal-flows.js b/seeds/003-add-kcal-flows.js index a373680..e29808d 100644 --- a/seeds/003-add-kcal-flows.js +++ b/seeds/003-add-kcal-flows.js @@ -11,9 +11,12 @@ const COUNTIES_FILE_PATH = path.join( ); exports.seed = async function (knex) { + console.log("Starting database seeding process..."); + /** * CLEAR FLOWS, CROPS, AND COUNTIES TABLES */ + console.log("Clearing tables: kcal_flows, crops, counties"); await knex.raw("TRUNCATE TABLE kcal_flows RESTART IDENTITY CASCADE"); await knex.raw("TRUNCATE TABLE crops RESTART IDENTITY CASCADE"); await knex.raw("TRUNCATE TABLE counties RESTART IDENTITY CASCADE"); @@ -21,6 +24,7 @@ exports.seed = async function (knex) { /** * INGEST COUNTIES */ + console.log("Ingesting counties data..."); const { features: counties } = await fs.readJson(COUNTIES_FILE_PATH); await knex.batchInsert( "counties", @@ -31,10 +35,12 @@ exports.seed = async function (knex) { })), 500 ); + console.log("Counties data ingestion completed."); /** * INGEST CROP CODES */ + console.log("Ingesting crop codes..."); const cropCodes = await fs.readFile(CROPS_CSV_PATH, "utf-8"); // Split CSV into rows @@ -56,10 +62,12 @@ exports.seed = async function (knex) { }) .filter((row) => row.name !== "") ); + console.log("Crop codes ingestion completed."); /** * INGEST KCAL FLOWS */ + console.log("Ingesting kcal flows..."); const files = (await fs.readdir(KCAL_FLOWS_DIR)).filter((file) => file.endsWith(".csv") ); @@ -68,7 +76,7 @@ exports.seed = async function (knex) { // Extract id from filename const crop_name = file .replace("kcal_produced_", "") - .replace("_impacted_results_df.csv", ""); + .replace("_results_df.csv", ""); const { id: crop_id } = await knex("crops") .where("name", crop_name) @@ -92,33 +100,31 @@ exports.seed = async function (knex) { try { await knex.batchInsert( "kcal_flows", - rows - .map((line) => { - if (line === "") return; - - const row = line.split(","); - - const origin_id = row[0].padStart(5, "0"); - const destination_id = row[1].padStart(5, "0"); - const value = row[2]; - - if (!origin_id || !destination_id || !value) { - console.log("Skipping row", row); - return null; - } - - return { - origin_id, - destination_id, - crop_id, - value, - impact_ratios: { - heat: parseFloat(row[3]), - drought: parseFloat(row[5]), - }, - }; - }) - .filter((row) => row.origin_id !== "0Dade"), // Discard rows with invalid origin_id + rows.map((line) => { + if (line === "") return; + + const row = line.split(","); + + const origin_id = row[0].padStart(5, "0"); + const destination_id = row[1].padStart(5, "0"); + const value = row[2]; + + if (!origin_id || !destination_id || !value) { + console.log("Skipping row", row); + return null; + } + + return { + origin_id, + destination_id, + crop_id, + value, + impact_ratios: { + heat: parseFloat(row[3]), + drought: parseFloat(row[5]), + }, + }; + }), 500 ); } catch (error) { From de04274a44cedd173a3499e831a4c938abffbf16 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Mon, 11 Dec 2023 16:23:38 +0000 Subject: [PATCH 3/7] Update link to seed data --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8bec944..fbc496c 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Migrate the database: yarn migrate ``` -Download the contents of this [Google Drive folder](https://drive.google.com/drive/folders/1uDlDT7NNI7l5WC0A9WsAZTlFWpC0Uo1i?usp=sharing) and add it to a directory called `./app-data` in the cloned repository. +Download the contents of this [Google Drive folder](https://drive.google.com/drive/folders/1IZunCVMNnA3h6VRBD365DfeUWQt5smzG?usp=drive_link) and add it to a directory called `./app-data` in the cloned repository. Ingest downloaded data with: From c37dc5f43c5e157834f1033495c665985d161915 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Tue, 12 Dec 2023 08:48:00 +0000 Subject: [PATCH 4/7] Fix file name --- seeds/003-add-kcal-flows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seeds/003-add-kcal-flows.js b/seeds/003-add-kcal-flows.js index e29808d..7bdb8db 100644 --- a/seeds/003-add-kcal-flows.js +++ b/seeds/003-add-kcal-flows.js @@ -76,7 +76,7 @@ exports.seed = async function (knex) { // Extract id from filename const crop_name = file .replace("kcal_produced_", "") - .replace("_results_df.csv", ""); + .replace("_impacted_results_df.csv", ""); const { id: crop_id } = await knex("crops") .where("name", crop_name) From 2e6ba8580e684fc88efd670abe5be39474f4fbdd Mon Sep 17 00:00:00 2001 From: Vitor George Date: Fri, 23 Feb 2024 11:09:46 +0000 Subject: [PATCH 5/7] Add Plausible tag --- src/pages/index.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 86f129d..183b89c 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -87,6 +87,13 @@ function Home({ href="/favicon-16x16.png" /> + {process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN && ( + + )} From ec60abd10cbaf91fe77e8973518bea7d736d5b79 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Fri, 23 Feb 2024 11:11:34 +0000 Subject: [PATCH 6/7] Add a comment indicating how to set plausible domain analytics --- .env | 1 + 1 file changed, 1 insertion(+) diff --git a/.env b/.env index bf983c4..7eb5b95 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ DATABASE_URL=postgres://postgres:postgres@localhost:5433/food-twin?sslmode=disable NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN= +#NEXT_PUBLIC_PLAUSIBLE_DOMAIN= From 0a68580218841ae3c1988f30913034aa3ddeb709 Mon Sep 17 00:00:00 2001 From: Vitor George Date: Fri, 23 Feb 2024 11:25:49 +0000 Subject: [PATCH 7/7] Remove redundant code --- src/pages/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 183b89c..d790ae7 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -90,7 +90,7 @@ function Home({ {process.env.NEXT_PUBLIC_PLAUSIBLE_DOMAIN && ( )}