Skip to content

Commit e460804

Browse files
committed
add examples
1 parent 79555d9 commit e460804

7 files changed

Lines changed: 56 additions & 19 deletions

File tree

public/df_stock_prices_live.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
9.46 KB
Loading

py-src/data_formulator/agents/agent_py_data_rec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
* the column can either be a column in the input data, or a new column that will be computed in the output data.
6868
* the mention don't have to be exact match, it can be semantically matching, e.g., if you mentioned "average score" in the text while the column to be computed is "Avg_Score", you should still highlight "**average score**" in the text.
6969
- determine "input_tables", the names of a subset of input tables from [CONTEXT] section that will be used to achieve the user's goal.
70-
- Note that the first table is the table the user is currently viewing, it should take precedence if the user asks for visualization of the "current table".
70+
- **IMPORTANT** Note that the Table 1 in [CONTEXT] section is the table the user is currently viewing, it should take precedence if the user refers to insights about the "current table".
7171
- At the same time, leverage table information to determine which tables are relevant to the user's goal and should be used.
7272
- "chart_type" must be one of "point", "bar", "line", "area", "heatmap", "group_bar", "boxplot"
7373
- "chart_encodings" should specify which fields should be used to create the visualization

py-src/data_formulator/agents/agent_py_data_transform.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
- **IMPORTANT** Note that the Table 1 in [CONTEXT] section is the table the user is currently viewing, it should take precedence if the user refers to insights about the "current table".
3939
- At the same time, leverage table information to determine which tables are relevant to the user's goal and should be used.
4040
- determine "output_fields", the desired fields that the output data should have to achieve the user's goal, it's a good idea to include intermediate fields here.
41-
- then decide "chart_encodings", which maps visualization channels (x, y, color, size, opacity, facet, etc.) to a subset of "output_fields" that will be visualized,
41+
- then decide "chart_encodings", which maps visualization channels (x, y, color, size, opacity, facet, latitude, longitude, etc.) to a subset of "output_fields" that will be visualized,
4242
- the "chart_encodings" should be created to support the user's "chart_type".
4343
- first, determine whether the user has provided sufficient fields in "chart_encodings" that are needed to achieve their goal:
4444
- if the user's "chart_encodings" are sufficient, simply copy it.
@@ -49,6 +49,7 @@
4949
- if the user's "chart_encodings" is sufficient but can be optimized, you can reorder encodings to visualize the data more effectively.
5050
- sometimes, user may provide instruction to update visualizations fields they provided. You should leverage the user's goal to resolve the conflict and decide the final "chart_encodings"
5151
- e.g., they may mention "use B metric instead" while A metric is in provided fields, in this case, you should update "chart_encodings" to update A metric with B metric.
52+
- if the user provides latitude and longitude as visual channels, use "latitude" and "longitude" as visual channels in "chart_encodings" as opposed to "x" and "y".
5253
- guide on statistical analysis:
5354
- when the user asks for forecasting or regression analysis, you should consider the following:
5455
- the output should be a long format table where actual x, y pairs and predicted x, y pairs are included in the X, Y columns, they are differentiated with a third column "is_predicted".

