| Actor | Fragment | Worker | State |
|---|---|---|---|
| 166568 | 20050 | 33 | running |
| 166569 | 20050 | 33 | running |
| 166570 | 20051 | 33 | running |
| 166571 | 20051 | 33 | running |
| 166572 | 20054 | 33 | running |
| 166573 | 20054 | 33 | running |
| 166574 | 20057 | 33 | running |
| 166575 | 20057 | 33 | running |
| 166576 | 20056 | 33 | running |
| 166577 | 20056 | 33 | running |
| 166578 | 20058 | 33 | running |
| 166579 | 20058 | 33 | running |
CREATE MATERIALIZED VIEW opportunity.signal_account_balance_increase_mv AS
WITH signal_metrics AS (
SELECT
account_id,
dim_balance_date,
'GET_INVESTMENT_ACCOUNT_BALANCE_PERCENT_INCREASE_1D' AS activity_name,
(
market_value - prev_market_value
) / prev_market_value 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_INCREASE_1D' AS activity_name,
market_value - prev_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