Update environment configuration and enhance logging: Add support for loading a local .env file and improve logging behavior based on QUIET_ENV_LOGS settings. Introduce new diagnostic scripts in package.json for town worth and money flow analysis. Adjust production cost calculations in FalukantService to align with updated pricing logic and enhance product initialization parameters.
This commit is contained in:
38
backend/sql/balance_carrot_product.sql
Normal file
38
backend/sql/balance_carrot_product.sql
Normal file
@@ -0,0 +1,38 @@
|
||||
-- Karotte: Debug-Tempo und Preis an gleiche Basis wie andere Kat.-1-Waren (siehe initializeFalukantPredefines.js).
|
||||
-- Sicher für alle Installationen: nur production_time ohne optionale Spalten.
|
||||
|
||||
BEGIN;
|
||||
|
||||
UPDATE falukant_type.product
|
||||
SET production_time = 2
|
||||
WHERE label_tr = 'carrot';
|
||||
|
||||
COMMIT;
|
||||
|
||||
-- Optional (wenn Migration mit original_sell_cost läuft): in derselben Session ausführen
|
||||
/*
|
||||
UPDATE falukant_type.product
|
||||
SET original_sell_cost = 6
|
||||
WHERE label_tr = 'carrot';
|
||||
|
||||
WITH RECURSIVE ancestors AS (
|
||||
SELECT id AS start_id, id, parent_id, tax_percent FROM falukant_data.region
|
||||
UNION ALL
|
||||
SELECT a.start_id, r.id, r.parent_id, r.tax_percent
|
||||
FROM falukant_data.region r
|
||||
JOIN ancestors a ON r.id = a.parent_id
|
||||
), totals AS (
|
||||
SELECT start_id, COALESCE(SUM(tax_percent), 0) AS total FROM ancestors GROUP BY start_id
|
||||
), mm AS (
|
||||
SELECT COALESCE(MAX(total), 0) AS max_total FROM totals
|
||||
)
|
||||
UPDATE falukant_type.product p
|
||||
SET sell_cost = CEIL(p.original_sell_cost * (
|
||||
CASE WHEN (1 - mm.max_total / 100) <= 0 THEN 1 ELSE (1 / (1 - mm.max_total / 100)) END
|
||||
))
|
||||
FROM mm
|
||||
WHERE p.label_tr = 'carrot' AND p.original_sell_cost IS NOT NULL;
|
||||
*/
|
||||
|
||||
-- Ohne original_sell_cost: grob sell_cost = 6 (wie Milch/Brot; ggf. anpassen)
|
||||
-- UPDATE falukant_type.product SET sell_cost = 6 WHERE label_tr = 'carrot';
|
||||
31
backend/sql/diagnostics/falukant_moneyflow_by_activity.sql
Normal file
31
backend/sql/diagnostics/falukant_moneyflow_by_activity.sql
Normal file
@@ -0,0 +1,31 @@
|
||||
-- Falukant: Geldbewegungen aus falukant_log.moneyflow (jede Zeile = ein Aufruf von
|
||||
-- falukant_data.update_money → activity-String wie im Backend übergeben).
|
||||
--
|
||||
-- Typische activity-Werte (siehe falukantService.js → updateFalukantUserMoney):
|
||||
-- Wirtschaft: Production cost; Product sale (net); Sell all products (net);
|
||||
-- Steueranteil Region (Verkauf); Sales tax (…); Buy/Sell storage (type: …)
|
||||
-- Transport/Fahrzeuge: transport; build_vehicles; buy_vehicles; repair_vehicle; repair_all_vehicles
|
||||
-- Filiale: create_branch
|
||||
-- Haus: housebuy; servants_hired; household_order; renovation_*; renovation_all
|
||||
-- Soziales: marriage_gift; Marriage cost; Gift cost; partyOrder; Baptism; Reputation action: …
|
||||
-- Bildung: learnAll; learnItem:<productId>
|
||||
-- Sonst: new nobility title; health.<aktivität>; credit taken (Kredit = positiver change_value)
|
||||
--
|
||||
-- Platzhalter (ersetzt durch scripts/falukant-moneyflow-report.mjs):
|
||||
-- __DIAG_DAYS__ → positive Ganzzahl (Tage zurück)
|
||||
-- __DIAG_USER_FILTER__ → leer ODER " AND m.falukant_user_id = <id>"
|
||||
--
|
||||
-- Manuell in psql: __DIAG_DAYS__ durch z. B. 30 ersetzen, __DIAG_USER_FILTER__ leer lassen.
|
||||
|
||||
SELECT
|
||||
m.activity,
|
||||
COUNT(*)::bigint AS n,
|
||||
ROUND(SUM(m.change_value)::numeric, 2) AS sum_change,
|
||||
ROUND(SUM(CASE WHEN m.change_value < 0 THEN -m.change_value ELSE 0 END)::numeric, 2) AS total_outflow,
|
||||
ROUND(SUM(CASE WHEN m.change_value > 0 THEN m.change_value ELSE 0 END)::numeric, 2) AS total_inflow,
|
||||
ROUND(AVG(m.change_value)::numeric, 4) AS avg_change
|
||||
FROM falukant_log.moneyflow m
|
||||
WHERE m."time" >= NOW() - (INTERVAL '1 day' * __DIAG_DAYS__)
|
||||
__DIAG_USER_FILTER__
|
||||
GROUP BY m.activity
|
||||
ORDER BY sum_change ASC NULLS LAST;
|
||||
14
backend/sql/diagnostics/falukant_moneyflow_window_totals.sql
Normal file
14
backend/sql/diagnostics/falukant_moneyflow_window_totals.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Kurzüberblick: Zeilen, Nutzer, Summen Ein-/Ausgang im gleichen Fenster wie
|
||||
-- falukant_moneyflow_by_activity.sql (Platzhalter identisch).
|
||||
|
||||
SELECT
|
||||
COUNT(*)::bigint AS row_count,
|
||||
COUNT(DISTINCT m.falukant_user_id)::bigint AS distinct_falukant_users,
|
||||
ROUND(SUM(m.change_value)::numeric, 2) AS net_sum_all,
|
||||
ROUND(SUM(CASE WHEN m.change_value < 0 THEN m.change_value ELSE 0 END)::numeric, 2) AS sum_negative_only,
|
||||
ROUND(SUM(CASE WHEN m.change_value > 0 THEN m.change_value ELSE 0 END)::numeric, 2) AS sum_positive_only,
|
||||
MIN(m."time") AS first_ts,
|
||||
MAX(m."time") AS last_ts
|
||||
FROM falukant_log.moneyflow m
|
||||
WHERE m."time" >= NOW() - (INTERVAL '1 day' * __DIAG_DAYS__)
|
||||
__DIAG_USER_FILTER__;
|
||||
@@ -0,0 +1,16 @@
|
||||
-- Übersicht: regionaler Warenwert je Produkt (Nachfrage / „worth“).
|
||||
-- Niedrige Mittelwerte erklären schwache Verkaufspreise; siehe auch falukant_data.town_product_worth Hooks im Backend-Model.
|
||||
|
||||
SELECT
|
||||
p.id,
|
||||
p.label_tr,
|
||||
p.category,
|
||||
p.sell_cost::numeric AS sell_cost,
|
||||
ROUND(AVG(tpw.worth_percent)::numeric, 2) AS avg_worth_pct,
|
||||
ROUND(MIN(tpw.worth_percent)::numeric, 2) AS min_worth_pct,
|
||||
ROUND(MAX(tpw.worth_percent)::numeric, 2) AS max_worth_pct,
|
||||
COUNT(tpw.region_id) AS region_rows
|
||||
FROM falukant_type.product p
|
||||
LEFT JOIN falukant_data.town_product_worth tpw ON tpw.product_id = p.id
|
||||
GROUP BY p.id, p.label_tr, p.category, p.sell_cost
|
||||
ORDER BY p.category, p.label_tr;
|
||||
Reference in New Issue
Block a user