Skip to content

Commit c3a89db

Browse files
authored
Embedded Single Card: get loadable time series selector (#6512)
Create a separate selector for the internal single card to fetch time series data with a given card Id.
1 parent 6391e40 commit c3a89db

File tree

2 files changed

+66
-8
lines changed

2 files changed

+66
-8
lines changed

tensorboard/webapp/metrics/store/metrics_selectors.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,20 +113,30 @@ export const getCardLoadState = createSelector(
113113
}
114114
);
115115

116+
export const getLoadableTimeSeries = memoize((cardMetadata: CardMetadata) => {
117+
return createSelector(
118+
(state: MetricsState): MetricsState => state,
119+
(state: MetricsState): DeepReadonly<RunToSeries> | null => {
120+
const {plugin, tag, sample} = cardMetadata;
121+
const loadable = storeUtils.getTimeSeriesLoadable(
122+
state.timeSeriesData,
123+
plugin,
124+
tag,
125+
sample
126+
);
127+
return loadable ? loadable.runToSeries : null;
128+
}
129+
);
130+
});
131+
116132
export const getCardTimeSeries = createSelector(
117133
selectMetricsState,
118134
(state: MetricsState, cardId: CardId): DeepReadonly<RunToSeries> | null => {
119135
if (!state.cardMetadataMap.hasOwnProperty(cardId)) {
120136
return null;
121137
}
122-
const {plugin, tag, sample} = state.cardMetadataMap[cardId];
123-
const loadable = storeUtils.getTimeSeriesLoadable(
124-
state.timeSeriesData,
125-
plugin,
126-
tag,
127-
sample
128-
);
129-
return loadable ? loadable.runToSeries : null;
138+
139+
return getLoadableTimeSeries(state.cardMetadataMap[cardId])(state);
130140
}
131141
);
132142

tensorboard/webapp/metrics/store/metrics_selectors_test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,54 @@ describe('metrics selectors', () => {
404404
});
405405
});
406406

407+
describe('getLoadableTimeSeries', () => {
408+
it('getLoadableTimeSeries', () => {
409+
const sampleScalarRunToSeries = {
410+
run1: createScalarStepData(),
411+
run2: createScalarStepData(),
412+
};
413+
const state = buildMetricsState({
414+
timeSeriesData: {
415+
...createTimeSeriesData(),
416+
scalars: {
417+
tagA: {
418+
runToLoadState: {
419+
run1: DataLoadState.LOADED,
420+
run2: DataLoadState.LOADED,
421+
},
422+
runToSeries: sampleScalarRunToSeries,
423+
},
424+
},
425+
},
426+
});
427+
428+
expect(
429+
selectors.getLoadableTimeSeries({
430+
plugin: PluginType.SCALARS,
431+
tag: 'tagA',
432+
runId: null,
433+
})(state)
434+
).toEqual(sampleScalarRunToSeries);
435+
});
436+
437+
it('returns null when plugin data does not contain tag', () => {
438+
const state = buildMetricsState({
439+
timeSeriesData: {
440+
...createTimeSeriesData(),
441+
scalars: {},
442+
},
443+
});
444+
445+
expect(
446+
selectors.getLoadableTimeSeries({
447+
plugin: PluginType.SCALARS,
448+
tag: 'tagA',
449+
runId: null,
450+
})(state)
451+
).toBeNull();
452+
});
453+
});
454+
407455
describe('getCardStepIndex', () => {
408456
it('returns null if no card exists', () => {
409457
selectors.getCardStepIndexMetaData.release();

0 commit comments

Comments
 (0)