mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 06:31:13 -05:00
feat: Implement test data generation plan
This commit is contained in:
@@ -72,6 +72,112 @@ function getPopulationLevel(fieldDensity: string, index: number): number {
|
||||
return 2;
|
||||
}
|
||||
|
||||
function randomFloat(min: number, max: number, decimals = 2): number {
|
||||
const value = Math.random() * (max - min) + min;
|
||||
return parseFloat(value.toFixed(decimals));
|
||||
}
|
||||
|
||||
function randomDatePrecision(): 'day' | 'month' | 'year' {
|
||||
return randomItem(['day', 'month', 'year']);
|
||||
}
|
||||
|
||||
function shouldPopulateField(
|
||||
fieldDensity: string,
|
||||
index: number,
|
||||
fieldImportance: 'low' | 'medium' | 'high'
|
||||
): boolean {
|
||||
const level = getPopulationLevel(fieldDensity, index);
|
||||
|
||||
if (fieldImportance === 'high') return level >= 1;
|
||||
if (fieldImportance === 'medium') return level >= 2;
|
||||
if (fieldImportance === 'low') return level >= 3;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Category-specific field generators
|
||||
function generateWaterRideFields(fieldDensity: string, index: number) {
|
||||
if (!shouldPopulateField(fieldDensity, index, 'medium')) return {};
|
||||
|
||||
return {
|
||||
water_depth_cm: randomInt(30, 300),
|
||||
splash_height_meters: randomFloat(1, 20, 1),
|
||||
wetness_level: randomItem(['dry', 'light', 'moderate', 'soaked']),
|
||||
flume_type: randomItem(['log', 'tube', 'raft', 'boat']),
|
||||
boat_capacity: randomInt(2, 20)
|
||||
};
|
||||
}
|
||||
|
||||
function generateDarkRideFields(fieldDensity: string, index: number) {
|
||||
if (!shouldPopulateField(fieldDensity, index, 'medium')) return {};
|
||||
|
||||
return {
|
||||
theme_name: randomItem(['Space Adventure', 'Haunted Mansion', 'Underwater Journey', 'Fantasy Quest']),
|
||||
story_description: 'An immersive journey through a themed environment with exciting scenes.',
|
||||
show_duration_seconds: randomInt(180, 600),
|
||||
animatronics_count: randomInt(5, 50),
|
||||
projection_type: randomItem(['2d', '3d', 'holographic', 'mixed']),
|
||||
ride_system: randomItem(['omnimover', 'tracked', 'trackless', 'boat']),
|
||||
scenes_count: randomInt(5, 20)
|
||||
};
|
||||
}
|
||||
|
||||
function generateFlatRideFields(fieldDensity: string, index: number) {
|
||||
if (!shouldPopulateField(fieldDensity, index, 'medium')) return {};
|
||||
|
||||
return {
|
||||
rotation_type: randomItem(['horizontal', 'vertical', 'both', 'none']),
|
||||
motion_pattern: randomItem(['circular', 'pendulum', 'spinning', 'wave', 'random']),
|
||||
platform_count: randomInt(1, 8),
|
||||
swing_angle_degrees: randomInt(45, 180),
|
||||
rotation_speed_rpm: randomInt(5, 30),
|
||||
arm_length_meters: randomFloat(5, 25, 1),
|
||||
max_height_reached_meters: randomFloat(10, 80, 1)
|
||||
};
|
||||
}
|
||||
|
||||
function generateKiddieRideFields(fieldDensity: string, index: number) {
|
||||
if (!shouldPopulateField(fieldDensity, index, 'medium')) return {};
|
||||
|
||||
return {
|
||||
min_age: randomInt(2, 5),
|
||||
max_age: randomInt(8, 12),
|
||||
educational_theme: randomItem(['counting', 'colors', 'animals', 'shapes', 'letters']),
|
||||
character_theme: randomItem(['dinosaurs', 'princesses', 'superheroes', 'animals', 'vehicles'])
|
||||
};
|
||||
}
|
||||
|
||||
function generateTransportationRideFields(fieldDensity: string, index: number) {
|
||||
if (!shouldPopulateField(fieldDensity, index, 'medium')) return {};
|
||||
|
||||
return {
|
||||
transport_type: randomItem(['monorail', 'train', 'skyway', 'gondola', 'ferry']),
|
||||
route_length_meters: randomInt(500, 5000),
|
||||
stations_count: randomInt(2, 8),
|
||||
vehicle_capacity: randomInt(20, 200),
|
||||
vehicles_count: randomInt(2, 12),
|
||||
round_trip_duration_seconds: randomInt(300, 1800)
|
||||
};
|
||||
}
|
||||
|
||||
function generateSubmissionNotes(
|
||||
fieldDensity: string,
|
||||
index: number,
|
||||
entityType: string
|
||||
): string | undefined {
|
||||
if (!shouldPopulateField(fieldDensity, index, 'low')) return undefined;
|
||||
|
||||
const notes = [
|
||||
`Updated ${entityType} information from official source`,
|
||||
`Added comprehensive data for testing purposes`,
|
||||
`Verified information through multiple sources`,
|
||||
`Historical data added for completeness`,
|
||||
`Technical specifications verified with manufacturer`
|
||||
];
|
||||
|
||||
return randomItem(notes);
|
||||
}
|
||||
|
||||
// Registry helper functions for cascading test data
|
||||
async function registerTestEntity(
|
||||
supabase: any,
|
||||
@@ -602,11 +708,28 @@ Deno.serve(async (req) => {
|
||||
companyData.founded_year = randomInt(1950, 2020);
|
||||
const location = randomItem(CITIES);
|
||||
companyData.headquarters_location = `${location.city}, ${location.country}`;
|
||||
|
||||
// Add full founded date with precision
|
||||
companyData.founded_date = `${companyData.founded_year}-01-01`;
|
||||
companyData.founded_date_precision = randomDatePrecision();
|
||||
|
||||
// Add defunct date for some companies (10% chance at level 3+)
|
||||
if (level >= 3 && Math.random() > 0.9) {
|
||||
const defunctYear = randomInt(companyData.founded_year + 10, 2024);
|
||||
companyData.defunct_date = `${defunctYear}-12-31`;
|
||||
companyData.defunct_date_precision = randomDatePrecision();
|
||||
}
|
||||
}
|
||||
|
||||
if (level >= 3) {
|
||||
companyData.website_url = `https://test-${compType}-${i + 1}.example.com`;
|
||||
companyData.logo_url = `https://cdn.thrillwiki.com/images/test-${compType}-${i + 1}-logo/logo`;
|
||||
companyData.source_url = `https://example.com/source/${compType}/${i + 1}`;
|
||||
|
||||
const notes = generateSubmissionNotes(fieldDensity, i, compType);
|
||||
if (notes) {
|
||||
companyData.submission_notes = notes;
|
||||
}
|
||||
}
|
||||
|
||||
if (level >= 4) {
|
||||
@@ -664,6 +787,7 @@ Deno.serve(async (req) => {
|
||||
|
||||
if (level >= 1) {
|
||||
parkData.opening_date = randomDate(1950, 2024);
|
||||
parkData.opening_date_precision = randomDatePrecision();
|
||||
parkData.description = `A ${parkData.park_type === 'theme_park' ? 'themed' : 'exciting'} park for all ages with various attractions.`;
|
||||
}
|
||||
|
||||
@@ -706,8 +830,16 @@ Deno.serve(async (req) => {
|
||||
}
|
||||
if (Math.random() > 0.9) {
|
||||
parkData.closing_date = randomDate(2000, 2024);
|
||||
parkData.closing_date_precision = randomDatePrecision();
|
||||
parkData.status = 'closed';
|
||||
}
|
||||
|
||||
parkData.source_url = `https://example.com/source/park/${i + 1}`;
|
||||
const notes = generateSubmissionNotes(fieldDensity, i, 'park');
|
||||
if (notes) {
|
||||
parkData.submission_notes = notes;
|
||||
}
|
||||
|
||||
parkData.banner_image_id = `test-park-banner-${i + 1}`;
|
||||
parkData.banner_image_url = `https://cdn.thrillwiki.com/images/test-park-banner-${i + 1}/banner`;
|
||||
}
|
||||
@@ -767,7 +899,7 @@ Deno.serve(async (req) => {
|
||||
|
||||
const parkItemId = createdSubmissionItems.park.length > 0 ? randomItem(createdSubmissionItems.park) : undefined;
|
||||
|
||||
const category = randomItem(['roller_coaster', 'flat_ride', 'water_ride', 'dark_ride']);
|
||||
const category = randomItem(['roller_coaster', 'flat_ride', 'water_ride', 'dark_ride', 'kiddie_ride', 'transport_ride', 'family_ride']);
|
||||
const rideData: any = {
|
||||
name: shouldVersionChain ? `Test Ride ${slug} (Updated)` : `Test Ride ${i + 1}`,
|
||||
slug: slug,
|
||||
@@ -778,6 +910,7 @@ Deno.serve(async (req) => {
|
||||
|
||||
if (level >= 1) {
|
||||
rideData.opening_date = randomDate(2000, 2024);
|
||||
rideData.opening_date_precision = randomDatePrecision();
|
||||
rideData.description = `An exciting ${category.replace('_', ' ')} attraction.`;
|
||||
rideData.height_requirement = randomInt(100, 140);
|
||||
}
|
||||
@@ -803,11 +936,31 @@ Deno.serve(async (req) => {
|
||||
rideData.inversions = randomInt(0, 7);
|
||||
rideData.coaster_type = randomItem(['steel', 'wooden', 'hybrid']);
|
||||
rideData.seating_type = randomItem(['sit_down', 'inverted', 'flying', 'stand_up']);
|
||||
|
||||
// Add material arrays for roller coasters
|
||||
if (shouldPopulateField(fieldDensity, i, 'medium')) {
|
||||
rideData.track_material = [randomItem(['steel', 'wood', 'hybrid'])];
|
||||
rideData.support_material = [randomItem(['steel', 'wood', 'concrete'])];
|
||||
rideData.propulsion_method = [randomItem(['chain_lift', 'cable_lift', 'launch', 'gravity', 'tire_drive'])];
|
||||
}
|
||||
}
|
||||
rideData.card_image_id = `test-ride-card-${i + 1}`;
|
||||
rideData.card_image_url = `https://cdn.thrillwiki.com/images/test-ride-card-${i + 1}/card`;
|
||||
}
|
||||
|
||||
// Add category-specific fields based on ride type
|
||||
if (category === 'water_ride') {
|
||||
Object.assign(rideData, generateWaterRideFields(fieldDensity, i));
|
||||
} else if (category === 'dark_ride') {
|
||||
Object.assign(rideData, generateDarkRideFields(fieldDensity, i));
|
||||
} else if (category === 'flat_ride') {
|
||||
Object.assign(rideData, generateFlatRideFields(fieldDensity, i));
|
||||
} else if (category === 'kiddie_ride') {
|
||||
Object.assign(rideData, generateKiddieRideFields(fieldDensity, i));
|
||||
} else if (category === 'transport_ride') {
|
||||
Object.assign(rideData, generateTransportationRideFields(fieldDensity, i));
|
||||
}
|
||||
|
||||
if (level >= 4) {
|
||||
if (createdCompanies.designer.length > 0) {
|
||||
const { data: designerData } = await supabase
|
||||
@@ -820,6 +973,20 @@ Deno.serve(async (req) => {
|
||||
rideData.length_meters = randomInt(500, 2000);
|
||||
rideData.drop_height_meters = randomInt(10, 80);
|
||||
rideData.max_g_force = (Math.random() * 4 + 2).toFixed(1);
|
||||
|
||||
rideData.source_url = `https://example.com/source/ride/${i + 1}`;
|
||||
const notes = generateSubmissionNotes(fieldDensity, i, 'ride');
|
||||
if (notes) {
|
||||
rideData.submission_notes = notes;
|
||||
}
|
||||
|
||||
// Add closing date for some rides
|
||||
if (Math.random() > 0.95) {
|
||||
rideData.closing_date = randomDate(2010, 2024);
|
||||
rideData.closing_date_precision = randomDatePrecision();
|
||||
rideData.status = 'closed';
|
||||
}
|
||||
|
||||
rideData.banner_image_id = `test-ride-banner-${i + 1}`;
|
||||
rideData.banner_image_url = `https://cdn.thrillwiki.com/images/test-ride-banner-${i + 1}/banner`;
|
||||
}
|
||||
@@ -922,6 +1089,12 @@ Deno.serve(async (req) => {
|
||||
if (level >= 2) {
|
||||
modelData.card_image_id = `test-model-card-${i + 1}`;
|
||||
modelData.card_image_url = `https://cdn.thrillwiki.com/images/test-model-card-${i + 1}/card`;
|
||||
modelData.source_url = `https://example.com/source/ride-model/${i + 1}`;
|
||||
|
||||
const notes = generateSubmissionNotes(fieldDensity, i, 'ride model');
|
||||
if (notes) {
|
||||
modelData.submission_notes = notes;
|
||||
}
|
||||
}
|
||||
|
||||
if (level >= 3) {
|
||||
|
||||
Reference in New Issue
Block a user