mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 08:51:12 -05:00
Fix company count calculation
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user