61d21cc1ff
- app.md - appicon.ico - playground/tables/data_table_logic.h - playground/tables/DEPRECATED.md Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
186 lines
8.5 KiB
C++
186 lines
8.5 KiB
C++
// Logica pura del playground data_table. Sin ImGui — testable headless.
|
|
// TIPOS promovidos al registry (issue 0081). Este header solo declara
|
|
// funciones; los types vienen de cpp/functions/core/data_table_types.h.
|
|
#pragma once
|
|
|
|
#include "core/data_table_types.h"
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace data_table {
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Helpers para Op y ColumnType.
|
|
// ----------------------------------------------------------------------------
|
|
const char* op_label(Op o);
|
|
bool op_is_string_only(Op o);
|
|
|
|
const char* column_type_name(ColumnType t);
|
|
const char* column_type_icon(ColumnType t); // UTF-8 Tabler icon
|
|
|
|
// Ops permitidos para cada tipo. Devuelve vector ordenado.
|
|
std::vector<Op> ops_for_type(ColumnType t);
|
|
|
|
// Auto-detect via sample: escanea hasta `sample_n` celdas no-vacias.
|
|
ColumnType auto_detect_type(const char* const* cells, int rows, int cols,
|
|
int col, int sample_n = 64);
|
|
|
|
// Tipo efectivo: si declared != Auto -> declared; else auto_detect.
|
|
ColumnType effective_type(ColumnType declared,
|
|
const char* const* cells, int rows, int cols, int col);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Aggregation helpers.
|
|
// ----------------------------------------------------------------------------
|
|
const char* agg_fn_name(AggFn f);
|
|
|
|
// Pure: alias por defecto cuando agg.alias esta vacio.
|
|
// count -> "count"
|
|
// distinct col -> "distinct_<col>"
|
|
// percentile p -> "p<arg*100>_<col>" (ej. p95_size_kb)
|
|
// resto -> "<fn>_<col>" (ej. avg_size_kb)
|
|
std::string aggregation_alias(const Aggregation& a);
|
|
|
|
// Pure: tipo del output de la aggregation.
|
|
ColumnType aggregation_type(const Aggregation& a,
|
|
const std::vector<std::string>& in_headers,
|
|
const std::vector<ColumnType>& in_types);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Compute pipeline.
|
|
// ----------------------------------------------------------------------------
|
|
// Pure: ejecuta un Stage sobre los cells de entrada. Aplica filter -> (group+agg|passthrough) -> sort.
|
|
StageOutput compute_stage(const char* const* in_cells, int in_rows, int in_cols,
|
|
const std::vector<std::string>& in_headers,
|
|
const std::vector<ColumnType>& in_types,
|
|
const Stage& stage);
|
|
|
|
// Pure: aplica filtros usando headers para resolver f.col.
|
|
std::vector<int> apply_filters(const char* const* cells, int rows, int cols,
|
|
const std::vector<Filter>& filters);
|
|
|
|
// Pure: helper para drill-down. Devuelve un Filter Op::Eq sobre col_idx con
|
|
// el value indicado.
|
|
Filter make_drill_filter(int col_idx, const std::string& value);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// ViewMode helpers.
|
|
// ----------------------------------------------------------------------------
|
|
const char* view_mode_token(ViewMode m);
|
|
const char* view_mode_label(ViewMode m);
|
|
ViewMode view_mode_from_token(const char* s);
|
|
int view_mode_min_cols(ViewMode m);
|
|
bool view_mode_needs_numeric(ViewMode m);
|
|
bool view_mode_needs_category(ViewMode m);
|
|
bool view_mode_needs_aggregation(ViewMode m);
|
|
|
|
// Lista completa de modos para el selector UI.
|
|
const ViewMode* all_view_modes(int* n_out);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Joins (MBQL-style). Ver issue 0078.
|
|
// ----------------------------------------------------------------------------
|
|
const char* join_strategy_token(JoinStrategy s);
|
|
JoinStrategy join_strategy_from_token(const char* s);
|
|
const char* join_strategy_label(JoinStrategy s);
|
|
|
|
// Pure: resuelve indice del main entre `tables` segun `main_source`.
|
|
int resolve_main_idx(const std::vector<TableInput>& tables, const std::string& main_source);
|
|
|
|
// Pure: aplica un join sobre dos tablas.
|
|
StageOutput join_tables(const char* const* left_cells, int left_rows, int left_cols,
|
|
const std::vector<std::string>& left_headers,
|
|
const std::vector<ColumnType>& left_types,
|
|
const TableInput& right,
|
|
const Join& jn);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Drill apply/undo (fase 10).
|
|
// ----------------------------------------------------------------------------
|
|
bool apply_drill_step(State& st, const DrillStep& step);
|
|
bool undo_drill_step(State& st, const DrillStep& step);
|
|
|
|
// Pure (fase 10): drill-up. Decrementa active_stage si > 0.
|
|
bool drill_up(State& st);
|
|
|
|
// Pure (fase 10): serializa una fila a TSV.
|
|
std::string row_to_tsv(const char* const* cells, int rows, int cols,
|
|
int row_idx, const std::vector<std::string>& headers);
|
|
|
|
// Pure (fase 10): construye filters Op::Eq desde una fila.
|
|
std::vector<Filter> build_filters_from_row(const char* const* cells, int rows,
|
|
int cols, int row_idx);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Date granularity helpers (fase 10).
|
|
// ----------------------------------------------------------------------------
|
|
const char* date_granularity_token(DateGranularity g);
|
|
DateGranularity date_granularity_from_token(const char* s);
|
|
|
|
DateGranularity parse_breakout_granularity(const std::string& breakout,
|
|
std::string& col_out);
|
|
|
|
std::string compose_breakout(const std::string& col, DateGranularity g);
|
|
|
|
void column_min_max(const char* const* cells, int rows, int cols, int col_idx,
|
|
std::string& min_out, std::string& max_out);
|
|
|
|
// Hit-tests para click-to-drill sobre charts (fase 10).
|
|
int nearest_index_1d(double target, const double* xs, int n);
|
|
int nearest_index_2d(double tx, double ty,
|
|
const double* xs, const double* ys, int n);
|
|
double pie_angle(double cx, double cy, double mx, double my);
|
|
int pie_slice_at_angle(double angle, const double* sums, int n);
|
|
void heatmap_cell_at(double px, double py, int rows, int cols,
|
|
int& row_out, int& col_out);
|
|
|
|
// Date trunc + auto + presets.
|
|
std::string truncate_date(const std::string& date, DateGranularity g);
|
|
DateGranularity auto_date_granularity(const std::string& min_ymd,
|
|
const std::string& max_ymd);
|
|
const char* filter_preset_label(FilterPreset p);
|
|
std::vector<Filter> build_preset_filters(FilterPreset preset, int col,
|
|
const std::string& today_ymd);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Misc helpers.
|
|
// ----------------------------------------------------------------------------
|
|
bool parse_number(const char* s, double& out);
|
|
bool compare(const char* a, const char* b, Op op);
|
|
|
|
std::vector<int> compute_visible_rows(const char* const* cells,
|
|
int rows, int cols,
|
|
const State& st);
|
|
|
|
void reorder_column(State& st, int src, int dst);
|
|
|
|
int find_open_bracket(const char* buf, int len, int cursor, std::string& filter_text);
|
|
|
|
std::string insert_column_ref(const std::string& src, int start, int cursor,
|
|
const std::string& name, int& new_cursor);
|
|
|
|
std::string csv_escape(const char* s);
|
|
|
|
std::string build_tsv(const char* const* cells, int rows, int cols,
|
|
const char* const* headers,
|
|
const std::vector<int>& col_order,
|
|
const std::vector<bool>& col_visible,
|
|
const std::vector<int>& visible_rows,
|
|
int view_row_lo, int view_row_hi,
|
|
int view_col_lo, int view_col_hi);
|
|
|
|
std::string build_csv(const char* const* cells, int rows, int cols,
|
|
const char* const* headers,
|
|
const std::vector<int>& col_order,
|
|
const std::vector<bool>& col_visible,
|
|
const std::vector<int>& visible_rows);
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// Column statistics — desde v1.5.0, ColStats + HIST_BINS + compute_column_stats
|
|
// viven en core/compute_column_stats.h (transitivamente via data_table_types.h).
|
|
// El playground los reutiliza directo, sin redefinir.
|
|
// ----------------------------------------------------------------------------
|
|
|
|
} // namespace data_table
|