class ReportQuery
SQL = <<~SQL.freeze
SELECT date_trunc('day', events.created_at) AS day,
count(*) AS total,
count(*) FILTER (WHERE events.kind = 'purchase') AS purchases
FROM events
class CspReportsController < ActionController::API
def create
Rails.logger.warn({
event: 'csp_report',
report: params.to_unsafe_h,
ip: request.remote_ip,
Rails.application.config.content_security_policy do |policy|
policy.default_src :self
policy.font_src :self, :https, :data
policy.img_src :self, :https, :data, "https://cdn.example.com"
policy.object_src :none
policy.script_src :self, :https
import pandas as pd
df = pd.read_parquet('events.parquet')
df['event_date'] = pd.to_datetime(df['event_date'])
df['month'] = df['event_date'].dt.to_period('M').astype(str)
CREATE TABLE daily_events (
id BIGSERIAL PRIMARY KEY,
category TEXT NOT NULL,
item_id BIGINT NOT NULL,
score NUMERIC(10,2) NOT NULL DEFAULT 0,
occurred_at TIMESTAMPTZ NOT NULL DEFAULT now()
class CreateCustomerRevenueSummaries < ActiveRecord::Migration[7.0]
def change
create_view :customer_revenue_summaries, materialized: true, version: 1
add_index :customer_revenue_summaries,
:customer_id,