Skip to content

Commit b9d06ac

Browse files
authored
Merge pull request #356 from UKSpaceAgency/develop
release
2 parents bb29a43 + 4209d78 commit b9d06ac

23 files changed

Lines changed: 674 additions & 279 deletions

File tree

src/__generated__/V1.ts

Lines changed: 79 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__generated__/data-contracts.ts

Lines changed: 58 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use server';
22

3-
import type { TypeGetStatsEventsTypeParams } from '@/__generated__/data-contracts';
3+
import type { TypeGetStatsEventsTypeAggregatedParams } from '@/__generated__/data-contracts';
44
import Api from '@/libs/Api';
55

6-
export async function getStatsConjunctionEventsType(query?: TypeGetStatsEventsTypeParams) {
7-
const { data } = await Api.getStatsEventsType(query);
6+
export async function getStatsConjunctionEventsType(query?: TypeGetStatsEventsTypeAggregatedParams) {
7+
const { data } = await Api.getStatsEventsTypeAggregated(query);
88
return data;
99
};
Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use server';
22

3-
import type { TypeGetStatsEventsByOrganizationParams } from '@/__generated__/data-contracts';
3+
import type { TypeGetStatsEventsByOrganizationAggregatedParams } from '@/__generated__/data-contracts';
44
import Api from '@/libs/Api';
5+
import { dayjs, FORMAT_API_DATE } from '@/libs/Dayjs';
56

67
export type EventsByOrganizationSectionType = {
78
events: number;
@@ -17,35 +18,26 @@ export type EventsByOrganizationType = {
1718
high: number;
1819
};
1920

20-
export async function getStatsEventsByOrganization(query?: TypeGetStatsEventsByOrganizationParams): Promise<EventsByOrganizationType[]> {
21-
const { data } = await Api.getStatsEventsByOrganization(query);
22-
23-
const groupedData = data.reduce((acc, item) => {
24-
const { name, id, events, collision_probability_range } = item;
25-
26-
const key = id as string;
27-
28-
if (!acc[key]) {
29-
acc[key] = { name, id: key, total_events: 0, low: 0, medium: 0, high: 0 };
30-
}
31-
32-
switch (collision_probability_range) {
33-
case '< 1e-5':
34-
acc[key].low = events;
35-
acc[key].total_events += events;
36-
break;
37-
case '1e-3 .. 1e-5':
38-
acc[key].medium = events;
39-
acc[key].total_events += events;
40-
break;
41-
case '> 1e-3':
42-
acc[key].high = events;
43-
acc[key].total_events += events;
44-
break;
45-
}
46-
47-
return acc;
48-
}, {} as { [key: string]: EventsByOrganizationType });
49-
50-
return Object.values(groupedData);
21+
export async function getStatsEventsByOrganization(query?: TypeGetStatsEventsByOrganizationAggregatedParams): Promise<EventsByOrganizationType[]> {
22+
const params: TypeGetStatsEventsByOrganizationAggregatedParams = {};
23+
if (query?.start_date) {
24+
params.start_date = dayjs(query.start_date).format(FORMAT_API_DATE);
25+
}
26+
if (query?.end_date) {
27+
params.end_date = dayjs(query.end_date).format(FORMAT_API_DATE);
28+
}
29+
const { data } = await Api.getStatsEventsByOrganizationAggregated(params);
30+
31+
if (data.length === 0) {
32+
return [];
33+
}
34+
35+
return data.map(item => ({
36+
name: item.organization_name,
37+
id: item.organization_id,
38+
total_events: item.total ?? 0,
39+
low: item['< 1e-5'] ?? 0,
40+
medium: item['1e-3 .. 1e-5'] ?? 0,
41+
high: item['> 1e-3'] ?? 0,
42+
}));
5143
};
Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
11
'use server';
22

3-
import type { TypeGetStatsEventsBySatelliteParams } from '@/__generated__/data-contracts';
3+
import dayjs from 'dayjs';
4+
5+
import type { TypeGetStatsEventsBySatelliteAggregatedParams } from '@/__generated__/data-contracts';
46
import Api from '@/libs/Api';
7+
import { FORMAT_API_DATE } from '@/libs/Dayjs';
58

69
export type EventsBySatelliteType = {
710
name: string;
8-
id: string;
911
low: number;
1012
medium: number;
1113
high: number;
1214
organization_name: string;
1315
};
1416

15-
export async function getStatsEventsBySatellite(query?: TypeGetStatsEventsBySatelliteParams): Promise<EventsBySatelliteType[]> {
16-
const { data } = await Api.getStatsEventsBySatellite(query);
17-
18-
const groupedData = data.reduce((acc, item) => {
19-
const { common_name, norad_id, events, collision_probability_range, organization_name } = item;
20-
21-
const key = norad_id;
22-
23-
if (!acc[key]) {
24-
acc[key] = { name: common_name, id: norad_id, organization_name, low: 0, medium: 0, high: 0 };
25-
}
26-
27-
switch (collision_probability_range) {
28-
case '< 1e-5':
29-
acc[key].low = events;
30-
break;
31-
case '1e-3 .. 1e-5':
32-
acc[key].medium = events;
33-
break;
34-
case '> 1e-3':
35-
acc[key].high = events;
36-
break;
37-
}
38-
39-
return acc;
40-
}, {} as { [key: string]: EventsBySatelliteType });
41-
42-
return Object.values(groupedData);
17+
export async function getStatsEventsBySatellite(query?: TypeGetStatsEventsBySatelliteAggregatedParams): Promise<EventsBySatelliteType[]> {
18+
const params: TypeGetStatsEventsBySatelliteAggregatedParams = {};
19+
20+
if (query?.start_date) {
21+
params.start_date = dayjs(query.start_date).format(FORMAT_API_DATE);
22+
}
23+
if (query?.end_date) {
24+
params.end_date = dayjs(query.end_date).format(FORMAT_API_DATE);
25+
}
26+
const { data } = await Api.getStatsEventsBySatelliteAggregated(params);
27+
28+
if (data.length === 0) {
29+
return [];
30+
}
31+
32+
return data.map(item => ({
33+
name: item.satellite_common_name,
34+
organization_name: item.organization_name,
35+
low: item['< 1e-5'] ?? 0,
36+
medium: item['1e-3 .. 1e-5'] ?? 0,
37+
high: item['> 1e-3'] ?? 0,
38+
}));
4339
};

src/actions/getStatsMonthlyConjunctionEvents.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
'use server';
22

3-
import { groupBy } from 'lodash';
4-
5-
import type { TypeGetStatsMonthlyConjunctionEventsParams } from '@/__generated__/data-contracts';
3+
import type { TypeGetStatsMonthlyConjunctionEventsAggregatedParams } from '@/__generated__/data-contracts';
64
import Api from '@/libs/Api';
75
import { dayjs, FORMAT_API_DATE } from '@/libs/Dayjs';
86

@@ -18,31 +16,26 @@ export type StatsMonthlyConjunctionEvent = {
1816
};
1917

2018
export async function getStatsMonthlyConjunctionEvents({ months }: StatsMonthlyConjunctionEventsParams): Promise<StatsMonthlyConjunctionEvent[]> {
21-
const queryParams: TypeGetStatsMonthlyConjunctionEventsParams = {
19+
const queryParams: TypeGetStatsMonthlyConjunctionEventsAggregatedParams = {
2220
end_date: dayjs().format(FORMAT_API_DATE),
2321
};
2422
if (months) {
2523
queryParams.start_date = dayjs().subtract(months, 'month').format(FORMAT_API_DATE);
2624
}
2725

2826
try {
29-
const { data } = await Api.getStatsMonthlyConjunctionEvents(queryParams);
30-
31-
const groupedByMonth = groupBy(data, 'month');
32-
33-
const groupedData = Object.entries(groupedByMonth).map(([month, events]) => {
34-
const high = events.find(event => event.collision_probability_range === '> 1e-3')?.count ?? 0;
35-
const medium = events.find(event => event.collision_probability_range === '1e-3 .. 1e-5')?.count ?? 0;
36-
const low = events.find(event => event.collision_probability_range === '< 1e-5')?.count ?? 0;
37-
return {
38-
month: dayjs(month).format('MM/YYYY'),
39-
high,
40-
medium,
41-
low,
42-
};
43-
});
44-
45-
return groupedData;
27+
const { data } = await Api.getStatsMonthlyConjunctionEventsAggregated(queryParams);
28+
29+
if (data.length === 0) {
30+
return [];
31+
}
32+
33+
return data.map(item => ({
34+
month: item.month ?? '',
35+
low: item['< 1e-5'] ?? 0,
36+
medium: item['1e-3 .. 1e-5'] ?? 0,
37+
high: item['> 1e-3'] ?? 0,
38+
}));
4639
} catch (error) {
4740
console.error(error);
4841
return [];
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use server';
22

3-
import { groupBy } from 'lodash';
4-
53
import type { TypeGetStatsMonthlyOrganizationsParams } from '@/__generated__/data-contracts';
64
import Api from '@/libs/Api';
75
import { dayjs } from '@/libs/Dayjs';
@@ -15,23 +13,19 @@ export type StatsMonthlyConjunctionEventsByObjectType = {
1513
};
1614

1715
export async function getStatsMonthlyConjunctionEventsByObjectType(query?: TypeGetStatsMonthlyOrganizationsParams): Promise<StatsMonthlyConjunctionEventsByObjectType[]> {
18-
const { data } = await Api.getStatsMonthlyConjunctionEventsByObjectType(query);
19-
20-
const groupedByMonth = groupBy(data, 'month');
16+
const { data } = await Api.getStatsMonthlyConjunctionEventsByObjectTypeAggregated(query);
2117

22-
const groupedData = Object.entries(groupedByMonth).map(([month, events]) => {
23-
const DEBRIS = events.find(event => event.event_type === 'Events with debris')?.count || 0;
24-
const ANOTHER_SATELLITE = events.find(event => event.event_type === 'Events with another satellite')?.count || 0;
25-
const WITH_UK_SATELLITES = events.find(event => event.event_type === 'Events with two UK-licensed satellites')?.count || 0;
26-
const OTHER = events.find(event => event.event_type === 'Events with other objects (unknown/rocket body)')?.count || 0;
18+
return data.map((event) => {
19+
const DEBRIS = event['Events with debris'] || 0;
20+
const ANOTHER_SATELLITE = event['Events with another satellite'] || 0;
21+
const WITH_UK_SATELLITES = event['Events with two UK-licensed satellites'] || 0;
22+
const OTHER = event['Events with other objects (unknown/rocket body)'] || 0;
2723
return {
28-
month: dayjs(month).format('MM/YYYY'),
24+
month: dayjs(event.month).format('MM/YYYY'),
2925
DEBRIS,
3026
ANOTHER_SATELLITE,
3127
WITH_UK_SATELLITES,
3228
OTHER,
3329
};
3430
});
35-
36-
return groupedData;
3731
}

src/app/(auth)/account/analysis-upload-log/page.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import type { Metadata } from 'next';
22
import { notFound } from 'next/navigation';
33
import { getTranslations } from 'next-intl/server';
4-
import { Suspense } from 'react';
54

65
import type { TypeAnalysesSortBy, TypeGetAnalysesParams } from '@/__generated__/data-contracts';
76
import { getAnalyses } from '@/actions/getAnalyses';
87
import { getUsersMe } from '@/actions/getUsersMe';
98
import { AnalysisDataTable } from '@/components/account/analysis-upload-log/AnalysisDataTable';
109
import Details from '@/ui/details/details';
11-
import Spinner from '@/ui/spinner/spinner';
1210
import { isAnalysist } from '@/utils/Roles';
1311

1412
export const metadata: Metadata = {
@@ -42,9 +40,7 @@ export default async function AnalysisUploadLog(props: {
4240
<div>
4341
<h1 className="govuk-heading-xl">{t('title')}</h1>
4442
<p className="govuk-body">{t('description')}</p>
45-
<Suspense key={query} fallback={<Spinner />}>
46-
<AnalysisDataTable data={data} params={params} />
47-
</Suspense>
43+
<AnalysisDataTable data={data} params={params} />
4844
<div className="mt-2">
4945
<Details summary={t.rich('help.title')}>
5046
{t.rich('help.description1')}

0 commit comments

Comments
 (0)