feat: Implement AnalyzerManager for dynamic simulation analysis data binding to dashboard label-value and graph elements, including custom predictive insight UI.

This commit is contained in:
2025-12-22 18:03:18 +05:30
parent f2670538e7
commit e4a6013248
2 changed files with 17 additions and 11 deletions

View File

@@ -144,8 +144,14 @@ const AnalyzerManager: React.FC = () => {
const rawDataValue = element.dataBinding.dataValue; const rawDataValue = element.dataBinding.dataValue;
const dataKeys = Array.isArray(rawDataValue) ? rawDataValue : [rawDataValue as string]; const dataKeys = Array.isArray(rawDataValue) ? rawDataValue : [rawDataValue as string];
const assetAnalysis = getAssetAnalysis(assetId); let dataObject: any = null;
if (assetAnalysis) { if (assetId === "global") {
dataObject = getSystemMetrics();
} else {
dataObject = getAssetAnalysis(assetId);
}
if (dataObject) {
let newGraphData: GraphDataPoint[] = []; let newGraphData: GraphDataPoint[] = [];
if (element.graphType === "line") { if (element.graphType === "line") {
@@ -155,16 +161,11 @@ const AnalyzerManager: React.FC = () => {
const dataPoint: GraphDataPoint = { name: timeStr, value: 0 }; const dataPoint: GraphDataPoint = { name: timeStr, value: 0 };
dataKeys.forEach((key) => { dataKeys.forEach((key) => {
const val = resolvePath(assetAnalysis, key); const path = assetId === "global" && key.startsWith("global.") ? key.replace("global.", "") : key;
const val = resolvePath(dataObject, path);
dataPoint[key] = typeof val === "number" ? val : 0; dataPoint[key] = typeof val === "number" ? val : 0;
}); });
// Add slight variations if values are static to make it "live" as requested (optional, but requested "up and down")
// If the user feels the values are strictly from store, I should stick to store.
// "makeing the lines go up dna down as times goes on"
// If I just use store values, they might be flat.
// I will stick to store values. The user's system likely updates `analysis`.
history.push(dataPoint); history.push(dataPoint);
if (history.length > 20) history.shift(); if (history.length > 20) history.shift();
@@ -172,7 +173,8 @@ const AnalyzerManager: React.FC = () => {
lineChartHistory.current.set(element.elementUuid, history); lineChartHistory.current.set(element.elementUuid, history);
} else { } else {
newGraphData = dataKeys.map((key) => { newGraphData = dataKeys.map((key) => {
const val = resolvePath(assetAnalysis, key); const path = assetId === "global" && key.startsWith("global.") ? key.replace("global.", "") : key;
const val = resolvePath(dataObject, path);
return { return {
// Make the key readable or just use it as name // Make the key readable or just use it as name
name: key.split(".").pop() || key, name: key.split(".").pop() || key,

View File

@@ -183,7 +183,11 @@ const ElementData: React.FC<ElementDataProps> = ({
key={field.id} key={field.id}
label={field.label} label={field.label}
options={field.options} options={field.options}
selected={getEventByModelUuid(selectedProduct.productUuid, element.dataBinding?.dataSource as string)?.modelName ?? ""} selected={
element.dataBinding?.dataSource === "global"
? "Global"
: getEventByModelUuid(selectedProduct.productUuid, element.dataBinding?.dataSource as string)?.modelName ?? ""
}
onSelect={(value) => { onSelect={(value) => {
updateDataSource(selectedBlock, selectedElement, value.id); updateDataSource(selectedBlock, selectedElement, value.id);
}} }}