From 51b8280d014b1795e8819558bb6e33c8ddc953b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Wed, 22 Nov 2023 11:41:08 +0100 Subject: [PATCH 1/3] Add support for getting data OONI Data Kraken API --- .env.development | 1 + .env.production | 1 + .env.test | 1 + components/Chart.js | 2 +- components/MATChart.js | 2 +- components/aggregation/Debug.js | 2 +- 6 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.env.development b/.env.development index c1c502786..1e66853ba 100644 --- a/.env.development +++ b/.env.development @@ -3,6 +3,7 @@ # Refer: https://nextjs.org/docs/basic-features/environment-variables NEXT_PUBLIC_OONI_API=https://ams-pg-test.ooni.org +NEXT_PUBLIC_OONI_DATA_API=https://ams-pg-test.ooni.org NEXT_PUBLIC_USER_FEEDBACK_API=https://ams-pg-test.ooni.org NEXT_PUBLIC_EXPLORER_URL=http://localhost:3100 diff --git a/.env.production b/.env.production index a6892c033..204938be3 100644 --- a/.env.production +++ b/.env.production @@ -3,6 +3,7 @@ # Refer: https://nextjs.org/docs/basic-features/environment-variables NEXT_PUBLIC_OONI_API=https://api.ooni.io +NEXT_PUBLIC_OONI_DATA_API=https://api.ooni.io NEXT_PUBLIC_USER_FEEDBACK_API=https://api.ooni.io NEXT_PUBLIC_SENTRY_DSN=https://49af7fff247c445b9a7c98ee21ddfd2f@o155150.ingest.sentry.io/1427510 NEXT_PUBLIC_EXPLORER_URL=https://explorer.ooni.org diff --git a/.env.test b/.env.test index d83d6bf27..1cb8b1ca7 100644 --- a/.env.test +++ b/.env.test @@ -3,6 +3,7 @@ # Refer: https://nextjs.org/docs/basic-features/environment-variables NEXT_PUBLIC_OONI_API=https://api.ooni.io +NEXT_PUBLIC_OONI_DATA_API=https://api.ooni.io NEXT_PUBLIC_USER_FEEDBACK_API=https://ams-pg-test.ooni.org NEXT_PUBLIC_EXPLORER_URL=https://explorer.test.ooni.org NEXT_PUBLIC_IS_TEST_ENV=1 diff --git a/components/Chart.js b/components/Chart.js index 8525eadf0..431ba5c26 100644 --- a/components/Chart.js +++ b/components/Chart.js @@ -18,7 +18,7 @@ const swrOptions = { export const MATLink = ({ query }) => { const intl = useIntl() const queryToSearchParams = new URLSearchParams(query) - const apiUrl = `${process.env.NEXT_PUBLIC_OONI_API}/api/v1/aggregation?${queryToSearchParams}` + const apiUrl = `${process.env.NEXT_PUBLIC_OONI_DATA_API}/api/v1/aggregation?${queryToSearchParams}` const showMATButton = !Array.isArray(query.test_name) diff --git a/components/MATChart.js b/components/MATChart.js index fb0645f4c..a0b310308 100644 --- a/components/MATChart.js +++ b/components/MATChart.js @@ -22,7 +22,7 @@ const swrOptions = { const fetcher = (query) => { const qs = new URLSearchParams(query).toString() - const reqUrl = `${process.env.NEXT_PUBLIC_OONI_API}/api/v1/aggregation?${qs}` + const reqUrl = `${process.env.NEXT_PUBLIC_OONI_DATA_API}/api/v1/aggregation?${qs}` console.debug(`API Query: ${reqUrl}`) return axios .get(reqUrl) diff --git a/components/aggregation/Debug.js b/components/aggregation/Debug.js index 5985a202e..c6257c9bd 100644 --- a/components/aggregation/Debug.js +++ b/components/aggregation/Debug.js @@ -45,7 +45,7 @@ export const Debug = ({ query, children, ...rest }) => { const tableReshapeTime = (tableReshapeTimeRef.current.pre > -1) ? Number(tableReshapeTimeRef.current.post - tableReshapeTimeRef.current.pre).toFixed(3) : undefined const chartReshapeTime = (chartsReshapeTimeRef.current.pre > -1) ? Number(chartsReshapeTimeRef.current.post - chartsReshapeTimeRef.current.pre).toFixed(3) : undefined const renderTime = Number([...renderTimeRef.current].pop() - chartsReshapeTimeRef.current.post).toFixed(3) - const apiQuery = `${process.env.NEXT_PUBLIC_OONI_API}/api/v1/aggregation?${paramsToQuery(params)}` + const apiQuery = `${process.env.NEXT_PUBLIC_OONI_DATA_API}/api/v1/aggregation?${paramsToQuery(params)}` return ( From 518c20b3cbda5543023baccd786f0de03a75104d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Wed, 22 Nov 2023 15:09:12 +0100 Subject: [PATCH 2/3] Add support for displaying LoNI values in tooltip --- components/aggregation/mat/CustomTooltip.js | 38 +++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/components/aggregation/mat/CustomTooltip.js b/components/aggregation/mat/CustomTooltip.js index 2c27050be..1f5a5bed3 100644 --- a/components/aggregation/mat/CustomTooltip.js +++ b/components/aggregation/mat/CustomTooltip.js @@ -3,6 +3,7 @@ import { Chip } from '@nivo/tooltip' import { useTheme } from '@nivo/core' import { Box, Flex, Text, Link, theme } from 'ooni-components' import NLink from 'next/link' +import dynamic from 'next/dynamic' import { colorMap } from './colorMap' import { MdClear } from 'react-icons/md' @@ -68,6 +69,40 @@ export const generateSearchQuery = (data, query) => { } } + +const ReactJson = dynamic( + () => import('react-json-view'), + { ssr: false } +) + + +const formatLoNI = (data) => { + let loni_down_map = {} + let loni_blocked_map = {} + Object.keys(data['loni_down_map']).forEach((orig_key) => { + const key = orig_key.split(".").slice(0, 2).join(".") + loni_down_map[key] = loni_down_map[key] | 0 + loni_down_map[key] += data['loni_down_map'][orig_key] + }) + console.log(data) + Object.keys(data['loni_blocked_map']).forEach((orig_key) => { + const key = orig_key.split(".").slice(0, 2).join(".") + loni_blocked_map[key] = loni_blocked_map[key] | 0 + loni_blocked_map[key] += data['loni_blocked_map'][orig_key] + }) + + return ( +
+
observation count: {data['observation_count']}
+
vp count: {data['vantage_point_count']}
+
down: {data['loni_down_value']}
+
ok: {data['loni_ok_value']}
+
blocked: {data['loni_blocked_value']}
+
down_map:
+
blocked_map:
+
+ ) +} const CustomToolTip = React.memo(({ data, onClose, title, link = true }) => { const theme = useTheme() const intl = useIntl() @@ -106,6 +141,9 @@ const CustomToolTip = React.memo(({ data, onClose, title, link = true }) => {
))} + + {formatLoNI(data)} + {link && From f8d5ee5c19ee8907d7e13dfa09f77d54a0d1e83c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arturo=20Filast=C3=B2?= Date: Wed, 22 Nov 2023 15:12:52 +0100 Subject: [PATCH 3/3] Fix lint issues to make vercel happy --- components/aggregation/mat/CustomTooltip.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/aggregation/mat/CustomTooltip.js b/components/aggregation/mat/CustomTooltip.js index 1f5a5bed3..70926f773 100644 --- a/components/aggregation/mat/CustomTooltip.js +++ b/components/aggregation/mat/CustomTooltip.js @@ -80,13 +80,13 @@ const formatLoNI = (data) => { let loni_down_map = {} let loni_blocked_map = {} Object.keys(data['loni_down_map']).forEach((orig_key) => { - const key = orig_key.split(".").slice(0, 2).join(".") + const key = orig_key.split('.').slice(0, 2).join('.') loni_down_map[key] = loni_down_map[key] | 0 loni_down_map[key] += data['loni_down_map'][orig_key] }) console.log(data) Object.keys(data['loni_blocked_map']).forEach((orig_key) => { - const key = orig_key.split(".").slice(0, 2).join(".") + const key = orig_key.split('.').slice(0, 2).join('.') loni_blocked_map[key] = loni_blocked_map[key] | 0 loni_blocked_map[key] += data['loni_blocked_map'][orig_key] })