Fix company type distribution logic

This commit is contained in:
gpt-engineer-app[bot]
2025-10-10 18:15:56 +00:00
parent 0aee7673ec
commit 7a1607f149

View File

@@ -376,18 +376,22 @@ Deno.serve(async (req) => {
console.info(`✓ Selected company types (${selectedCompanyTypes.length}):`, selectedCompanyTypes);
// Calculate fair distribution: base amount per type + extras
const basePerType = Math.floor(plan.companies / selectedCompanyTypes.length);
const extras = plan.companies % selectedCompanyTypes.length;
console.info(`Distribution plan: ${basePerType} base per type, ${extras} extra(s) to first types`);
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);
// Each type gets base amount, first N types get +1 extra
const count = basePerType + (typeIndex < extras ? 1 : 0);
console.info(`✓ Generating ${count} companies of type ${compType} (${remainingCompanies} remaining, ${remainingTypes} types left)`);
console.info(`✓ Generating ${count} companies of type ${compType}`);
for (let i = 0; i < count; i++) {
console.info(` Creating company ${i + 1}/${count} (type: ${compType})`);