Query editor
WITH latest AS (SELECT MAX(run_id) AS rid FROM dune.w3io.dealsync_email_processing),raw AS (SELECTdate AS block_date,daily_emails AS raw_points,active_users,CAST(AVG(CAST(daily_emails AS DOUBLE)) OVER (ORDER BY date ROWS BETWEEN 7 PRECEDING AND 1 PRECEDING) AS BIGINT) AS trailing_avgFROM dune.w3io.dealsync_email_processing tJOIN latest l ON t.run_id = l.rid),smoothed AS (SELECTblock_date,CASEWHEN trailing_avg > 0 AND raw_points > trailing_avg * 2THEN trailing_avg * 2ELSE raw_pointsEND AS ai_data_points,active_usersFROM raw)SELECTblock_date,ai_data_points,SUM(ai_data_points) OVER (ORDER BY block_date) AS cumulative_ai_data_points,active_users,CAST(AVG(CAST(ai_data_points AS DOUBLE)) OVER (ORDER BY block_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS BIGINT) AS ma_7dayFROM smoothedORDER BY block_date