| Actor | Fragment | Worker | State |
|---|---|---|---|
| 166532 | 20046 | 33 | running |
| 166533 | 20046 | 33 | running |
| 166534 | 20043 | 33 | running |
| 166535 | 20043 | 33 | running |
| 166536 | 20042 | 33 | running |
| 166537 | 20042 | 33 | running |
| 166538 | 20044 | 33 | running |
| 166539 | 20044 | 33 | running |
| 166540 | 20045 | 33 | running |
| 166541 | 20045 | 33 | running |
| 166542 | 20049 | 33 | running |
| 166543 | 20049 | 33 | running |
CREATE MATERIALIZED VIEW opportunity.signal_account_balance_decrease_mv AS
WITH signal_metrics AS (
SELECT
account_id,
dim_balance_date,
'GET_INVESTMENT_ACCOUNT_BALANCE_PERCENT_DECREASE_1D' AS activity_name,
CASE
WHEN market_value <> 0
THEN (
prev_market_value - market_value
) / market_value
ELSE 1
END AS metric
FROM opportunity.account_balance_delta_mv AS account_balance_delta_mv_next
WHERE
market_value < prev_market_value
UNION ALL
SELECT
account_id,
dim_balance_date,
'GET_INVESTMENT_ACCOUNT_BALANCE_ABSOLUTE_DECREASE_1D' AS activity_name,
prev_market_value - market_value AS metric
FROM opportunity.account_balance_delta_mv AS account_balance_delta_mv_next
WHERE
market_value < prev_market_value
)
SELECT
c.opportunity_id,
c.activity_name,
s.account_id AS resource_id,
s.dim_balance_date AS fact_date
FROM signal_metrics AS s
JOIN opportunity.opportunity_conditions_mv AS c
ON c.activity_name = s.activity_name
WHERE
CASE c.op
WHEN 'GTE'
THEN s.metric >= c.threshold
WHEN 'GT'
THEN s.metric > c.threshold
WHEN 'LTE'
THEN s.metric <= c.threshold
WHEN 'LT'
THEN s.metric < c.threshold
WHEN 'EQ'
THEN s.metric = c.threshold
ELSE FALSE
END