Add debug logging for carrot product pricing in FalukantService

- Introduced console logs to trace the price calculation process specifically for the carrot product (productId: 3).
- Enhanced visibility into the evaluation of cities and the resulting prices, aiding in debugging and performance monitoring.
- Logged details when skipping the current city, calculating prices, and adding cities to the results, improving traceability of pricing logic.
This commit is contained in:
Torsten Schulz (local)
2025-12-03 08:44:45 +01:00
parent 4eeb5021ee
commit 5d01b24c2d

View File

@@ -3725,9 +3725,16 @@ class FalukantService extends BaseService {
// Für jede Stadt den Preis berechnen und Branch-Typ bestimmen // Für jede Stadt den Preis berechnen und Branch-Typ bestimmen
const results = []; const results = [];
const isCarrot = productId === 3; // Debug für Karotten
if (isCarrot) {
console.log(`[getProductPricesInCities CARROT] productId: ${productId}, currentPrice: ${currentPrice}, currentRegionId: ${currentRegionId}, knowledgeFactor: ${knowledgeFactor}, product.sellCost: ${product.sellCost}, cities: ${cities.length}`);
}
for (const city of cities) { for (const city of cities) {
// Aktuelle Stadt ausschließen // Aktuelle Stadt ausschließen
if (currentRegionId && city.id === currentRegionId) { if (currentRegionId && city.id === currentRegionId) {
if (isCarrot) {
console.log(`[getProductPricesInCities CARROT] Skipping current city: ${city.name} (${city.id})`);
}
continue; continue;
} }
@@ -3742,6 +3749,10 @@ class FalukantService extends BaseService {
const max = basePrice; const max = basePrice;
const priceInCity = min + (max - min) * (knowledgeFactor / 100); const priceInCity = min + (max - min) * (knowledgeFactor / 100);
if (isCarrot) {
console.log(`[getProductPricesInCities CARROT] City: ${city.name} (${city.id}), worthPercent: ${worthPercent}, basePrice: ${basePrice}, priceInCity: ${priceInCity}, currentPrice: ${currentPrice}, isBetter: ${priceInCity > currentPrice}`);
}
// Nur Städte zurückgeben, wo der Preis höher ist // Nur Städte zurückgeben, wo der Preis höher ist
// Keine Toleranz, da wir die aktuelle Stadt bereits ausschließen // Keine Toleranz, da wir die aktuelle Stadt bereits ausschließen
if (priceInCity > currentPrice) { if (priceInCity > currentPrice) {
@@ -3757,6 +3768,10 @@ class FalukantService extends BaseService {
} }
} }
if (isCarrot) {
console.log(`[getProductPricesInCities CARROT] Adding ${city.name} to results: price=${priceInCity}, branchType=${branchType}`);
}
results.push({ results.push({
regionId: city.id, regionId: city.id,
regionName: city.name, regionName: city.name,
@@ -3765,6 +3780,10 @@ class FalukantService extends BaseService {
}); });
} }
} }
if (isCarrot) {
console.log(`[getProductPricesInCities CARROT] Returning ${results.length} cities with better prices:`, results.map(r => `${r.regionName} (${r.price})`).join(', '));
}
// Sortiere nach Preis (höchster zuerst) // Sortiere nach Preis (höchster zuerst)
results.sort((a, b) => b.price - a.price); results.sort((a, b) => b.price - a.price);