Skip to content

Add functions to list variables available in a .sql file (#17) - #22

Merged
voightp merged 1 commit into
mainfrom
feat/17-list-sql-variables
Jul 15, 2026
Merged

Add functions to list variables available in a .sql file (#17)#22
voightp merged 1 commit into
mainfrom
feat/17-list-sql-variables

Conversation

@Tokarzewski

Copy link
Copy Markdown
Collaborator

Summary

Implements #17 — a way to discover what variables a .sql file contains, grouped by table (reporting frequency). Adds the three methods suggested in the issue:

fromdb_eplusout_readerimportget_tables, get_variables, get_all_variablesget_tables(path) # -> ['timestep', 'hourly', 'daily', 'monthly', 'runperiod']get_variables(path, H) # -> [Variable(key='Environment', type='Site Opaque Sky Cover', units=''), ...]get_all_variables(path) # -> OrderedDict {frequency: [Variable, ...]}
  • get_tables returns the distinct frequencies as {TS, H, D, M, A, RP} constants, de-duplicated (Zone Timestep / HVAC System Timestep both map to TS) and ordered most→least granular.
  • get_variables returns the sorted Variable list for one frequency.
  • get_all_variables composes the two into a {frequency: [Variable, ...]} overview.

All three are exported from the package top level. A small connect() helper centralizes the file-existence check, now also reused by get_results_from_sql.

Tests

Added TestListVariables (runs across all versioned SQL fixtures): table discovery + de-dup + ordering, per-frequency variable listing, a non-meter round-trip through get_results, get_all_variables consistency, and IOError on a missing file. Full suite: 130 passed; ruff clean.

Note

Listed meter variables carry key='' (NULL KeyValue) and currently aren't retrievable by exact key match — that's the limitation tracked in #12 (fixed separately in #21). Listing them here is correct; only exact-key retrieval is affected.

🤖 Generated with Claude Code

Introduce three public helpers:
- get_tables(path): reporting frequencies present in the file
- get_variables(path, frequency): variables available for a frequency
- get_all_variables(path): {frequency: [Variable, ...]} overview
Also add a connect() helper and reuse it in get_results_from_sql to
share the file-existence check.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Tokarzewski
Tokarzewski requested a review from voightpJune 9, 2026 07:27
@voightp
voightp merged commit e2def70 into mainJul 15, 2026
7 checks passed
@Tokarzewski
Tokarzewski deleted the feat/17-list-sql-variables branch July 28, 2026 08:08
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@Tokarzewski@voightp