Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Fix charts for dataset v3.0 (#5)
Browse files
src/app/[org]/[dataset]/[episode]/fetch-data.ts
CHANGED
|
@@ -451,7 +451,31 @@ function processEpisodeDataForCharts(
|
|
| 451 |
};
|
| 452 |
|
| 453 |
// Columns to exclude from charts
|
| 454 |
-
const excludedColumns = ['index', 'task_index', 'episode_index', 'frame_index'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
// First, extract all series from the first data row to understand the structure
|
| 457 |
if (episodeData.length > 0) {
|
|
@@ -467,10 +491,14 @@ function processEpisodeDataForCharts(
|
|
| 467 |
// Skip excluded columns
|
| 468 |
if (excludedColumns.includes(featureName)) return;
|
| 469 |
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 474 |
});
|
| 475 |
} else if (typeof value === 'number' && !isNaN(value)) {
|
| 476 |
// For scalar numeric values
|
|
@@ -483,10 +511,10 @@ function processEpisodeDataForCharts(
|
|
| 483 |
|
| 484 |
seriesNames = ["timestamp", ...allKeys];
|
| 485 |
} else {
|
| 486 |
-
// Fallback to
|
| 487 |
seriesNames = [
|
| 488 |
"timestamp",
|
| 489 |
-
...
|
| 490 |
];
|
| 491 |
}
|
| 492 |
|
|
@@ -502,9 +530,7 @@ function processEpisodeDataForCharts(
|
|
| 502 |
}
|
| 503 |
obj["timestamp"] = (index / Math.max(episodeData.length - 1, 1)) * videoDuration;
|
| 504 |
|
| 505 |
-
//
|
| 506 |
-
|
| 507 |
-
// Add all data columns
|
| 508 |
if (row && typeof row === 'object') {
|
| 509 |
Object.entries(row).forEach(([key, value]) => {
|
| 510 |
if (key === 'timestamp') {
|
|
@@ -518,11 +544,16 @@ function processEpisodeDataForCharts(
|
|
| 518 |
// Skip excluded columns
|
| 519 |
if (excludedColumns.includes(featureName)) return;
|
| 520 |
|
| 521 |
-
|
| 522 |
-
|
|
|
|
|
|
|
|
|
|
| 523 |
value.forEach((val, idx) => {
|
| 524 |
-
|
| 525 |
-
|
|
|
|
|
|
|
| 526 |
});
|
| 527 |
} else if (typeof value === 'number' && !isNaN(value)) {
|
| 528 |
obj[featureName] = value;
|
|
@@ -549,46 +580,15 @@ function processEpisodeDataForCharts(
|
|
| 549 |
...excludedColumns // Also include the manually excluded columns
|
| 550 |
];
|
| 551 |
|
| 552 |
-
// Group processing logic (
|
| 553 |
const numericKeys = seriesNames.filter((k) => k !== "timestamp");
|
| 554 |
-
|
| 555 |
-
// Group keys by prefix (for hierarchical structure like v2)
|
| 556 |
const suffixGroupsMap: Record<string, string[]> = {};
|
| 557 |
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
for (const key of numericKeys) {
|
| 564 |
-
const cleanKey = key.replace(/\[\d+\]$/, ''); // Remove array indices
|
| 565 |
-
const parts = cleanKey.split('.');
|
| 566 |
-
|
| 567 |
-
if (parts.length >= 2) {
|
| 568 |
-
// For keys like "observation.state" or "action.main_shoulder_pan"
|
| 569 |
-
const suffix = parts.slice(1).join('.'); // Everything after first dot
|
| 570 |
-
if (!suffixGroupsMap[suffix]) {
|
| 571 |
-
suffixGroupsMap[suffix] = [];
|
| 572 |
-
}
|
| 573 |
-
suffixGroupsMap[suffix].push(key);
|
| 574 |
-
} else {
|
| 575 |
-
// Keys without dots go in their own group
|
| 576 |
-
if (!suffixGroupsMap[key]) {
|
| 577 |
-
suffixGroupsMap[key] = [];
|
| 578 |
-
}
|
| 579 |
-
suffixGroupsMap[key].push(key);
|
| 580 |
-
}
|
| 581 |
-
}
|
| 582 |
-
} else {
|
| 583 |
-
// For v3 data without hierarchical keys, group by base name (removing array indices)
|
| 584 |
-
for (const key of numericKeys) {
|
| 585 |
-
const baseKey = key.replace(/\[\d+\]$/, '');
|
| 586 |
-
|
| 587 |
-
if (!suffixGroupsMap[baseKey]) {
|
| 588 |
-
suffixGroupsMap[baseKey] = [];
|
| 589 |
-
}
|
| 590 |
-
suffixGroupsMap[baseKey].push(key);
|
| 591 |
-
}
|
| 592 |
}
|
| 593 |
const suffixGroups = Object.values(suffixGroupsMap);
|
| 594 |
|
|
@@ -655,60 +655,34 @@ function processEpisodeDataForCharts(
|
|
| 655 |
return [merged];
|
| 656 |
});
|
| 657 |
|
| 658 |
-
// Utility function to group row keys by suffix
|
| 659 |
function groupRowBySuffix(row: Record<string, number>): Record<string, any> {
|
| 660 |
const result: Record<string, any> = {};
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
// Group by prefix for hierarchical display
|
| 667 |
-
const prefixGroups: Record<string, Record<string, number>> = {};
|
| 668 |
-
|
| 669 |
-
for (const [key, value] of Object.entries(row)) {
|
| 670 |
-
if (key === "timestamp") {
|
| 671 |
-
result["timestamp"] = value;
|
| 672 |
-
continue;
|
| 673 |
-
}
|
| 674 |
-
|
| 675 |
-
const cleanKey = key.replace(/\[\d+\]$/, ''); // Remove array indices
|
| 676 |
-
const parts = cleanKey.split('.');
|
| 677 |
-
|
| 678 |
-
if (parts.length >= 2) {
|
| 679 |
-
const prefix = parts[0];
|
| 680 |
-
const suffix = parts.slice(1).join('.');
|
| 681 |
-
|
| 682 |
-
if (!prefixGroups[suffix]) {
|
| 683 |
-
prefixGroups[suffix] = {};
|
| 684 |
-
}
|
| 685 |
-
|
| 686 |
-
// Store with the prefix as key
|
| 687 |
-
prefixGroups[suffix][prefix] = value;
|
| 688 |
-
} else {
|
| 689 |
-
// Non-hierarchical keys go directly to result
|
| 690 |
-
result[key] = value;
|
| 691 |
-
}
|
| 692 |
-
}
|
| 693 |
-
|
| 694 |
-
// Add grouped data to result
|
| 695 |
-
for (const [suffix, group] of Object.entries(prefixGroups)) {
|
| 696 |
-
const keys = Object.keys(group);
|
| 697 |
-
if (keys.length === 1) {
|
| 698 |
-
// Single value, use full name
|
| 699 |
-
result[`${keys[0]}.${suffix}`] = group[keys[0]];
|
| 700 |
-
} else {
|
| 701 |
-
// Multiple values, create nested structure
|
| 702 |
-
result[suffix] = group;
|
| 703 |
-
}
|
| 704 |
}
|
| 705 |
-
|
| 706 |
-
|
| 707 |
-
|
|
|
|
|
|
|
|
|
|
| 708 |
result[key] = value;
|
| 709 |
}
|
| 710 |
}
|
| 711 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 712 |
return result;
|
| 713 |
}
|
| 714 |
|
|
|
|
| 451 |
};
|
| 452 |
|
| 453 |
// Columns to exclude from charts
|
| 454 |
+
const excludedColumns = ['index', 'task_index', 'episode_index', 'frame_index', 'next.done'];
|
| 455 |
+
|
| 456 |
+
// Create columns structure similar to V2.1 for proper hierarchical naming
|
| 457 |
+
const columns = Object.entries(info.features)
|
| 458 |
+
.filter(([key, value]) =>
|
| 459 |
+
["float32", "int32"].includes(value.dtype) &&
|
| 460 |
+
value.shape.length === 1 &&
|
| 461 |
+
!excludedColumns.includes(key)
|
| 462 |
+
)
|
| 463 |
+
.map(([key, feature]) => {
|
| 464 |
+
let column_names = feature.names;
|
| 465 |
+
while (typeof column_names === "object") {
|
| 466 |
+
if (Array.isArray(column_names)) break;
|
| 467 |
+
column_names = Object.values(column_names ?? {})[0];
|
| 468 |
+
}
|
| 469 |
+
return {
|
| 470 |
+
key,
|
| 471 |
+
value: Array.isArray(column_names)
|
| 472 |
+
? column_names.map((name) => `${key}${SERIES_NAME_DELIMITER}${name}`)
|
| 473 |
+
: Array.from(
|
| 474 |
+
{ length: feature.shape[0] || 1 },
|
| 475 |
+
(_, i) => `${key}${SERIES_NAME_DELIMITER}${i}`,
|
| 476 |
+
),
|
| 477 |
+
};
|
| 478 |
+
});
|
| 479 |
|
| 480 |
// First, extract all series from the first data row to understand the structure
|
| 481 |
if (episodeData.length > 0) {
|
|
|
|
| 491 |
// Skip excluded columns
|
| 492 |
if (excludedColumns.includes(featureName)) return;
|
| 493 |
|
| 494 |
+
// Find the matching column definition to get proper names
|
| 495 |
+
const columnDef = columns.find(col => col.key === featureName);
|
| 496 |
+
if (columnDef && Array.isArray(value) && value.length > 0) {
|
| 497 |
+
// Use the proper hierarchical naming from column definition
|
| 498 |
+
columnDef.value.forEach((seriesName, idx) => {
|
| 499 |
+
if (idx < value.length) {
|
| 500 |
+
allKeys.push(seriesName);
|
| 501 |
+
}
|
| 502 |
});
|
| 503 |
} else if (typeof value === 'number' && !isNaN(value)) {
|
| 504 |
// For scalar numeric values
|
|
|
|
| 511 |
|
| 512 |
seriesNames = ["timestamp", ...allKeys];
|
| 513 |
} else {
|
| 514 |
+
// Fallback to column-based approach like V2.1
|
| 515 |
seriesNames = [
|
| 516 |
"timestamp",
|
| 517 |
+
...columns.map(({ value }) => value).flat(),
|
| 518 |
];
|
| 519 |
}
|
| 520 |
|
|
|
|
| 530 |
}
|
| 531 |
obj["timestamp"] = (index / Math.max(episodeData.length - 1, 1)) * videoDuration;
|
| 532 |
|
| 533 |
+
// Add all data columns using hierarchical naming
|
|
|
|
|
|
|
| 534 |
if (row && typeof row === 'object') {
|
| 535 |
Object.entries(row).forEach(([key, value]) => {
|
| 536 |
if (key === 'timestamp') {
|
|
|
|
| 544 |
// Skip excluded columns
|
| 545 |
if (excludedColumns.includes(featureName)) return;
|
| 546 |
|
| 547 |
+
// Find the matching column definition to get proper series names
|
| 548 |
+
const columnDef = columns.find(col => col.key === featureName);
|
| 549 |
+
|
| 550 |
+
if (Array.isArray(value) && columnDef) {
|
| 551 |
+
// For array values like observation.state and action, use proper hierarchical naming
|
| 552 |
value.forEach((val, idx) => {
|
| 553 |
+
if (idx < columnDef.value.length) {
|
| 554 |
+
const seriesName = columnDef.value[idx];
|
| 555 |
+
obj[seriesName] = typeof val === 'number' ? val : Number(val);
|
| 556 |
+
}
|
| 557 |
});
|
| 558 |
} else if (typeof value === 'number' && !isNaN(value)) {
|
| 559 |
obj[featureName] = value;
|
|
|
|
| 580 |
...excludedColumns // Also include the manually excluded columns
|
| 581 |
];
|
| 582 |
|
| 583 |
+
// Group processing logic (using SERIES_NAME_DELIMITER like v2.1)
|
| 584 |
const numericKeys = seriesNames.filter((k) => k !== "timestamp");
|
|
|
|
|
|
|
| 585 |
const suffixGroupsMap: Record<string, string[]> = {};
|
| 586 |
|
| 587 |
+
for (const key of numericKeys) {
|
| 588 |
+
const parts = key.split(SERIES_NAME_DELIMITER);
|
| 589 |
+
const suffix = parts[1] || parts[0]; // fallback to key if no delimiter
|
| 590 |
+
if (!suffixGroupsMap[suffix]) suffixGroupsMap[suffix] = [];
|
| 591 |
+
suffixGroupsMap[suffix].push(key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 592 |
}
|
| 593 |
const suffixGroups = Object.values(suffixGroupsMap);
|
| 594 |
|
|
|
|
| 655 |
return [merged];
|
| 656 |
});
|
| 657 |
|
| 658 |
+
// Utility function to group row keys by suffix (same as V2.1)
|
| 659 |
function groupRowBySuffix(row: Record<string, number>): Record<string, any> {
|
| 660 |
const result: Record<string, any> = {};
|
| 661 |
+
const suffixGroups: Record<string, Record<string, number>> = {};
|
| 662 |
+
for (const [key, value] of Object.entries(row)) {
|
| 663 |
+
if (key === "timestamp") {
|
| 664 |
+
result["timestamp"] = value;
|
| 665 |
+
continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 666 |
}
|
| 667 |
+
const parts = key.split(SERIES_NAME_DELIMITER);
|
| 668 |
+
if (parts.length === 2) {
|
| 669 |
+
const [prefix, suffix] = parts;
|
| 670 |
+
if (!suffixGroups[suffix]) suffixGroups[suffix] = {};
|
| 671 |
+
suffixGroups[suffix][prefix] = value;
|
| 672 |
+
} else {
|
| 673 |
result[key] = value;
|
| 674 |
}
|
| 675 |
}
|
| 676 |
+
for (const [suffix, group] of Object.entries(suffixGroups)) {
|
| 677 |
+
const keys = Object.keys(group);
|
| 678 |
+
if (keys.length === 1) {
|
| 679 |
+
// Use the full original name as the key
|
| 680 |
+
const fullName = `${keys[0]}${SERIES_NAME_DELIMITER}${suffix}`;
|
| 681 |
+
result[fullName] = group[keys[0]];
|
| 682 |
+
} else {
|
| 683 |
+
result[suffix] = group;
|
| 684 |
+
}
|
| 685 |
+
}
|
| 686 |
return result;
|
| 687 |
}
|
| 688 |
|
src/components/data-recharts.tsx
CHANGED
|
@@ -19,6 +19,9 @@ type DataGraphProps = {
|
|
| 19 |
|
| 20 |
import React, { useMemo } from "react";
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
export const DataRecharts = React.memo(
|
| 23 |
({ data, onChartsReady }: DataGraphProps) => {
|
| 24 |
// Shared hoveredTime for all graphs
|
|
@@ -47,7 +50,6 @@ export const DataRecharts = React.memo(
|
|
| 47 |
},
|
| 48 |
);
|
| 49 |
|
| 50 |
-
const NESTED_KEY_DELIMITER = ",";
|
| 51 |
|
| 52 |
const SingleDataGraph = React.memo(
|
| 53 |
({
|
|
@@ -66,13 +68,13 @@ const SingleDataGraph = React.memo(
|
|
| 66 |
// Special case: if this is a group value that is a primitive, assign to prefix.key
|
| 67 |
if (typeof value === "number") {
|
| 68 |
if (prefix) {
|
| 69 |
-
result[`${prefix}${
|
| 70 |
} else {
|
| 71 |
result[key] = value;
|
| 72 |
}
|
| 73 |
} else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
| 74 |
// If it's an object, recurse
|
| 75 |
-
Object.assign(result, flattenRow(value, prefix ? `${prefix}${
|
| 76 |
}
|
| 77 |
}
|
| 78 |
// Always keep timestamp at top level if present
|
|
@@ -99,7 +101,7 @@ const SingleDataGraph = React.memo(
|
|
| 99 |
const groups: Record<string, string[]> = {};
|
| 100 |
const singles: string[] = [];
|
| 101 |
dataKeys.forEach((key) => {
|
| 102 |
-
const parts = key.split(
|
| 103 |
if (parts.length > 1) {
|
| 104 |
const group = parts[0];
|
| 105 |
if (!groups[group]) groups[group] = [];
|
|
@@ -148,7 +150,7 @@ const SingleDataGraph = React.memo(
|
|
| 148 |
const groups: Record<string, string[]> = {};
|
| 149 |
const singles: string[] = [];
|
| 150 |
dataKeys.forEach((key) => {
|
| 151 |
-
const parts = key.split(
|
| 152 |
if (parts.length > 1) {
|
| 153 |
const group = parts[0];
|
| 154 |
if (!groups[group]) groups[group] = [];
|
|
@@ -305,7 +307,7 @@ const SingleDataGraph = React.memo(
|
|
| 305 |
{/* Render lines for visible dataKeys only */}
|
| 306 |
{dataKeys.map((key) => {
|
| 307 |
// Use group color for all keys in a group
|
| 308 |
-
const group = key.includes(
|
| 309 |
const color = groupColorMap[group];
|
| 310 |
let strokeDasharray: string | undefined = undefined;
|
| 311 |
if (groups[group] && groups[group].length > 1) {
|
|
|
|
| 19 |
|
| 20 |
import React, { useMemo } from "react";
|
| 21 |
|
| 22 |
+
// Use the same delimiter as the data processing
|
| 23 |
+
const SERIES_NAME_DELIMITER = " | ";
|
| 24 |
+
|
| 25 |
export const DataRecharts = React.memo(
|
| 26 |
({ data, onChartsReady }: DataGraphProps) => {
|
| 27 |
// Shared hoveredTime for all graphs
|
|
|
|
| 50 |
},
|
| 51 |
);
|
| 52 |
|
|
|
|
| 53 |
|
| 54 |
const SingleDataGraph = React.memo(
|
| 55 |
({
|
|
|
|
| 68 |
// Special case: if this is a group value that is a primitive, assign to prefix.key
|
| 69 |
if (typeof value === "number") {
|
| 70 |
if (prefix) {
|
| 71 |
+
result[`${prefix}${SERIES_NAME_DELIMITER}${key}`] = value;
|
| 72 |
} else {
|
| 73 |
result[key] = value;
|
| 74 |
}
|
| 75 |
} else if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
| 76 |
// If it's an object, recurse
|
| 77 |
+
Object.assign(result, flattenRow(value, prefix ? `${prefix}${SERIES_NAME_DELIMITER}${key}` : key));
|
| 78 |
}
|
| 79 |
}
|
| 80 |
// Always keep timestamp at top level if present
|
|
|
|
| 101 |
const groups: Record<string, string[]> = {};
|
| 102 |
const singles: string[] = [];
|
| 103 |
dataKeys.forEach((key) => {
|
| 104 |
+
const parts = key.split(SERIES_NAME_DELIMITER);
|
| 105 |
if (parts.length > 1) {
|
| 106 |
const group = parts[0];
|
| 107 |
if (!groups[group]) groups[group] = [];
|
|
|
|
| 150 |
const groups: Record<string, string[]> = {};
|
| 151 |
const singles: string[] = [];
|
| 152 |
dataKeys.forEach((key) => {
|
| 153 |
+
const parts = key.split(SERIES_NAME_DELIMITER);
|
| 154 |
if (parts.length > 1) {
|
| 155 |
const group = parts[0];
|
| 156 |
if (!groups[group]) groups[group] = [];
|
|
|
|
| 307 |
{/* Render lines for visible dataKeys only */}
|
| 308 |
{dataKeys.map((key) => {
|
| 309 |
// Use group color for all keys in a group
|
| 310 |
+
const group = key.includes(SERIES_NAME_DELIMITER) ? key.split(SERIES_NAME_DELIMITER)[0] : key;
|
| 311 |
const color = groupColorMap[group];
|
| 312 |
let strokeDasharray: string | undefined = undefined;
|
| 313 |
if (groups[group] && groups[group].length > 1) {
|