From a8acad42297de6e16ee16aecbc937da506ec5b6a Mon Sep 17 00:00:00 2001 From: Alexander Thor Date: Tue, 12 Aug 2025 00:05:20 +0200 Subject: [PATCH] adding annotations --- .../metrics/auction_metrics.yaml | 5 ++ .../models/annotations_auction.sql | 86 +++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 rill-openrtb-prog-ads/models/annotations_auction.sql diff --git a/rill-openrtb-prog-ads/metrics/auction_metrics.yaml b/rill-openrtb-prog-ads/metrics/auction_metrics.yaml index 02b3ac1..ab70975 100644 --- a/rill-openrtb-prog-ads/metrics/auction_metrics.yaml +++ b/rill-openrtb-prog-ads/metrics/auction_metrics.yaml @@ -8,6 +8,11 @@ type: metrics_view timeseries: "__time" smallest_time_grain: "hour" +annotations: + - model: annotations_auction + name: auction_annotations + measures: ['requests'] + measures: - display_name: Total Requests name: requests diff --git a/rill-openrtb-prog-ads/models/annotations_auction.sql b/rill-openrtb-prog-ads/models/annotations_auction.sql new file mode 100644 index 0000000..f3b9dc0 --- /dev/null +++ b/rill-openrtb-prog-ads/models/annotations_auction.sql @@ -0,0 +1,86 @@ +-- Model SQL +-- Reference documentation: https://docs.rilldata.com/reference/project-files/models +-- @materialize: true + +WITH min_max AS ( + SELECT + MIN(__time) AS min_time, + MAX(__time) AS max_time, + (MAX(__time) - MIN(__time)) AS total_span + FROM auction_data_model +), +sequence AS ( + SELECT + min_time + ((total_span * i::DOUBLE) / 49) + ((random() - 0.5) * total_span * 0.02) AS time, + i + FROM min_max, range(50) t(i) +), +descriptions AS ( + SELECT description + FROM UNNEST([ + 'Programmatic auction started', + 'Bid request sent to DSP', + 'Ad impression logged', + 'Auction timeout occurred', + 'Floor price applied', + 'Bid won by DSP A', + 'Creative served successfully', + 'Ad rendered on device', + 'Invalid traffic detected', + 'Ad click tracked', + 'Viewability threshold met', + 'Brand safety check passed', + 'Geo-targeting matched', + 'Device type classified', + 'Ad not rendered due to timeout', + 'Second price auction applied', + 'Ad slot refreshed', + 'Campaign budget depleted', + 'Frequency cap reached', + 'DSP throttled bid rate', + 'Publisher added new inventory', + 'SSP filtering low-value bids', + 'Demand spike observed', + 'Creative rejected by scanner', + 'Bid caching mechanism used', + 'No eligible bids', + 'Programmatic deal triggered', + 'PMP deal preference applied', + 'Dynamic price floor used', + 'Contextual signal evaluated', + 'Latency spike during bidding', + 'Outstream video ad served', + 'Ad slot collapsed', + 'Native ad rendered', + 'OpenRTB 2.5 used', + 'Header bidding enabled', + 'Ad verification passed', + 'Campaign pacing adjusted', + 'Click-through rate spike', + 'Device ID match successful', + 'Cross-device attribution fired', + 'Lookalike segment matched', + 'Audience extension applied', + 'Server-side auction triggered', + 'Bid shading applied', + 'DSP bidding aggressively', + 'Ad failed brand check', + 'Ad muted by user', + 'Impression fraud prevented', + 'Auction closed' + ]) AS t(description) +), +annotations AS ( + SELECT + s.time, + d.description + FROM sequence s + JOIN ( + SELECT description, ROW_NUMBER() OVER () - 1 AS rn FROM descriptions + ) d ON d.rn = s.i +) +SELECT + *, + --'day' as duration -- Allows you to floor a annotation to a specified duration +FROM annotations +ORDER BY time \ No newline at end of file