Add detailed debug logging in getProductPricesInCities method of FalukantService

- Introduced console logs to trace the execution flow and key variables in the getProductPricesInCities method, enhancing visibility into product price calculations.
- Logged parameters such as productId, currentPrice, and currentRegionId at the start of the method.
- Added logs for the number of cities and town worth entries found, as well as details when skipping the current city and adding results, improving traceability during price evaluations.
- This update aims to facilitate debugging and performance monitoring by providing comprehensive insights into the pricing logic.
This commit is contained in:
Torsten Schulz (local)
2025-12-03 13:39:09 +01:00
parent 87c720c3fe
commit 3f56939421

View File

@@ -3671,6 +3671,7 @@ class FalukantService extends BaseService {
} }
async getProductPricesInCities(hashedUserId, productId, currentPrice, currentRegionId = null) { async getProductPricesInCities(hashedUserId, productId, currentPrice, currentRegionId = null) {
console.log(`[getProductPricesInCities] Called: productId=${productId}, currentPrice=${currentPrice}, currentRegionId=${currentRegionId}`);
const user = await this.getFalukantUserByHashedId(hashedUserId); const user = await this.getFalukantUserByHashedId(hashedUserId);
const character = await FalukantCharacter.findOne({ where: { userId: user.id } }); const character = await FalukantCharacter.findOne({ where: { userId: user.id } });
if (!character) { if (!character) {
@@ -3688,6 +3689,7 @@ class FalukantService extends BaseService {
where: { characterId: character.id, productId: productId } where: { characterId: character.id, productId: productId }
}); });
const knowledgeFactor = knowledge?.knowledge || 0; const knowledgeFactor = knowledge?.knowledge || 0;
console.log(`[getProductPricesInCities] product.sellCost=${product.sellCost}, knowledgeFactor=${knowledgeFactor}`);
// Alle Städte abrufen // Alle Städte abrufen
const cities = await RegionData.findAll({ const cities = await RegionData.findAll({
@@ -3715,6 +3717,7 @@ class FalukantService extends BaseService {
} }
] ]
}); });
console.log(`[getProductPricesInCities] Found ${cities.length} cities`);
// TownProductWorth für alle Städte und dieses Produkt abrufen // TownProductWorth für alle Städte und dieses Produkt abrufen
const townWorths = await TownProductWorth.findAll({ const townWorths = await TownProductWorth.findAll({
@@ -3722,12 +3725,14 @@ class FalukantService extends BaseService {
attributes: ['regionId', 'worthPercent'] attributes: ['regionId', 'worthPercent']
}); });
const worthMap = new Map(townWorths.map(tw => [tw.regionId, tw.worthPercent])); const worthMap = new Map(townWorths.map(tw => [tw.regionId, tw.worthPercent]));
console.log(`[getProductPricesInCities] Found ${townWorths.length} townWorths entries`);
// 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 = [];
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) {
console.log(`[getProductPricesInCities] Skipping current city: ${city.name} (${city.id})`);
continue; continue;
} }
@@ -3742,6 +3747,8 @@ class FalukantService extends BaseService {
const max = basePrice; const max = basePrice;
const priceInCity = min + (max - min) * (knowledgeFactor / 100); const priceInCity = min + (max - min) * (knowledgeFactor / 100);
console.log(`[getProductPricesInCities] 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 +3764,7 @@ class FalukantService extends BaseService {
} }
} }
console.log(`[getProductPricesInCities] 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,
@@ -3766,6 +3774,7 @@ class FalukantService extends BaseService {
} }
} }
console.log(`[getProductPricesInCities] Returning ${results.length} cities with better prices`);
// 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);