chore: auto-commit (95 archivos)
- cmd/fn/doctor.go - cmd/fn/main.go - cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt - cpp/apps/primitives_gallery/playground/tables/data_table.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp - cpp/apps/primitives_gallery/playground/tables/data_table_logic.h - cpp/apps/primitives_gallery/playground/tables/self_test.cpp - cpp/apps/primitives_gallery/playground/tables/tql.cpp - cpp/apps/primitives_gallery/playground/tables/viz.cpp - cpp/apps/primitives_gallery/playground/tables/viz.h - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
// data_table_types — types compartidos del stack TQL (Table Query Language).
|
||||
// Promovido al registry desde cpp/apps/primitives_gallery/playground/tables/.
|
||||
// Ver issue 0081 + docs/TQL.md. Pure value types + enums.
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace data_table {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Operadores de filtro.
|
||||
// ----------------------------------------------------------------------------
|
||||
enum class Op {
|
||||
Eq, Neq, Gt, Gte, Lt, Lte,
|
||||
Contains, NotContains, StartsWith, EndsWith
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Tipo de columna. Declarado por caller o auto-detectado.
|
||||
// ----------------------------------------------------------------------------
|
||||
enum class ColumnType {
|
||||
Auto, String, Int, Float, Bool, Date, Json
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Derived column: inmutable. Dos modos:
|
||||
// 1) Retipo puro: source_col >= 0, formula == "". Cells del origen.
|
||||
// 2) Formula: source_col == -1, formula no vacia. Eval por Lua.
|
||||
// ----------------------------------------------------------------------------
|
||||
struct DerivedColumn {
|
||||
int source_col = -1;
|
||||
ColumnType type = ColumnType::String;
|
||||
std::string name;
|
||||
std::string formula; // "" = retipado puro; resto = body Lua
|
||||
int lua_id = -1; // referencia en lua_engine; -1 si no compilado
|
||||
std::string compile_error;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Filtro: col index en eff_headers + op + value.
|
||||
// ----------------------------------------------------------------------------
|
||||
struct Filter {
|
||||
int col;
|
||||
Op op;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ColorRule: pintado condicional de celdas (UI helper).
|
||||
// ----------------------------------------------------------------------------
|
||||
struct ColorRule {
|
||||
int col;
|
||||
std::string equals;
|
||||
unsigned int color;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Aggregations (TQL stages 1+).
|
||||
// ----------------------------------------------------------------------------
|
||||
enum class AggFn {
|
||||
Count, Sum, Avg, Min, Max, Distinct, Stddev,
|
||||
Median, P25, P75, P90, P99, Percentile
|
||||
};
|
||||
|
||||
struct Aggregation {
|
||||
AggFn fn = AggFn::Count;
|
||||
std::string col; // ignorado para Count
|
||||
double arg = 0.0; // para Percentile (0..1)
|
||||
std::string alias; // vacio -> auto-generado via aggregation_alias()
|
||||
};
|
||||
|
||||
struct SortClause {
|
||||
std::string col;
|
||||
bool desc = false;
|
||||
};
|
||||
|
||||
// Stage: layer de TQL. Stage 0 = Raw (sin breakouts/aggregations).
|
||||
// Stage 1+ pueden agrupar. Cada stage consume output del anterior.
|
||||
struct Stage {
|
||||
std::vector<Filter> filters;
|
||||
std::vector<DerivedColumn> derived; // expressions de este stage
|
||||
std::vector<std::string> breakouts; // col names del INPUT de este stage
|
||||
std::vector<Aggregation> aggregations;
|
||||
std::vector<SortClause> sorts;
|
||||
};
|
||||
|
||||
// Output de compute_stage. Posee `cell_backing` (strings nuevos para
|
||||
// resultados agregados) y `cells` (punteros row-major a backing o a
|
||||
// `in_cells` original para passthrough).
|
||||
struct StageOutput {
|
||||
std::vector<std::string> cell_backing;
|
||||
std::vector<const char*> cells;
|
||||
int rows = 0;
|
||||
int cols = 0;
|
||||
std::vector<std::string> headers;
|
||||
std::vector<ColumnType> types;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ViewMode: tipo de visualizacion a renderizar sobre el output del stage activo.
|
||||
// ----------------------------------------------------------------------------
|
||||
enum class ViewMode {
|
||||
Table,
|
||||
// Bars
|
||||
Bar, Column, GroupedBar, StackedBar,
|
||||
// Lines / area
|
||||
Line, Area, Stairs,
|
||||
// Points
|
||||
Scatter, Bubble,
|
||||
// Distribution
|
||||
Histogram, Histogram2D, Heatmap, BoxPlot,
|
||||
// Stems / signals
|
||||
Stem, ErrorBars,
|
||||
// Composition
|
||||
Pie, Donut, Funnel, Waterfall,
|
||||
// Single values
|
||||
KPI, KPIGrid,
|
||||
// Specialized
|
||||
Candlestick, Radar,
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Joins (MBQL-style). Ver issue 0078.
|
||||
// ----------------------------------------------------------------------------
|
||||
enum class JoinStrategy { Left, Inner, Right, Full };
|
||||
|
||||
// Tabla extra pasada al render() para joins. Owner externo (caller).
|
||||
struct TableInput {
|
||||
std::string name; // identificador estable (matchea Join.source)
|
||||
std::vector<std::string> headers;
|
||||
std::vector<ColumnType> types;
|
||||
const char* const* cells = nullptr; // row-major, headers.size() cols x rows filas
|
||||
int rows = 0;
|
||||
int cols = 0;
|
||||
};
|
||||
|
||||
// Join clause: une la tabla actual con `source` por las parejas `on`,
|
||||
// prefijando las cols del derecho con `alias.`.
|
||||
struct Join {
|
||||
std::string alias;
|
||||
std::string source;
|
||||
std::vector<std::pair<std::string, std::string>> on; // {left_col, right_col}
|
||||
JoinStrategy strategy = JoinStrategy::Left;
|
||||
std::vector<std::string> fields; // vacio = all del derecho
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ViewConfig: overrides manuales de auto-detect para la vista activa.
|
||||
// ----------------------------------------------------------------------------
|
||||
struct ViewConfig {
|
||||
std::string x_col; // single: scatter, line, hist2d
|
||||
std::vector<std::string> y_cols; // 1..N: line/area/bar/etc
|
||||
std::string size_col; // bubble
|
||||
std::string cat_col; // bar/pie/funnel/box override
|
||||
unsigned int primary_color = 0; // 0 = ImPlot auto
|
||||
int hist_bins = 0; // 0 = Sturges
|
||||
float pie_radius = 0.0f; // 0 = default
|
||||
bool show_legend = true;
|
||||
bool show_markers = false; // line/area markers
|
||||
bool locked = false; // disable pan/zoom
|
||||
mutable bool fit_request = false; // consumed by viz::render
|
||||
};
|
||||
|
||||
// VizPanel: viz adicional sobre el mismo StageOutput.
|
||||
struct VizPanel {
|
||||
ViewMode display = ViewMode::Bar;
|
||||
ViewConfig config;
|
||||
mutable ViewMode last_non_table = ViewMode::Bar;
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// State: stage pipeline + viz globales.
|
||||
// ----------------------------------------------------------------------------
|
||||
struct State {
|
||||
std::vector<Stage> stages;
|
||||
int active_stage = 0;
|
||||
ViewMode display = ViewMode::Table;
|
||||
ViewConfig viz_config;
|
||||
std::vector<VizPanel> extra_panels;
|
||||
std::vector<Join> joins; // aplicado antes de stages[0]
|
||||
std::string main_source; // name de TableInput; vacio -> tables[0]
|
||||
|
||||
std::vector<ColorRule> color_rules;
|
||||
std::vector<bool> col_visible;
|
||||
std::vector<int> col_order;
|
||||
|
||||
// Helpers (definidos en compute_stage.cpp).
|
||||
Stage& raw();
|
||||
const Stage& raw() const;
|
||||
Stage& active();
|
||||
const Stage& active_const() const;
|
||||
void ensure_stage0();
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Drill extendido (fase 10). Ver issue 0079.
|
||||
// ----------------------------------------------------------------------------
|
||||
enum class DateGranularity { None, Year, Month, Week, Day, Hour };
|
||||
|
||||
enum class FilterPreset { Last7d, Last30d, Last90d, ExcludeNulls, NonZero };
|
||||
|
||||
// Step de drill grabado para history undo/redo (fase 10).
|
||||
struct DrillStep {
|
||||
int target_stage = -1; // stage donde se anadio el filter
|
||||
int filter_pos = -1; // index en target_stage.filters
|
||||
int prev_active_stage = 0; // active_stage antes del drill
|
||||
Filter added; // filter para redo
|
||||
};
|
||||
|
||||
} // namespace data_table
|
||||
Reference in New Issue
Block a user