mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
Fix company count calculation
This commit is contained in:
@@ -358,66 +358,79 @@ Deno.serve(async (req) => {
|
||||
console.info('Plan calls for companies:', plan.companies);
|
||||
|
||||
const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner'];
|
||||
for (const compType of companyTypes) {
|
||||
|
||||
// First, determine which company types are selected
|
||||
const selectedCompanyTypes = companyTypes.filter(compType =>
|
||||
entityTypes.includes(pluralizeCompanyType(compType))
|
||||
);
|
||||
|
||||
console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, selectedCompanyTypes);
|
||||
|
||||
let companiesCreatedTotal = 0;
|
||||
|
||||
for (let typeIndex = 0; typeIndex < selectedCompanyTypes.length; typeIndex++) {
|
||||
const compType = selectedCompanyTypes[typeIndex];
|
||||
const pluralType = pluralizeCompanyType(compType);
|
||||
const shouldGenerate = entityTypes.includes(pluralType);
|
||||
console.info(`Checking ${compType} → ${pluralType}: ${shouldGenerate}`);
|
||||
|
||||
if (shouldGenerate) {
|
||||
const count = Math.floor(plan.companies / 4);
|
||||
console.info(`✓ Generating ${count} companies of type ${compType}`);
|
||||
for (let i = 0; i < count; i++) {
|
||||
console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);
|
||||
const level = getPopulationLevel(fieldDensity, i);
|
||||
const companyData: any = {
|
||||
name: `Test ${compType.replace('_', ' ')} ${i + 1}`,
|
||||
slug: `test-${compType}-${i + 1}`,
|
||||
company_type: compType
|
||||
};
|
||||
// Calculate fair distribution: remaining companies / remaining types
|
||||
const remainingCompanies = plan.companies - companiesCreatedTotal;
|
||||
const remainingTypes = selectedCompanyTypes.length - typeIndex;
|
||||
const count = Math.ceil(remainingCompanies / remainingTypes);
|
||||
|
||||
console.info(`✓ Generating ${count} companies of type ${compType} (${remainingCompanies} remaining, ${remainingTypes} types left)`);
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);
|
||||
const level = getPopulationLevel(fieldDensity, i);
|
||||
const companyData: any = {
|
||||
name: `Test ${compType.replace('_', ' ')} ${i + 1}`,
|
||||
slug: `test-${compType}-${i + 1}`,
|
||||
company_type: compType
|
||||
};
|
||||
|
||||
if (level >= 1) {
|
||||
companyData.description = `Leading ${compType.replace('_', ' ')} in the amusement industry.`;
|
||||
companyData.person_type = compType === 'designer' && Math.random() > 0.5 ? 'individual' : 'company';
|
||||
}
|
||||
|
||||
if (level >= 2) {
|
||||
companyData.founded_year = randomInt(1950, 2020);
|
||||
const location = randomItem(CITIES);
|
||||
companyData.headquarters_location = `${location.city}, ${location.country}`;
|
||||
}
|
||||
|
||||
if (level >= 3) {
|
||||
companyData.website_url = `https://test-${compType}-${i + 1}.example.com`;
|
||||
companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`;
|
||||
}
|
||||
|
||||
if (level >= 4) {
|
||||
companyData.card_image_id = `test-${compType}-card-${i + 1}`;
|
||||
companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`;
|
||||
companyData.banner_image_id = `test-${compType}-banner-${i + 1}`;
|
||||
companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`;
|
||||
}
|
||||
|
||||
const { itemId } = await createSubmission(user.id, compType, companyData);
|
||||
|
||||
// Track created submission item
|
||||
createdSubmissionItems[compType].push(itemId);
|
||||
|
||||
// Register newly created company in the registry
|
||||
const companySlug = `test-${compType}-${i + 1}`;
|
||||
const { data: approvedCompany } = await supabase
|
||||
.from('companies')
|
||||
.select('id')
|
||||
.eq('slug', companySlug)
|
||||
.maybeSingle();
|
||||
|
||||
if (approvedCompany) {
|
||||
await registerTestEntity(supabase, compType, companySlug, approvedCompany.id, itemId, sessionId);
|
||||
}
|
||||
|
||||
createdCompanies[compType].push(companySlug);
|
||||
summary.companies++;
|
||||
if (level >= 1) {
|
||||
companyData.description = `Leading ${compType.replace('_', ' ')} in the amusement industry.`;
|
||||
companyData.person_type = compType === 'designer' && Math.random() > 0.5 ? 'individual' : 'company';
|
||||
}
|
||||
|
||||
if (level >= 2) {
|
||||
companyData.founded_year = randomInt(1950, 2020);
|
||||
const location = randomItem(CITIES);
|
||||
companyData.headquarters_location = `${location.city}, ${location.country}`;
|
||||
}
|
||||
|
||||
if (level >= 3) {
|
||||
companyData.website_url = `https://test-${compType}-${i + 1}.example.com`;
|
||||
companyData.logo_url = `https://imagedelivery.net/test/${compType}-${i + 1}/logo`;
|
||||
}
|
||||
|
||||
if (level >= 4) {
|
||||
companyData.card_image_id = `test-${compType}-card-${i + 1}`;
|
||||
companyData.card_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/card`;
|
||||
companyData.banner_image_id = `test-${compType}-banner-${i + 1}`;
|
||||
companyData.banner_image_url = `https://imagedelivery.net/test/${compType}-${i + 1}/banner`;
|
||||
}
|
||||
|
||||
const { itemId } = await createSubmission(user.id, compType, companyData);
|
||||
|
||||
// Track created submission item
|
||||
createdSubmissionItems[compType].push(itemId);
|
||||
|
||||
// Register newly created company in the registry
|
||||
const companySlug = `test-${compType}-${i + 1}`;
|
||||
const { data: approvedCompany } = await supabase
|
||||
.from('companies')
|
||||
.select('id')
|
||||
.eq('slug', companySlug)
|
||||
.maybeSingle();
|
||||
|
||||
if (approvedCompany) {
|
||||
await registerTestEntity(supabase, compType, companySlug, approvedCompany.id, itemId, sessionId);
|
||||
}
|
||||
|
||||
createdCompanies[compType].push(companySlug);
|
||||
summary.companies++;
|
||||
companiesCreatedTotal++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user