From 7d934195a43474e11cdcffe546c7dbda085d7356 Mon Sep 17 00:00:00 2001 From: Xavier FACQ Date: Thu, 19 Oct 2023 14:49:12 +0200 Subject: [PATCH 1/4] Fix Dashboard shows incorrect download numbers #385 --- src/Graph/ColumnDrilldown.tsx | 26 +++++++++++------ src/Graph/Download.tsx | 2 +- src/Graph/__tests__/ColumnDrilldown.test.tsx | 30 +++++++++++--------- src/Graph/__tests__/Download.test.tsx | 5 ---- src/api.tsx | 4 ++- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/Graph/ColumnDrilldown.tsx b/src/Graph/ColumnDrilldown.tsx index 1994f83..2c3308b 100644 --- a/src/Graph/ColumnDrilldown.tsx +++ b/src/Graph/ColumnDrilldown.tsx @@ -9,7 +9,6 @@ import {splitDrilldownSeriesByArtifacts} from '../utils' drilldown(Highcharts); interface ColumnDrilldownProps { - data?: { [key: string]: number }; name: string; } @@ -58,17 +57,24 @@ export default class ColumnDrilldown extends Component[] = Object.keys(data).map(async key => { + // this step loops over all versions (e.g. "8":41425474,"11":50446738...) + const seriesDataPromises: Promise[] = availableReleases.available_releases.map(async key => { + // then call download data of key (e.g. https://api.adoptium.net/v3/stats/downloads/total/21) const apiData = await api.downloads(key); if (!apiData) return null; - + + // loop over all elements const drilldownDataPromises: Promise[] = Object.keys(apiData).map(async apiDataKey => { + // get data (e.g. https://api.adoptium.net/v3/stats/downloads/total/21/jdk-21+35) const secondLevelApiData = await api.downloads(`${key}/${apiDataKey}`); + + // this returns data of each element (e.g. OpenJDK20U-jdk_x64_windows_hotspot_20.0.2_9.zip) const secondLevelDrilldownSeriesData: DrilldownData[] = Object.keys(secondLevelApiData).map(secondLevelApiKey => { return { name: secondLevelApiKey, @@ -77,6 +83,7 @@ export default class ColumnDrilldown extends Component a.localeCompare(b)).map(val => { return { name: val, + // count number of value per level y: r.artifacts[val].data.reduce((a, b) => a + b.y || 0, 0), drilldown: `${apiDataKey}-${val}` } @@ -94,19 +102,21 @@ export default class ColumnDrilldown extends Component a.name.localeCompare(b.name)) }); }); return { name: apiDataKey, - y: apiData[apiDataKey], + y: secondLevelDrilldownSeriesData.reduce((a, b) => a + b.y || 0, 0), drilldown: apiDataKey, }; }); // this get all primary level keys: JDK21, JDK20... const drilldownSeriesData = await Promise.all(drilldownDataPromises); + drilldownSeries.push({ name: `JDK${key}`, id: key, @@ -115,7 +125,7 @@ export default class ColumnDrilldown extends Component a + b.y || 0, 0), drilldown: key, }; }); @@ -128,7 +138,6 @@ export default class ColumnDrilldown extends Component +

