reporting

ruby
class CreateCustomerRevenueSummaries < ActiveRecord::Migration[7.0]
  def change
    create_view :customer_revenue_summaries, materialized: true, version: 1

    add_index :customer_revenue_summaries,
              :customer_id,

Database Views for Read Models

rails postgres performance
by codesnips 4 tabs
ruby
class DailySignupRollup < ApplicationRecord
  validates :day, presence: true, uniqueness: true
  validates :total, :verified, numericality: { greater_than_or_equal_to: 0 }

  scope :for_range, ->(from, to) do
    where(day: from.to_date..to.to_date).order(:day)

Nightly Signup Rollups in Rails with a Scheduled Job and Upsert

rails postgres background-jobs
by codesnips 3 tabs
ruby
class ReportsController < ApplicationController
  def monthly_sales
    year = params.fetch(:year, Date.current.year).to_i
    rows = Order.monthly_sales(year: year)
    @report = MonthlySalesReport.new(rows, year: year)

Aggregate Monthly Sales Reports in Rails with group_by SQL and a Presenter

rails postgres reporting
by codesnips 3 tabs
java
import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

import Transaction.Category;

Grouping and Summarizing Transactions with Java Stream Collectors

java streams collectors
by codesnips 3 tabs
rust
use once_cell::sync::Lazy;
use regex::Regex;
use std::str::FromStr;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Severity {

Grouping Log Lines by Severity and Emitting a Summary Report in Rust

logging parsing cli
by codesnips 3 tabs
rust
use crate::paginator::Paginator;

#[derive(Clone)]
pub struct Row {
    pub cells: Vec<String>,
}

Streaming Paginated PDF Report Sections From a Domain Model in Rust

rust pdf pagination
by codesnips 3 tabs