Fix company count calculation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 17:52:50 +00:00
parent 7b2e890165
commit b256b6f9ab

View File

@@ -358,14 +358,27 @@ Deno.serve(async (req) => {
console.info('Plan calls for companies:', plan.companies);
const companyTypes = ['manufacturer', 'operator', 'designer', 'property_owner'];
for (const compType of companyTypes) {
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}`);
// 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);
// 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);
@@ -417,7 +430,7 @@ Deno.serve(async (req) => {
createdCompanies[compType].push(companySlug);
summary.companies++;
}
companiesCreatedTotal++;
}
}