*Includes only results with Type of release: General Availability(ga)

); } diff --git a/src/Graph/Download.tsx b/src/Graph/Download.tsx index 628ed66..1132e2d 100644 --- a/src/Graph/Download.tsx +++ b/src/Graph/Download.tsx @@ -74,7 +74,7 @@ export default class DownloadTotal extends Component<{}, DownloadTotalState> { {/* */} - + ) } diff --git a/src/Graph/__tests__/ColumnDrilldown.test.tsx b/src/Graph/__tests__/ColumnDrilldown.test.tsx index 4ad6bb9..404be5f 100644 --- a/src/Graph/__tests__/ColumnDrilldown.test.tsx +++ b/src/Graph/__tests__/ColumnDrilldown.test.tsx @@ -11,18 +11,16 @@ import { api } from '../../api'; const delay = 2000; const mock_data = { - "date": "2023-10-09T07:10:48Z", - "docker_pulls": { - "eclipse-temurin": 74596680 - }, - "github_downloads": { - "8": 40769834 - }, - "total_downloads": { - "docker_pulls": 74596680, - "github_downloads": 165154324, - "total": 239751004 - } + "available_lts_releases": [ + 8 + ], + "available_releases": [ + 8 + ], + "most_recent_feature_release": 21, + "most_recent_feature_version": 22, + "most_recent_lts": 21, + "tip_version": 22 } const mock_data_api_8 = { @@ -51,8 +49,12 @@ const mock_data_api_b08 = { describe('ColumnDrilldown component', () => { test('renders correctly', async () => { + api.availableReleases = vi.fn().mockImplementation(() => { + return mock_data + }); + api.downloads = vi.fn().mockImplementation((arg) => { - if(arg === '8') return mock_data_api_8; + if(arg === 8) return mock_data_api_8; else if (arg === '8/jdk8u302-b08') return mock_data_api_b08; return undefined }); @@ -61,7 +63,7 @@ describe('ColumnDrilldown component', () => { await act(async () => { ({ getByText } = render( - + )); setTimeout(() => { }, delay) }); diff --git a/src/Graph/__tests__/Download.test.tsx b/src/Graph/__tests__/Download.test.tsx index a5ee899..6309bf2 100644 --- a/src/Graph/__tests__/Download.test.tsx +++ b/src/Graph/__tests__/Download.test.tsx @@ -57,11 +57,6 @@ describe('Download component', () => { expect(getByText('233 144 070')).toBeInTheDocument(); expect(queryAllByText('Github Downloads', {selector: 'text'}).length).toBe(3); - expect(getByText('39 821 217')).toBeInTheDocument(); - expect(getByText('48 300 842')).toBeInTheDocument(); - expect(getByText('45 342 098')).toBeInTheDocument(); - expect(getByText('594 778')).toBeInTheDocument(); - expect(queryAllByText('JDK Versions', {selector: 'text'}).length).toBe(1); }); }); diff --git a/src/api.tsx b/src/api.tsx index 16ef1f9..9dcd455 100644 --- a/src/api.tsx +++ b/src/api.tsx @@ -5,5 +5,7 @@ export const api = { // eslint-disable-next-line camelcase tracking: ({ source, feature_version, jvm_impl, days, ...rest }) => get('https://api.adoptium.net/v3/stats/downloads/tracking/', { source, feature_version, jvm_impl, days, ...rest }), // eslint-disable-next-line camelcase - monthly: ({ source, feature_version, jvm_impl, ...rest }) => get('https://api.adoptium.net/v3/stats/downloads/monthly/', { source, feature_version, jvm_impl, ...rest }) + monthly: ({ source, feature_version, jvm_impl, ...rest }) => get('https://api.adoptium.net/v3/stats/downloads/monthly/', { source, feature_version, jvm_impl, ...rest }), + // eslint-disable-next-line camelcase + availableReleases: () => get('https://api.adoptium.net/v3/info/available_releases') } From 1a2265eaed78b6c08002b0f357dc82f2995327cc Mon Sep 17 00:00:00 2001 From: Xavier FACQ Date: Thu, 19 Oct 2023 17:19:48 +0200 Subject: [PATCH 2/4] Remove text in the bottom --- src/Graph/ColumnDrilldown.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Graph/ColumnDrilldown.tsx b/src/Graph/ColumnDrilldown.tsx index 2c3308b..0d72752 100644 --- a/src/Graph/ColumnDrilldown.tsx +++ b/src/Graph/ColumnDrilldown.tsx @@ -208,7 +208,6 @@ export default class ColumnDrilldown extends Component -

*Includes only results with Type of release: General Availability(ga)

); } From 6ba1264633c430b2f09eb52c72b5e28bc6b33e21 Mon Sep 17 00:00:00 2001 From: Xavier FACQ Date: Thu, 19 Oct 2023 21:22:03 +0200 Subject: [PATCH 3/4] Use the created api function availableReleases() --- src/Graph/Trends.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Graph/Trends.tsx b/src/Graph/Trends.tsx index 538e000..aafdb81 100644 --- a/src/Graph/Trends.tsx +++ b/src/Graph/Trends.tsx @@ -1,6 +1,5 @@ import React, { Component } from 'react'; import { api } from '../api'; -import { get } from '../utils'; import LineChart from './LineChart'; import BarChart from './BarChart'; import moment from 'moment'; @@ -95,7 +94,7 @@ export default class Trends extends Component<{}, State> { await this.updateData(2, this.state.args2); await this.updateMonthlyData(this.state.monthlyArgs); this.setState({ - versions: (await get('https://api.adoptium.net/v3/info/available_releases')).available_releases, + versions: (await api.availableReleases()).available_releases, }); } From fef1c901680b4b927997893a2e3353d741920c1d Mon Sep 17 00:00:00 2001 From: Xavier FACQ Date: Fri, 20 Oct 2023 10:54:01 +0200 Subject: [PATCH 4/4] Change the title from "Github Downloads" to "Github Release Downloads" --- src/Graph/Download.tsx | 2 +- src/Graph/__tests__/ColumnDrilldown.test.tsx | 2 +- src/Graph/__tests__/Download.test.tsx | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Graph/Download.tsx b/src/Graph/Download.tsx index 1132e2d..4bc2c36 100644 --- a/src/Graph/Download.tsx +++ b/src/Graph/Download.tsx @@ -74,7 +74,7 @@ export default class DownloadTotal extends Component<{}, DownloadTotalState> { {/* */} - + ) } diff --git a/src/Graph/__tests__/ColumnDrilldown.test.tsx b/src/Graph/__tests__/ColumnDrilldown.test.tsx index 404be5f..e78b22c 100644 --- a/src/Graph/__tests__/ColumnDrilldown.test.tsx +++ b/src/Graph/__tests__/ColumnDrilldown.test.tsx @@ -63,7 +63,7 @@ describe('ColumnDrilldown component', () => { await act(async () => { ({ getByText } = render( - + )); setTimeout(() => { }, delay) }); diff --git a/src/Graph/__tests__/Download.test.tsx b/src/Graph/__tests__/Download.test.tsx index 6309bf2..fd5bcd1 100644 --- a/src/Graph/__tests__/Download.test.tsx +++ b/src/Graph/__tests__/Download.test.tsx @@ -56,7 +56,8 @@ describe('Download component', () => { expect(getByText('160 810 668')).toBeInTheDocument(); expect(getByText('233 144 070')).toBeInTheDocument(); - expect(queryAllByText('Github Downloads', {selector: 'text'}).length).toBe(3); + expect(queryAllByText('Github Downloads', {selector: 'text'}).length).toBe(2); + expect(queryAllByText('Github Release Downloads', {selector: 'text'}).length).toBe(1); expect(queryAllByText('JDK Versions', {selector: 'text'}).length).toBe(1); }); });