YOUSEFUL / DELPHI / COMPONENTS

TAtlasAnalytics

Static query functions over a TAtlasTable: select and filter, group and aggregate, and export the dataset JSON.

Class Unit Atlas.Analytics · Inherits TObject · Product Atlas Analytics

Description

All members are static class functions; you never create an instance. Reports and dashboards are built on them, and you can call them directly.

Every function reads the current view of the source (after the table's own SetFilter and Sort) and never modifies the source. Select and Aggregate return a new, unowned TAtlasTable with read-only columns that the caller must free.

Filters (TAtlasFilter) are conjunctive: a row must match all of them. Field names match without regard to case. Text and dates compare without case (dates are YYYY-MM-DD, so text order is date order); numbers compare numerically. afContains is a case-insensitive substring test and needs a text column. A missing (empty) value takes part in afEqual and afNotEqual but never passes afLess, afLessEqual, afGreater or afGreaterEqual. Filter values are first normalized for the column kind, so 1 matches true in a boolean column, and a value that does not fit (lots for a number, 1.9.2026 for a date) raises EAtlasDataError.

Measures (TAtlasMeasure): amCount counts every row, including rows with missing values. Sum, minimum, maximum and average skip missing values; the average divides by the number of values actually present. With no dimensions there is always exactly one result row: on empty input the count and sum are 0 and the minimum, maximum and average are missing. Arithmetic uses finite Double values; a sum that overflows raises EAtlasAnalyticsError.

Members

MemberKindWhat it does
FieldIndexmethodReturns the index of the column called Name, compared without regard to case.
SelectmethodReturns the listed columns (all columns, in source order, when Fields is empty) of the rows that match every filter, in view order.
AggregatemethodGroups the rows by the exact text of the dimension columns (so East and east are separate groups), in first-seen order, and returns one row per group: the dimension columns, named as you passed them and with the source kinds, then one ackNumber column per measure named by its caption.
DatasetJSONmethodReturns the current view as the version 1 dataset JSON read by the web example: fields is an array of {"name", "kind"} objects with kinds text, number, boolean and date, and rows is an array of arrays in field order.

Methods

FieldIndex method

class function FieldIndex(Source: TAtlasTable; const Name: string): Integer; static;

Returns the index of the column called Name, compared without regard to case. Raises EAtlasAnalyticsError A source table is required for nil and Unknown field: Name when there is no such column.

pascal
Sales.SetFilter('West', TAtlasAnalytics.FieldIndex(Sales, 'region'));

Select method

class function Select(Source: TAtlasTable; const Fields: array of string; const Filters: array of TAtlasFilter): TAtlasTable; static;

Returns the listed columns (all columns, in source order, when Fields is empty) of the rows that match every filter, in view order. Result columns keep the source names, kinds and widths and are read-only. Raises EAtlasAnalyticsError for a nil source, an unknown field, an out-of-range operator or afContains on a non-text column; raises EAtlasDataError for a filter value that does not fit its column and for a field listed twice.

pascal
Rows := TAtlasAnalytics.Select(Sales, ['Region', 'Revenue'],
  [TAtlasFilter.Create('Revenue', '10000', afGreater)]);

Aggregate method

class function Aggregate(Source: TAtlasTable; const Dimensions: array of string; const Measures: array of TAtlasMeasure): TAtlasTable; static;

Groups the rows by the exact text of the dimension columns (so East and east are separate groups), in first-seen order, and returns one row per group: the dimension columns, named as you passed them and with the source kinds, then one ackNumber column per measure named by its caption. With no dimensions it returns one total row. Values are written in invariant format (12216.6666666667). Raises EAtlasAnalyticsError for a nil source, no measures (At least one measure is required), an unknown field (including an empty field for a measure other than amCount), a numeric measure on a non-numeric column (Numeric measure requires a numeric field) and sum overflow. Raises EAtlasDataError when a caption is empty or two result columns have the same name (compared without case). Filter first with Select if you need both.

pascal
Totals := TAtlasAnalytics.Aggregate(Sales, ['Region'],
  [TAtlasMeasure.Create('Revenue', 'Revenue', amSum)]);

DatasetJSON method

class function DatasetJSON(Source: TAtlasTable): string; static;

Returns the current view as the version 1 dataset JSON read by the web example: fields is an array of {"name", "kind"} objects with kinds text, number, boolean and date, and rows is an array of arrays in field order. Empty cells become null, numbers are JSON numbers (a whole number is written with .0, for example 18000.0), booleans are true or false, and text and dates (YYYY-MM-DD) are strings. Raises EAtlasAnalyticsError for a nil source.

pascal
{"version":1,"fields":[{"name":"Region","kind":"text"},{"name":"Revenue","kind":"number"}],"rows":[["East",18000.0],["West",null]]}

Examples

Totals per region

Revenue and order count per region, printed to the console.

pascal
uses System.SysUtils, Atlas.Data, Atlas.Analytics;

procedure PrintRegionTotals(Sales: TAtlasTable);
var
  Totals: TAtlasTable;
  I: Integer;
begin
  Totals := TAtlasAnalytics.Aggregate(Sales, ['Region'], [
    TAtlasMeasure.Create('Revenue', 'Revenue', amSum),
    TAtlasMeasure.Create('', 'Orders', amCount)]);
  try
    for I := 0 to Totals.RowCount - 1 do
      Writeln(Totals.Cell(0, I), ': ', Totals.Cell(1, I), ' from ', Totals.Cell(2, I), ' orders');
  finally
    Totals.Free;
  end;
end;

Export the dataset JSON

Writes the table in the format the browser dashboard and the ASP.NET example read.

pascal
uses System.SysUtils, System.IOUtils, Atlas.Data, Atlas.Analytics;

procedure ExportDataset(Sales: TAtlasTable; const FileName: string);
begin
  TFile.WriteAllText(FileName, TAtlasAnalytics.DatasetJSON(Sales), TEncoding.UTF8);
end;

TAtlasFilter · TAtlasMeasure · EAtlasAnalyticsError · TAtlasReportDefinition · TAtlasTable

Also in Atlas Analytics

TAtlasReportDefinition · TAtlasDashboard