Add new calculate scripts, add in historical data import

This commit is contained in:
2025-03-30 10:30:13 -04:00
parent 4c4359908c
commit 047122a620
9 changed files with 1990 additions and 28 deletions

View File

@@ -5,7 +5,7 @@
DO $$
DECLARE
_module_name VARCHAR := 'periodic_metrics';
_module_name TEXT := 'periodic_metrics';
_start_time TIMESTAMPTZ := clock_timestamp();
_last_calc_time TIMESTAMPTZ;
_abc_basis VARCHAR;
@@ -25,7 +25,7 @@ BEGIN
WITH LeadTimes AS (
SELECT
pid,
AVG(GREATEST(1, DATE_PART('day', last_received_date - date))) AS avg_days -- Use GREATEST(1,...) to avoid 0 or negative days
AVG(GREATEST(1, (last_received_date::date - date::date))) AS avg_days -- Use GREATEST(1,...) to avoid 0 or negative days
FROM public.purchase_orders
WHERE status = 'received' -- Or potentially 'full_received' if using that status
AND last_received_date IS NOT NULL