remove faker

This commit is contained in:
Nate Kelley 2025-04-25 14:55:47 -06:00
parent 3f3b87f670
commit 14de0c1a8f
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
4 changed files with 176 additions and 92 deletions

View File

@ -1,5 +1,5 @@
import { ChartType } from '@/api/asset_interfaces';
import { faker } from '@faker-js/faker';
export const scatterDataProblematic1 = {
metric_id: '7bbe91e5-7133-50f4-a9b2-5a4663f4848a',
data: [

View File

@ -6,75 +6,82 @@ import {
type BusterChatMessageReasoning_file,
type BusterChatMessageResponse
} from '@/api/asset_interfaces';
import { faker } from '@faker-js/faker';
const MOCK_MESSAGE_RESPONSE = (typeProp?: 'text' | 'file'): BusterChatMessageResponse => {
const type = typeProp || faker.helpers.arrayElement(['text', 'file']);
// Helper functions for predictable data generation
const generateId = (prefix: string, index: number = 0) => `${prefix}-${index}`;
const generateTimestamp = (index: number = 0) => new Date(2024, 0, 1, 0, 0, index).toISOString();
const MOCK_MESSAGE_RESPONSE = (
typeProp?: 'text' | 'file',
index: number = 0
): BusterChatMessageResponse => {
const type = typeProp || (index % 2 === 0 ? 'text' : 'file');
if (type === 'text') {
return {
id: faker.string.uuid(),
id: generateId('response', index),
type,
message: faker.lorem.sentence(),
message: `Sample message ${index}`,
is_final_message: false
};
}
return {
id: faker.string.uuid(),
id: generateId('response', index),
type: 'file',
file_type: faker.helpers.arrayElement(['metric', 'dashboard']),
file_name: faker.system.fileName(),
version_number: faker.number.int({ min: 1, max: 10 }),
filter_version_id: faker.string.uuid(),
file_type: index % 2 === 0 ? 'metric' : 'dashboard',
file_name: `sample-file-${index}.txt`,
version_number: (index % 5) + 1,
filter_version_id: generateId('filter', index),
metadata: [
{
status: 'completed',
message: 'Create your file',
timestamp: 4200
message: `Create your file ${index}`,
timestamp: 4200 + index
}
]
};
};
const MOCK_MESSAGE_REASONING = (
typeProp?: 'text' | 'files' | 'pills'
typeProp?: 'text' | 'files' | 'pills',
index: number = 0
): BusterChatMessageReasoning => {
const type = typeProp || faker.helpers.arrayElement(['text', 'files', 'pills']);
const type = typeProp || ['text', 'files', 'pills'][index % 3];
if (type === 'text') {
return {
id: faker.string.uuid(),
id: generateId('reasoning', index),
type: 'text',
title: faker.lorem.sentence(),
title: `Sample title ${index}`,
status: 'completed',
message: faker.lorem.sentence(),
message: `Sample reasoning message ${index}`,
secondary_title: '4.2 seconds'
};
}
if (type === 'files') {
const MOCK_FILE = (): BusterChatMessageReasoning_file => {
const MOCK_FILE = (fileIndex: number): BusterChatMessageReasoning_file => {
return {
id: faker.string.uuid(),
file_type: faker.helpers.arrayElement(['metric', 'dashboard']),
file_name: faker.system.fileName(),
version_number: faker.number.int({ min: 1, max: 10 }),
id: generateId('file', fileIndex),
file_type: fileIndex % 2 === 0 ? 'metric' : 'dashboard',
file_name: `file-${fileIndex}.txt`,
version_number: (fileIndex % 5) + 1,
status: 'loading',
file: {
text: faker.lorem.sentence(),
text: `Sample file text ${fileIndex}`,
modified: [[0, 100]]
}
};
};
const files = Array.from({ length: 3 }, () => MOCK_FILE());
const files = Array.from({ length: 3 }, (_, i) => MOCK_FILE(i + index));
return {
id: faker.string.uuid(),
id: generateId('reasoning', index),
type: 'files',
title: faker.lorem.sentence(),
secondary_title: faker.lorem.sentence(),
title: `Sample files title ${index}`,
secondary_title: `Sample secondary title ${index}`,
status: 'completed',
file_ids: files.map((f) => f.id),
files: files.reduce<Record<string, BusterChatMessageReasoning_file>>((acc, f) => {
@ -85,24 +92,24 @@ const MOCK_MESSAGE_REASONING = (
}
return {
id: faker.string.uuid(),
id: generateId('reasoning', index),
type: 'pills',
title: faker.lorem.sentence(),
title: `Sample pills title ${index}`,
status: 'completed',
secondary_title: '4.2 seconds',
pill_containers: [
{
title: faker.lorem.sentence(),
title: `Sample pill container ${index}`,
pills: []
}
]
};
};
const MOCK_MESSAGE = (): BusterChatMessage => {
const MOCK_MESSAGE = (messageIndex: number = 0): BusterChatMessage => {
const responseTypes: ('text' | 'file')[] = ['text', 'file', 'file', 'file', 'text'];
const responseMessage = Array.from({ length: 5 }, (_, i) =>
MOCK_MESSAGE_RESPONSE(responseTypes[i])
MOCK_MESSAGE_RESPONSE(responseTypes[i], i + messageIndex * 5)
);
const reasoningTypes: ('text' | 'files' | 'pills')[] = [
@ -113,17 +120,17 @@ const MOCK_MESSAGE = (): BusterChatMessage => {
'files'
];
const reasoningMessage = Array.from({ length: 5 }, (_, i) =>
MOCK_MESSAGE_REASONING(reasoningTypes[i])
MOCK_MESSAGE_REASONING(reasoningTypes[i], i + messageIndex * 5)
);
return {
id: faker.string.uuid(),
created_at: faker.date.past().toISOString(),
id: generateId('message', messageIndex),
created_at: generateTimestamp(messageIndex),
request_message: {
request: faker.lorem.sentence(),
sender_id: faker.string.uuid(),
sender_name: faker.person.fullName(),
sender_avatar: faker.image.avatar()
request: `Sample request ${messageIndex}`,
sender_id: generateId('sender', messageIndex),
sender_name: `User ${messageIndex}`,
sender_avatar: `https://avatar.example.com/user${messageIndex}.jpg`
},
final_reasoning_message: null,
response_message_ids: responseMessage.map((m) => m.id),
@ -146,24 +153,24 @@ const MOCK_MESSAGE = (): BusterChatMessage => {
};
};
export const MOCK_CHAT = (): BusterChat => {
const messages = Array.from({ length: 3 }, () => MOCK_MESSAGE());
export const MOCK_CHAT = (chatIndex: number = 0): BusterChat => {
const messages = Array.from({ length: 3 }, (_, i) => MOCK_MESSAGE(i + chatIndex * 3));
const messageIds = messages.map((m) => m.id);
return {
id: faker.string.uuid(),
title: faker.lorem.sentence(),
is_favorited: faker.datatype.boolean(),
id: generateId('chat', chatIndex),
title: `Sample Chat ${chatIndex}`,
is_favorited: chatIndex % 2 === 0,
message_ids: messageIds,
messages: messages.reduce<Record<string, BusterChatMessage>>((acc, m) => {
acc[m.id] = m;
return acc;
}, {}),
created_at: faker.date.past().toISOString(),
updated_at: faker.date.past().toISOString(),
created_by: faker.person.fullName(),
created_by_id: faker.string.uuid(),
created_by_name: faker.person.fullName(),
created_by_avatar: faker.image.avatar()
created_at: generateTimestamp(chatIndex),
updated_at: generateTimestamp(chatIndex + 1),
created_by: `User ${chatIndex}`,
created_by_id: generateId('user', chatIndex),
created_by_name: `User ${chatIndex}`,
created_by_avatar: `https://avatar.example.com/user${chatIndex}.jpg`
};
};

View File

@ -7,17 +7,71 @@ import {
BusterMetricListItem
} from '@/api/asset_interfaces/metric';
import { ShareRole, VerificationStatus } from '@/api/asset_interfaces/share';
import { faker } from '@faker-js/faker';
const createMockChartConfig = (): IBusterMetricChartConfig => {
const chartType = faker.helpers.arrayElement([
ChartType.Bar,
ChartType.Table,
ChartType.Line,
ChartType.Pie,
ChartType.Scatter,
ChartType.Metric
]);
// Utility functions for predictable mock data generation
const CHART_TYPES = [
ChartType.Bar,
ChartType.Table,
ChartType.Line,
ChartType.Pie,
ChartType.Scatter,
ChartType.Metric
];
const PRODUCT_NAMES = [
'Premium Widget',
'Super Gadget',
'Mega Tool',
'Ultra Device',
'Pro Instrument',
'Advanced System'
];
const generatePredictableWords = (id: string, count: number): string => {
const words = [
'analytics',
'metrics',
'sales',
'performance',
'revenue',
'growth',
'trends',
'insights'
];
const hash = Array.from(id).reduce((acc, char) => acc + char.charCodeAt(0), 0);
const result = [];
for (let i = 0; i < count; i++) {
result.push(words[(hash + i) % words.length]);
}
return result.join(' ');
};
const generatePredictableDate = (id: string): string => {
const hash = Array.from(id).reduce((acc, char) => acc + char.charCodeAt(0), 0);
const date = new Date(2024, 0, (hash % 28) + 1); // Generates a date in January 2024
return date.toISOString();
};
const generatePredictableUUID = (id: string, salt: string = ''): string => {
const hash = Array.from(id + salt).reduce((acc, char) => acc + char.charCodeAt(0), 0);
const segments = [8, 4, 4, 4, 12].map((length, index) => {
return Array.from({ length }, (_, i) => ((hash + index + i) % 16).toString(16)).join('');
});
return segments.join('-');
};
const generatePredictableEmail = (id: string): string => {
const hash = Array.from(id).reduce((acc, char) => acc + char.charCodeAt(0), 0);
const names = ['john', 'jane', 'bob', 'alice', 'charlie'];
const domains = ['example.com', 'test.org', 'mock.net'];
const name = names[hash % names.length];
const domain = domains[(hash + 1) % domains.length];
return `${name}.${hash % 100}@${domain}`;
};
const createMockChartConfig = (id: string): IBusterMetricChartConfig => {
const hash = Array.from(id).reduce((acc, char) => acc + char.charCodeAt(0), 0);
const chartType = CHART_TYPES[hash % CHART_TYPES.length];
return {
...DEFAULT_CHART_CONFIG,
@ -75,25 +129,28 @@ const dataMetadata: DataMetadata = {
};
export const createMockMetric = (id: string): IBusterMetric => {
const chart_config = createMockChartConfig();
const chart_config = createMockChartConfig(id);
return {
name: id + ' - ' + faker.lorem.words({ min: 2, max: 6 }),
name: `${id} - ${generatePredictableWords(id, 3)}`,
version_number: 1,
file_name: `${faker.lorem.words({ min: 1, max: 4 })}.yml`,
description: faker.commerce.productName(),
data_source_id: '6840fa04-c0d7-4e0e-8d3d-ea9190d93874',
file_name: `${generatePredictableWords(id, 2)}.yml`,
description:
PRODUCT_NAMES[
Array.from(id).reduce((acc, char) => acc + char.charCodeAt(0), 0) % PRODUCT_NAMES.length
],
data_source_id: generatePredictableUUID(id, 'source'),
time_frame: '1d',
type: 'metric',
chart_config: chart_config,
dataset_id: '21c91803-c324-4341-98d1-960ef6a3e003',
dataset_id: generatePredictableUUID(id, 'dataset'),
dataset_name: 'Mock Dataset',
error: null,
data_metadata: dataMetadata,
status: VerificationStatus.NOT_REQUESTED,
evaluation_score: 'Moderate',
versions: [],
evaluation_summary: faker.lorem.sentence(33),
evaluation_summary: `Predictable evaluation summary for ${id} showing consistent performance metrics and data quality indicators.`,
file: `
metric:
name: sales_performance
@ -136,11 +193,11 @@ export const createMockMetric = (id: string): IBusterMetric => {
direction: desc
limit: 1000`,
created_at: '',
updated_at: '',
sent_by_id: '',
sent_by_name: '',
sent_by_avatar_url: '',
created_at: generatePredictableDate(id),
updated_at: generatePredictableDate(id),
sent_by_id: generatePredictableUUID(id, 'user'),
sent_by_name: `User ${id}`,
sent_by_avatar_url: `https://avatar.example.com/${id}`,
sql: `WITH records AS (
SELECT
response_time_id,
@ -199,14 +256,16 @@ export const mockMetric30 = createMockMetric('number30');
export const createMockListMetric = (id: string): BusterMetricListItem => ({
id,
name: faker.commerce.productName(),
last_edited: faker.date.recent().toISOString(),
dataset_name: faker.commerce.productName(),
dataset_uuid: faker.string.uuid(),
created_by_id: faker.string.uuid(),
created_by_name: faker.person.fullName(),
created_by_email: faker.internet.email(),
created_by_avatar: faker.image.avatar(),
name: PRODUCT_NAMES[
Array.from(id).reduce((acc, char) => acc + char.charCodeAt(0), 0) % PRODUCT_NAMES.length
],
last_edited: generatePredictableDate(id),
dataset_name: `Dataset ${id}`,
dataset_uuid: generatePredictableUUID(id, 'dataset'),
created_by_id: generatePredictableUUID(id, 'user'),
created_by_name: `User ${id}`,
created_by_email: generatePredictableEmail(id),
created_by_avatar: `https://avatar.example.com/${id}`,
status: VerificationStatus.VERIFIED,
is_shared: true
});

View File

@ -1,11 +1,29 @@
import type { DataMetadata, BusterMetricData } from '@/api/asset_interfaces/metric';
import { faker } from '@faker-js/faker';
const mockData = (): Record<string, string | number | null>[] => {
return Array.from({ length: faker.number.int({ min: 2, max: 100 }) }, (x, index) => ({
sales: index + 1,
date: faker.date.past({ years: index + 1 }).toISOString(),
product: faker.commerce.productName()
const PRODUCTS = [
'Laptop',
'Smartphone',
'Tablet',
'Monitor',
'Keyboard',
'Mouse',
'Headphones',
'Printer',
'Camera',
'Speaker'
];
const generateDate = (index: number): string => {
const baseDate = new Date('2024-01-01');
baseDate.setDate(baseDate.getDate() + index);
return baseDate.toISOString();
};
const mockData = (length: number = 10): Record<string, string | number | null>[] => {
return Array.from({ length }, (_, index) => ({
sales: (index + 1) * 100,
date: generateDate(index),
product: PRODUCTS[index % PRODUCTS.length]
}));
};
@ -14,7 +32,7 @@ const dataMetadata: DataMetadata = {
column_metadata: [
{
name: 'sales',
min_value: 0,
min_value: 100,
max_value: 1000,
unique_values: 10,
simple_type: 'number',
@ -30,9 +48,9 @@ const dataMetadata: DataMetadata = {
},
{
name: 'product',
min_value: 'Product A',
max_value: 'Product Z',
unique_values: 26,
min_value: PRODUCTS[0],
max_value: PRODUCTS[PRODUCTS.length - 1],
unique_values: PRODUCTS.length,
simple_type: 'text',
type: 'text'
}
@ -42,7 +60,7 @@ const dataMetadata: DataMetadata = {
const MOCK_DATA: Required<BusterMetricData> = {
data: mockData(),
metricId: faker.string.uuid(),
metricId: 'mock-metric-1',
data_metadata: dataMetadata
};