Skip to content

Commit

Permalink
make ctx.view saved view aware for python operators
Browse files Browse the repository at this point in the history
  • Loading branch information
imanjra committed Apr 3, 2024
1 parent 8331d26 commit e688343
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions app/packages/operators/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function useCurrentSample() {
function useOperatorThrottledContextSetter() {
const datasetName = useRecoilValue(fos.datasetName);
const view = useRecoilValue(fos.view);
const viewName = useRecoilValue(fos.viewName);
const extendedStages = useRecoilValue(fos.extendedStages);
const filters = useRecoilValue(fos.filters);
const selectedSamples = useRecoilValue(fos.selectedSamples);
Expand All @@ -53,6 +54,7 @@ function useOperatorThrottledContextSetter() {
selectedSamples,
selectedLabels,
currentSample,
viewName,
});
}, [
setThrottledContext,
Expand All @@ -63,6 +65,7 @@ function useOperatorThrottledContextSetter() {
selectedSamples,
selectedLabels,
currentSample,
viewName,
]);
}

Expand Down
5 changes: 5 additions & 0 deletions app/packages/operators/src/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ async function executeOperatorAsGenerator(
selected_labels: formatSelectedLabels(currentContext.selectedLabels),
current_sample: currentContext.currentSample,
request_delegation: ctx.requestDelegation,
view_name: currentContext.viewName,
},
"json-stream"
);
Expand Down Expand Up @@ -542,6 +543,7 @@ export async function executeOperatorWithContext(
current_sample: currentContext.currentSample,
delegation_target: ctx.delegationTarget,
request_delegation: ctx.requestDelegation,
view_name: currentContext.viewName,
}
);
result = serverResult.result;
Expand Down Expand Up @@ -608,6 +610,7 @@ export async function resolveRemoteType(
results: results ? results.result : null,
delegated: results ? results.delegated : null,
current_sample: currentContext.currentSample,
view_name: currentContext.viewName,
}
);

Expand Down Expand Up @@ -675,6 +678,7 @@ export async function resolveExecutionOptions(
? Array.from(currentContext.selectedSamples)
: [],
selected_labels: formatSelectedLabels(currentContext.selectedLabels),
view_name: currentContext.viewName,
}
);

Expand Down Expand Up @@ -703,6 +707,7 @@ export async function fetchRemotePlacements(ctx: ExecutionContext) {
: [],
selected_labels: formatSelectedLabels(currentContext.selectedLabels),
current_sample: currentContext.currentSample,
view_name: currentContext.viewName,
}
);
if (result && result.error) {
Expand Down
6 changes: 6 additions & 0 deletions app/packages/operators/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const globalContextSelector = selector({
const selectedSamples = get(fos.selectedSamples);
const selectedLabels = get(fos.selectedLabels);
const currentSample = get(fos.currentSampleId);
const viewName = get(fos.viewName);

return {
datasetName,
Expand All @@ -92,6 +93,7 @@ const globalContextSelector = selector({
selectedSamples,
selectedLabels,
currentSample,
viewName,
};
},
});
Expand Down Expand Up @@ -121,6 +123,7 @@ const useExecutionContext = (operatorName, hooks = {}) => {
params,
selectedLabels,
currentSample,
viewName,
} = curCtx;
const ctx = useMemo(() => {
return new ExecutionContext(
Expand All @@ -133,6 +136,7 @@ const useExecutionContext = (operatorName, hooks = {}) => {
selectedSamples,
selectedLabels,
currentSample,
viewName,
},
hooks
);
Expand All @@ -145,6 +149,8 @@ const useExecutionContext = (operatorName, hooks = {}) => {
selectedSamples,
selectedLabels,
hooks,
viewName,
currentSample,
]);

return ctx;
Expand Down
25 changes: 15 additions & 10 deletions fiftyone/operators/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| `voxel51.com <https://voxel51.com/>`_
|
"""

import asyncio
import collections
import inspect
Expand Down Expand Up @@ -503,20 +504,24 @@ def view(self):

# Always derive the view from the context's dataset
dataset = self.dataset
view_name = self.request_params.get("view_name", None)
stages = self.request_params.get("view", None)
filters = self.request_params.get("filters", None)
extended = self.request_params.get("extended", None)

if dataset is None:
return None

self._view = fosv.get_view(
dataset,
stages=stages,
filters=filters,
extended_stages=extended,
reload=False,
)
if view_name is None:
self._view = fosv.get_view(
dataset,
stages=stages,
filters=filters,
extended_stages=extended,
reload=False,
)
else:
self._view = dataset.load_saved_view(view_name)

return self._view

Expand Down Expand Up @@ -797,9 +802,9 @@ def to_json(self):
"executor": self.executor.to_json() if self.executor else None,
"error": self.error,
"delegated": self.delegated,
"validation_ctx": self.validation_ctx.to_json()
if self.validation_ctx
else None,
"validation_ctx": (
self.validation_ctx.to_json() if self.validation_ctx else None
),
}


Expand Down

0 comments on commit e688343

Please sign in to comment.