-
Notifications
You must be signed in to change notification settings - Fork 0
update: save kgird data to context #151
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import type { PointsGridDataProviderSchema } from "@mat3ra/esse/dist/js/types"; | ||
| import type { MaterialExternalContext } from "../../mixins/MaterialContextMixin"; | ||
| type UnitContext = Array<{ | ||
| name?: string; | ||
| data?: PointsGridDataProviderSchema; | ||
| }> | unknown; | ||
| export declare function getKgridDataFromUnitContext(context: UnitContext): PointsGridDataProviderSchema | undefined; | ||
| export declare function getEffectiveKgridPrecision(kgridData: PointsGridDataProviderSchema, externalContext: MaterialExternalContext): { | ||
| value: number; | ||
| metric: NonNullable<PointsGridDataProviderSchema["gridMetricType"]>; | ||
| }; | ||
| export {}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.getKgridDataFromUnitContext = getKgridDataFromUnitContext; | ||
| exports.getEffectiveKgridPrecision = getEffectiveKgridPrecision; | ||
| const KGridFormDataManager_1 = __importDefault(require("./KGridFormDataManager")); | ||
| function getKgridDataFromUnitContext(context) { | ||
| if (!context) { | ||
| return undefined; | ||
| } | ||
| if (Array.isArray(context)) { | ||
| const item = context.find((entry) => (entry === null || entry === void 0 ? void 0 : entry.name) === "kgrid"); | ||
| return item === null || item === void 0 ? void 0 : item.data; | ||
| } | ||
| if (typeof context === "object" && context !== null && "kgrid" in context) { | ||
| return context.kgrid; | ||
| } | ||
| return undefined; | ||
| } | ||
| function getEffectiveKgridPrecision(kgridData, externalContext) { | ||
| var _a, _b; | ||
| const provider = new KGridFormDataManager_1.default({ name: "kgrid", data: kgridData }, externalContext); | ||
| provider.setData(provider.getData()); | ||
| const normalized = provider.getData(); | ||
| return { | ||
| value: (_a = normalized.gridMetricValue) !== null && _a !== void 0 ? _a : -1, | ||
| metric: (_b = normalized.gridMetricType) !== null && _b !== void 0 ? _b : "KPPRA", | ||
| }; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -105,6 +105,11 @@ abstract class ContextProvider< | |
| this.data = Utils.clone.deepClone(data); | ||
| } | ||
|
|
||
| /** Re-run `setData` normalization before persisting (e.g. derive grid metric from dimensions). */ | ||
| syncPersistentData() { | ||
| this.setData(this.getData()); | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now for example if we use (2 2 2) kgrid on Si2, then the gridMetricValue is still shown "5" by default in UI -- which is not true, the "16" value is used in calculations. |
||
|
|
||
| /** | ||
| * Derive template-facing `data` from persisted `data`. Override when the template needs fields | ||
| * that must not be stored (e.g. coordinates from symmetry point names + lattice). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,9 @@ type SetExecutableProps = { | |
| flavorName?: string; | ||
| }; | ||
|
|
||
| /** Context items always serialized on the unit so rupy can store them in scope after execution. */ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
| const CONTEXT_SCOPE_ITEMS = new Set(["kgrid"]); | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No premature optimization. Either storing full contexts on each unit -- which will be too much, or specifying those that are actually needed during the job running |
||
| class ExecutionUnit extends (BaseUnit as Base) implements Schema { | ||
| inputInstances: ExecutionUnitInput[] = []; | ||
|
|
||
|
|
@@ -228,8 +231,12 @@ class ExecutionUnit extends (BaseUnit as Base) implements Schema { | |
| } | ||
|
|
||
| savePersistentContext() { | ||
| this.contextProvidersInstances | ||
| .filter((p) => CONTEXT_SCOPE_ITEMS.has(p.name)) | ||
| .forEach((p) => p.syncPersistentData()); | ||
|
|
||
| const persistentItems = this.contextProvidersInstances.map((p) => p.getContextItemData()); | ||
| this.context = persistentItems.filter((c) => c.isEdited); | ||
| this.context = persistentItems.filter((c) => c.isEdited || CONTEXT_SCOPE_ITEMS.has(c.name)); | ||
| } | ||
|
|
||
| saveRenderingContext(externalContext: ExternalContext) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//as commentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a test for this