Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dashboard shows incorrect download numbers #385 #389

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/Graph/ColumnDrilldown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {splitDrilldownSeriesByArtifacts} from '../utils'
drilldown(Highcharts);

interface ColumnDrilldownProps {
data?: { [key: string]: number };
name: string;
}

Expand Down Expand Up @@ -58,17 +57,24 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col
}

async updateData() {
const { data } = this.props;
if (data) {
const availableReleases = await api.availableReleases();

if (availableReleases.available_releases) {
const drilldownSeries: DrilldownItem[] = [];
const archLevelDrilldownSeries: DrilldownSeries[] = [];

const seriesDataPromises: Promise<DrilldownData | null>[] = Object.keys(data).map(async key => {
// this step loops over all versions (e.g. "8":41425474,"11":50446738...)
const seriesDataPromises: Promise<DrilldownData | null>[] = 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<DrilldownData>[] = 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,
Expand All @@ -77,13 +83,15 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col
};
});

// this step will allocate element by level
const r = splitDrilldownSeriesByArtifacts(secondLevelDrilldownSeriesData);
archLevelDrilldownSeries.push({
name: apiDataKey,
id: apiDataKey,
data: Object.keys(r.artifacts).sort((a, b) => 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}`
}
Expand All @@ -94,19 +102,21 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col
archLevelDrilldownSeries.push({
name: `${apiDataKey}-${val}`,
id: `${apiDataKey}-${val}`,
// count number of value per level
data: r.artifacts[val].data.sort((a, b) => 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,
Expand All @@ -115,7 +125,7 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col

return {
name: `JDK${key}`,
y: data[key],
y: drilldownSeriesData.reduce((a, b) => a + b.y || 0, 0),
drilldown: key,
};
});
Expand All @@ -128,7 +138,6 @@ export default class ColumnDrilldown extends Component<ColumnDrilldownProps, Col
drilldownSeries: [...drilldownSeries, ...archLevelDrilldownSeries],
});
}

}

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/Graph/Download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class DownloadTotal extends Component<{}, DownloadTotalState> {
<PieChart data={totalPieChartData} name='Total Downloads' showInLegend dataLabels colors={['rgb(108,109,227)', 'rgb(254,174,98)']} />
{/* <PieChart data={pieChartData} name="jdk8u222-b10 Downloads" /> */}
</div>
<ColumnDrilldown data={data.github_downloads} name='Github Downloads' />
<ColumnDrilldown name='Github Release Downloads' />
</>
)
}
Expand Down
3 changes: 1 addition & 2 deletions src/Graph/Trends.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
});
}

Expand Down
30 changes: 16 additions & 14 deletions src/Graph/__tests__/ColumnDrilldown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
});
Expand All @@ -61,7 +63,7 @@ describe('ColumnDrilldown component', () => {

await act(async () => {
({ getByText } = render(
<ColumnDrilldown data={mock_data.github_downloads} name='Github Downloads' />
<ColumnDrilldown name='Github Release Downloads' />
));
setTimeout(() => { }, delay)
});
Expand Down
8 changes: 2 additions & 6 deletions src/Graph/__tests__/Download.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +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(getByText('39 821 217')).toBeInTheDocument();
expect(getByText('48 300 842')).toBeInTheDocument();
expect(getByText('45 342 098')).toBeInTheDocument();
expect(getByText('594 778')).toBeInTheDocument();

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);
});
});
4 changes: 3 additions & 1 deletion src/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}