From f8bf5b7d8e54e5433ebb0865e877549444660509 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:52:41 +0300 Subject: [PATCH 01/10] Update AirQo exceedance production image tag to prod-5e45c956-1733849508 --- k8s/exceedance/values-prod-airqo.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/exceedance/values-prod-airqo.yaml b/k8s/exceedance/values-prod-airqo.yaml index 8eaf5c0da7..d26ed0773e 100644 --- a/k8s/exceedance/values-prod-airqo.yaml +++ b/k8s/exceedance/values-prod-airqo.yaml @@ -4,6 +4,6 @@ app: configmap: env-exceedance-production image: repository: eu.gcr.io/airqo-250220/airqo-exceedance-job - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 nameOverride: '' fullnameOverride: '' From e375c0ff79fa2af280f7045e61b4964b67e0ca98 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:52:48 +0300 Subject: [PATCH 02/10] Update KCCA exceedance production image tag to prod-5e45c956-1733849508 --- k8s/exceedance/values-prod-kcca.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/exceedance/values-prod-kcca.yaml b/k8s/exceedance/values-prod-kcca.yaml index afea05a6f6..da76b77e9d 100644 --- a/k8s/exceedance/values-prod-kcca.yaml +++ b/k8s/exceedance/values-prod-kcca.yaml @@ -4,6 +4,6 @@ app: configmap: env-exceedance-production image: repository: eu.gcr.io/airqo-250220/kcca-exceedance-job - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 nameOverride: '' fullnameOverride: '' From 826c43613ad7640487c1c275dc5ddcfe55c37ddd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:53:32 +0300 Subject: [PATCH 03/10] Update device registry production image tag to prod-5e45c956-1733849508 --- k8s/device-registry/values-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/device-registry/values-prod.yaml b/k8s/device-registry/values-prod.yaml index 9f7570f9bc..b98df12889 100644 --- a/k8s/device-registry/values-prod.yaml +++ b/k8s/device-registry/values-prod.yaml @@ -6,7 +6,7 @@ app: replicaCount: 3 image: repository: eu.gcr.io/airqo-250220/airqo-device-registry-api - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 nameOverride: '' fullnameOverride: '' podAnnotations: {} From 0607721b8814b1793ee3ac2da34d876753bb61f8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:53:35 +0300 Subject: [PATCH 04/10] Update analytics staging images tag to stage-dd764c29-1733849460 --- k8s/analytics/values-stage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/analytics/values-stage.yaml b/k8s/analytics/values-stage.yaml index 6c2109404c..114d458f1a 100644 --- a/k8s/analytics/values-stage.yaml +++ b/k8s/analytics/values-stage.yaml @@ -8,7 +8,7 @@ images: celeryWorker: eu.gcr.io/airqo-250220/airqo-stage-analytics-celery-worker reportJob: eu.gcr.io/airqo-250220/airqo-stage-analytics-report-job devicesSummaryJob: eu.gcr.io/airqo-250220/airqo-stage-analytics-devices-summary-job - tag: stage-014ccd0f-1733315863 + tag: stage-dd764c29-1733849460 api: name: airqo-stage-analytics-api label: sta-alytics-api From ec8c7899ac429cbeca43968121e7a08cb59ec6df Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:53:51 +0300 Subject: [PATCH 05/10] Update website production image tag to prod-5e45c956-1733849508 --- k8s/website/values-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/website/values-prod.yaml b/k8s/website/values-prod.yaml index 342d8be4aa..4f049cd0a1 100644 --- a/k8s/website/values-prod.yaml +++ b/k8s/website/values-prod.yaml @@ -6,7 +6,7 @@ app: replicaCount: 3 image: repository: eu.gcr.io/airqo-250220/airqo-website-api - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 nameOverride: '' fullnameOverride: '' podAnnotations: {} From f9ad01f5e9ed23cd420b22e21acbf2b1236654a2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:54:32 +0300 Subject: [PATCH 06/10] Update workflows prod image tag to prod-5e45c956-1733849508 --- k8s/workflows/values-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/workflows/values-prod.yaml b/k8s/workflows/values-prod.yaml index d0549ff120..e80c45e124 100644 --- a/k8s/workflows/values-prod.yaml +++ b/k8s/workflows/values-prod.yaml @@ -10,7 +10,7 @@ images: initContainer: eu.gcr.io/airqo-250220/airqo-workflows-xcom redisContainer: eu.gcr.io/airqo-250220/airqo-redis containers: eu.gcr.io/airqo-250220/airqo-workflows - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 nameOverride: '' fullnameOverride: '' podAnnotations: {} From 2c2e01c516694dbec6bd90f61fe24b4c53c21767 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:54:42 +0300 Subject: [PATCH 07/10] Update analytics production image tag to prod-5e45c956-1733849508 --- k8s/analytics/values-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/analytics/values-prod.yaml b/k8s/analytics/values-prod.yaml index 98861f66e8..0a76851664 100644 --- a/k8s/analytics/values-prod.yaml +++ b/k8s/analytics/values-prod.yaml @@ -8,7 +8,7 @@ images: celeryWorker: eu.gcr.io/airqo-250220/airqo-analytics-celery-worker reportJob: eu.gcr.io/airqo-250220/airqo-analytics-report-job devicesSummaryJob: eu.gcr.io/airqo-250220/airqo-analytics-devices-summary-job - tag: prod-3d3f6c14-1733315928 + tag: prod-5e45c956-1733849508 api: name: airqo-analytics-api label: analytics-api From 1641a392ab59b08ec6c83564b7974a7a887f6985 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 19:56:24 +0300 Subject: [PATCH 08/10] Update predict production image tag to prod-5e45c956-1733849508 --- k8s/predict/values-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/predict/values-prod.yaml b/k8s/predict/values-prod.yaml index 18ec2275a1..9c89c531f4 100644 --- a/k8s/predict/values-prod.yaml +++ b/k8s/predict/values-prod.yaml @@ -7,7 +7,7 @@ images: predictJob: eu.gcr.io/airqo-250220/airqo-predict-job trainJob: eu.gcr.io/airqo-250220/airqo-train-job predictPlaces: eu.gcr.io/airqo-250220/airqo-predict-places-air-quality - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 api: name: airqo-prediction-api label: prediction-api From 5fac056f746868d22e5abbd9d1051a22210d4269 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:01:48 +0300 Subject: [PATCH 09/10] Update spatial production image tag to prod-5e45c956-1733849508 --- k8s/spatial/values-prod.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/spatial/values-prod.yaml b/k8s/spatial/values-prod.yaml index 94644d2a35..dd1053451b 100644 --- a/k8s/spatial/values-prod.yaml +++ b/k8s/spatial/values-prod.yaml @@ -6,7 +6,7 @@ app: replicaCount: 3 image: repository: eu.gcr.io/airqo-250220/airqo-spatial-api - tag: prod-ae2e15a3-1733844050 + tag: prod-5e45c956-1733849508 nameOverride: '' fullnameOverride: '' podAnnotations: {} From b41583a3428ffdc0f14811239bd9f7149ef8e23c Mon Sep 17 00:00:00 2001 From: baalmart Date: Tue, 10 Dec 2024 23:25:04 +0300 Subject: [PATCH 10/10] addressing a runtime error for listing cohorts --- src/device-registry/models/Cohort.js | 2 +- .../utils/scripts/new-bulk-script.js | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/device-registry/utils/scripts/new-bulk-script.js diff --git a/src/device-registry/models/Cohort.js b/src/device-registry/models/Cohort.js index e5aeb92d20..a00884dacd 100644 --- a/src/device-registry/models/Cohort.js +++ b/src/device-registry/models/Cohort.js @@ -214,7 +214,7 @@ cohortSchema.statics.list = async function( .sort({ createdAt: -1 }) .project(inclusionProjection) .project(exclusionProjection) - .groups({ + .group({ _id: "$_id", visibility: { $first: "$visibility" }, cohort_tags: { $first: "$cohort_tags" }, diff --git a/src/device-registry/utils/scripts/new-bulk-script.js b/src/device-registry/utils/scripts/new-bulk-script.js new file mode 100644 index 0000000000..37b7f4c23b --- /dev/null +++ b/src/device-registry/utils/scripts/new-bulk-script.js @@ -0,0 +1,71 @@ +const axios = require("axios"); +const isEmpty = require("is-empty"); + +const url = "http://localhost:3000/api/v2/devices/sites"; +const config = { + headers: { + Authorization: "", + }, +}; + +const NETWORK_MAPPINGS = { + // iqair: "permian-health", + // usembassy: "us-embassy", + // urbanbetter: "urban-better", + // kcca: "kcca", + // airqo: "airqo", + // Add more mappings as needed +}; + +const DEFAULT_GROUP = "unknown"; + +axios + .get(url, config) + .then(async (response) => { + const groups = response.data.sites + .map((site) => { + // Look up the group based on network, with a fallback to a default + const group = NETWORK_MAPPINGS[site.network] || DEFAULT_GROUP; + + // Optionally log devices with unknown networks + if (group === DEFAULT_GROUP) { + console.log( + `Unrecognized network for device ${site.name}: ${site.network}` + ); + } + + return group; + }) + // Remove any 'unknown' groups if you want only mapped networks + .filter((group) => group !== DEFAULT_GROUP); + + console.log("the data:"); + console.dir({ groups }); + + // Process devices in batches + for (let i = 0; i < response.data.sites.length; i += 10) { + const batch = response.data.sites.slice(i, i + 10); + + for (const site of batch) { + const group = NETWORK_MAPPINGS[site.network] || DEFAULT_GROUP; + + if (group !== DEFAULT_GROUP) { + const url = `http://localhost:3000/api/v2/devices/sites?id=${site._id}`; + const data = { groups: [group] }; + // console.log("the data:"); + // console.dir(data); + + try { + // Uncomment if you want to make the PUT request + const putResponse = await axios.put(url, data, config); + console.log("PUT response:", putResponse.data); + } catch (error) { + console.error("PUT error:", error.message); + } + } + } + } + }) + .catch((error) => { + console.error("GET error:", error); + });