Skip to content

Commit 8dba99d

Browse files
committed
fix unique profile names
1 parent 86bdcbf commit 8dba99d

File tree

7 files changed

+58
-36
lines changed

7 files changed

+58
-36
lines changed
Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11
{
22
"datasetStart": "2024-245T14:00:00",
33
"profileSet": {
4-
"/orientation": {
4+
"/awake": {
5+
"schema": {
6+
"type": "string"
7+
},
8+
"segments": [
9+
{
10+
"duration": 3000000000,
11+
"dynamics": "foo"
12+
},
13+
{
14+
"duration": 3000000000,
15+
"dynamics": "bar"
16+
}
17+
],
18+
"type": "discrete"
19+
},
20+
"/batteryEnergy": {
521
"schema": {
622
"items": {
7-
"x": {
8-
"type": "real"
9-
},
10-
"y": {
23+
"initial": {
1124
"type": "real"
1225
},
13-
"z": {
26+
"rate": {
1427
"type": "real"
1528
}
1629
},
1730
"type": "struct"
1831
},
1932
"segments": [
2033
{
21-
"duration": 3600000000,
34+
"duration": 40000000,
2235
"dynamics": {
23-
"x": 0,
24-
"y": 0,
25-
"z": 1
36+
"initial": 100,
37+
"rate": -0.5
2638
}
2739
},
2840
{
29-
"duration": 3600000000
30-
},
31-
{
32-
"duration": 3600000000,
41+
"duration": 30000000,
3342
"dynamics": {
34-
"x": 1,
35-
"y": 1,
36-
"z": 0
43+
"initial": 35,
44+
"rate": -0.1
3745
}
3846
}
3947
],
40-
"type": "discrete"
48+
"type": "real"
4149
}
4250
}
43-
}
51+
}

src/components/ResourceList.svelte

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import CloseIcon from '@nasa-jpl/stellar/icons/close.svg?component';
55
import UploadIcon from '@nasa-jpl/stellar/icons/upload.svg?component';
66
import { plan } from '../stores/plan';
7-
import { resourceTypes, simulationDatasetId } from '../stores/simulation';
7+
import { allResourceTypes, simulationDatasetId } from '../stores/simulation';
88
import type { User } from '../types/app';
99
import type { ResourceType } from '../types/simulation';
1010
import type { TimelineItemType } from '../types/timeline';
@@ -27,7 +27,7 @@
2727
let uploadFiles: FileList | undefined;
2828
let uploadFileInput: HTMLInputElement;
2929
30-
$: resourceDataTypes = [...new Set($resourceTypes.map(t => t.schema.type))];
30+
$: resourceDataTypes = $allResourceTypes.map(({ name }) => name);
3131
$: if (user !== null && $plan !== null) {
3232
hasUploadPermission = featurePermissions.externalResources.canCreate(user, $plan);
3333
}
@@ -61,7 +61,7 @@
6161
</script>
6262

6363
<TimelineItemList
64-
items={$resourceTypes}
64+
items={$allResourceTypes}
6565
chartType="line"
6666
typeName="resource"
6767
typeNamePlural="Resources"

src/routes/plans/[id]/+page.svelte

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
import type { ActivityErrorCounts } from '../../../types/errors';
120120
import type { Extension } from '../../../types/extension';
121121
import type { PlanSnapshot } from '../../../types/plan-snapshot';
122-
import type { ResourceType } from '../../../types/simulation';
123122
import type { View, ViewSaveEvent, ViewToggleEvent } from '../../../types/view';
124123
import { getConstraintStatus } from '../../../utilities/constraint';
125124
import effects from '../../../utilities/effects';
@@ -415,17 +414,7 @@
415414
$: if ($initialPlan && browser) {
416415
// Asynchronously fetch resource types
417416
effects.getResourceTypes($initialPlan.model_id, data.user).then(initialResourceTypes => {
418-
const uniqueLookup: Set<string> = new Set();
419-
$resourceTypes = [...initialResourceTypes, ...$externalResources].reduce(
420-
(prevExternalResources: ResourceType[], { name, schema }) => {
421-
if (!uniqueLookup.has(name)) {
422-
uniqueLookup.add(name);
423-
prevExternalResources.push({ name, schema });
424-
}
425-
return prevExternalResources;
426-
},
427-
[],
428-
);
417+
$resourceTypes = initialResourceTypes;
429418
$resourceTypesLoading = false;
430419
});
431420
}

src/stores/simulation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ export const selectedSimulationEventId: Writable<number | null> = writable(null)
100100

101101
/* Derived. */
102102

103+
export const allResourceTypes: Readable<ResourceType[]> = derived(
104+
[resourceTypes, externalResources],
105+
([$resourceTypes, $externalResources]) => {
106+
return $resourceTypes
107+
.map(({ name, schema }) => ({ name, schema }))
108+
.concat($externalResources.map(({ name, schema }) => ({ name, schema })));
109+
},
110+
);
111+
103112
export const spansMap: Readable<SpansMap> = derived(spans, $spans => keyBy($spans, 'span_id'));
104113

105114
export const spanUtilityMaps: Readable<SpanUtilityMaps> = derived(spans, $spans => {

src/types/simulation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Subscription } from './subscribable';
77

88
export type PlanDataset = {
99
dataset: { profiles: Profile[] };
10+
dataset_id: number;
1011
offset_from_plan_start: string;
1112
};
1213

src/utilities/effects.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ import type {
213213
import type { Row, Timeline } from '../types/timeline';
214214
import type { View, ViewDefinition, ViewInsertInput, ViewSlim, ViewUpdateInput } from '../types/view';
215215
import { ActivityDeletionAction } from './activities';
216-
import { convertToQuery, getSearchParameterNumber, setQueryParam } from './generic';
216+
import { compare, convertToQuery, getSearchParameterNumber, setQueryParam } from './generic';
217217
import gql, { convertToGQLArray } from './gql';
218218
import {
219219
showConfirmModal,
@@ -4225,12 +4225,26 @@ const effects = {
42254225
const { plan_dataset: plan_datasets } = data;
42264226
if (plan_datasets != null) {
42274227
let resources: Resource[] = [];
4228+
4229+
const profileMap: Set<string> = new Set();
4230+
plan_datasets.sort(({ dataset_id: datasetIdA }, { dataset_id: datasetIdB }) => {
4231+
return compare(datasetIdA, datasetIdB, false);
4232+
});
4233+
42284234
for (const dataset of plan_datasets) {
42294235
const {
42304236
dataset: { profiles },
42314237
offset_from_plan_start,
42324238
} = dataset;
4233-
const sampledResources: Resource[] = sampleProfiles(profiles, startTimeYmd, offset_from_plan_start);
4239+
const uniqueProfiles: Profile[] = profiles.filter(profile => {
4240+
if (!profileMap.has(profile.name)) {
4241+
profileMap.add(profile.name);
4242+
return true;
4243+
}
4244+
return false;
4245+
});
4246+
4247+
const sampledResources: Resource[] = sampleProfiles(uniqueProfiles, startTimeYmd, offset_from_plan_start);
42344248
resources = [...resources, ...sampledResources];
42354249
}
42364250
return { aborted: false, resources };

src/utilities/gql.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ const gql = {
18031803
type
18041804
}
18051805
}
1806+
dataset_id
18061807
offset_from_plan_start
18071808
}
18081809
}

0 commit comments

Comments
 (0)