src/app/useDataRefresh.tsx

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export function useDataRefresh() {
2727
const timeoutRefs = useRef<Map<string, NodeJS.Timeout>>(new Map());
2828
const refreshInProgressRef = useRef<Map<string, boolean>>(new Map());
2929
const isActiveRef = useRef<Map<string, boolean>>(new Map());
30+
const initializedTablesRef = useRef<Set<string>>(new Set()); // Track tables that have been initialized
3031
const lastMessageTimeRef = useRef<number>(0);
3132
const MESSAGE_THROTTLE_MS = 10000; // 10 seconds
3233

@@ -316,6 +317,7 @@ export function useDataRefresh() {
316317
/**
317318
* Set up refresh intervals for tables with auto-refresh enabled.
318319
* Uses recursive setTimeout pattern to ensure updates wait until complete.
320+
* Triggers immediate refresh for newly loaded tables.
319321
*/
320322
useEffect(() => {
321323
// Clear all existing timeouts
@@ -334,22 +336,44 @@ export function useDataRefresh() {
334336

335337
if (shouldAutoRefresh) {
336338
const intervalMs = source.refreshIntervalSeconds! * 1000;
339+
const isNewTable = !initializedTablesRef.current.has(table.id);
337340

338-
console.log(`[DataRefresh] Setting up auto-refresh for "${table.id}" every ${source.refreshIntervalSeconds}s (waiting for completion)`);
341+
console.log(`[DataRefresh] Setting up auto-refresh for "${table.id}" every ${source.refreshIntervalSeconds}s (new=${isNewTable})`);
339342

340-
// Mark as active
343+
// Mark as active and initialized
341344
isActiveRef.current.set(table.id, true);
345+
initializedTablesRef.current.add(table.id);
342346

343-
// Start the refresh cycle - first refresh happens after interval, then schedules next after completion
344-
const initialTimeout = setTimeout(async () => {
345-
if (!isActiveRef.current.get(table.id)) {
346-
return;
347-
}
348-
await performRefresh(table);
349-
scheduleNextRefresh(table.id);
350-
}, intervalMs);
347+
if (isNewTable) {
348+
// For newly loaded tables, trigger immediate refresh then schedule next
349+
console.log(`[DataRefresh] Triggering immediate first refresh for newly loaded table "${table.id}"`);
350+
(async () => {
351+
if (!isActiveRef.current.get(table.id)) {
352+
return;
353+
}
354+
await performRefresh(table);
355+
scheduleNextRefresh(table.id);
356+
})();
357+
} else {
358+
// For existing tables, continue with normal interval
359+
const initialTimeout = setTimeout(async () => {
360+
if (!isActiveRef.current.get(table.id)) {
361+
return;
362+
}
363+
await performRefresh(table);
364+
scheduleNextRefresh(table.id);
365+
}, intervalMs);
366+
367+
timeoutRefs.current.set(table.id, initialTimeout);
368+
}
369+
}
370+
});
351371

352-
timeoutRefs.current.set(table.id, initialTimeout);
372+
// Clean up tables that no longer exist from the initialized set
373+
const currentTableIds = new Set(tables.map(t => t.id));
374+
initializedTablesRef.current.forEach(tableId => {
375+
if (!currentTableIds.has(tableId)) {
376+
initializedTablesRef.current.delete(tableId);
353377
}
354378
});
355379

src/views/DataFormulator.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ export const DataFormulatorFC = ({ }) => {
5555
const theme = useTheme();
5656

5757
const dispatch = useDispatch();
58-
59-
// Set up auto-refresh for streaming and database tables
60-
const { manualRefresh, getRefreshInfo } = useDataRefresh();
6158

6259
// Set up automatic refresh of derived tables when source data changes
6360
useDerivedTableRefresh();

src/views/ExampleSessions.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
alpha,
1212
useTheme,
1313
} from '@mui/material';
14+
import StreamIcon from '@mui/icons-material/Stream';
1415

1516
// Example session data for pre-built sessions
1617
export interface ExampleSession {
@@ -19,36 +20,49 @@ export interface ExampleSession {
1920
description: string;
2021
previewImage: string;
2122
dataFile: string;
23+
live: boolean;
2224
}
2325

2426
export const exampleSessions: ExampleSession[] = [
27+
{
28+
id: 'stock-prices-live',
29+
title: 'Stock Prices (Live)',
30+
description: 'Live stock prices for different companies',
31+
previewImage: '/screenshot-stock-price-live-thumbnail.webp',
32+
dataFile: '/df_stock_prices_live.json',
33+
live: true,
34+
},
2535
{
2636
id: 'gas-prices',
2737
title: 'Gas Prices',
2838
description: 'Weekly gas prices across different grades and formulations',
2939
previewImage: '/gas_prices-thumbnail.webp',
3040
dataFile: '/df_gas_prices.json',
41+
live: false,
3142
},
3243
{
3344
id: 'global-energy',
3445
title: 'Global Energy',
3546
description: 'Explore global energy consumption and CO2 emissions data',
3647
previewImage: '/global_energy-thumbnail.webp',
37-
dataFile: '/df_global_energy.json',
48+
dataFile: '/df_global_energy.json',
49+
live: false,
3850
},
3951
{
4052
id: 'movies',
4153
title: 'Movies',
4254
description: 'Analyze movie performance, budgets, and ratings data',
4355
previewImage: '/movies-thumbnail.webp',
4456
dataFile: '/df_movies.json',
57+
live: false,
4558
},
4659
{
4760
id: 'unemployment',
4861
title: 'Unemployment',
4962
description: 'Unemployment rates across different industries over time',
5063
previewImage: '/unemployment-thumbnail.webp',
5164
dataFile: '/df_unemployment.json',
65+
live: false,
5266
}
5367
];
5468

@@ -66,7 +80,7 @@ export const ExampleSessionCard: React.FC<{
6680
cursor: disabled ? 'default' : 'pointer',
6781
'&:hover': disabled ? {} : {
6882
transform: 'translateY(-2px)',
69-
borderColor: alpha(theme.palette.primary.main, 0.4),
83+
borderColor: session.live ? alpha(theme.palette.secondary.main, 0.4) : alpha(theme.palette.primary.main, 0.4),
7084
},
7185
}}
7286
onClick={disabled ? undefined : onClick}
@@ -111,7 +125,7 @@ export const ExampleSessionCard: React.FC<{
111125
overflow: 'hidden'
112126
}}
113127
>
114-
<span style={{textDecoration: 'underline'}}>{session.title}:</span> {session.description}
128+
{session.live && <StreamIcon sx={{ fontSize: 10, color: 'success.main' }} />} <span style={{textDecoration: 'underline'}}>{session.title}:</span> {session.description}
115129
</Typography>
116130
</Box>
117131
</CardContent>

0 commit comments

Comments
 (0)