Skip to content

feat(api): expose n_Apartment on GET /data/:code - #39

Merged
jravani merged 1 commit into
mainfrom
feat/n-apartment-passthrough
Sep 9, 2026
Merged

jravani merged 1 commit into
mainfrom
feat/n-apartment-passthrough

Conversation

@jravani

@jravani jravani commented Sep 9, 2026

Copy link
Copy Markdown
Member

Closes #38

What

GET /api/v1/data/{code} now returns the TABULA apartment count at tabula_data.BasicParameters.BuildingAppearance.n_Apartment.

  • internal/models/tabula.go: N_Apartment int with json tag n_Apartment on BuildingThematic. GetVariant selects every column and the struct mapper matches by json tag, so no repository, handler, SQL or migration change.
  • docs/openapi/openapi.yaml: one sentence in the TabulaData description. It is not listed under CalculateRequest because it is not an override and the calculate body rejects unknown fields.
  • internal/db/repository/struct_mapper_test.go: asserts a float32 map value lands as int.
  • internal/db/repository/repository_integration_test.go: tabula.netherlands fixture with a REAL column; AB.03 returns 15, SFH.01 returns 1.

Why

Downstream building models scale occupancy-driven loads by the number of dwellings. Without this field a caller has to assume one dwelling per building, which under-counts every apartment block.

Verification

  • go vet ./..., go build ./..., go test ./... pass.
  • go test -tags integration ./internal/db/repository/ passes against a testcontainers Postgres.
  • Against a local database built from the workbook:
Variant n_Apartment
NL.N.AB.03.Gen.ReEx.001.001 15
NL.N.SFH.01.Gen.ReEx.001.001 1
NL.N.TH.01.Gen.ReEx.001.001 1
DE.N.MFH.05.Gen.ReEx.001.001 32

Data notes

The column is REAL in PostgreSQL. All 2147 rows across the 20 country tables hold whole numbers, so the int conversion loses nothing. Three Denmark variants (DK.N.AB.09.Gen.ReEx.001.001 to .003) hold 0 because the workbook gives no count; the OpenAPI text documents 0 as "no count".

Downstream building models scale occupancy-driven loads (internal
gains, electricity, hot water) by the number of dwellings in a
building. TABULA carries that count as n_Apartment, and every country
table already holds the column because the workbook loader imports
every header, but GET /api/v1/data/:code did not expose it, so a
caller had to assume one dwelling per building.

Add N_Apartment to BuildingThematic. GetVariant selects every column
and the struct mapper matches by json tag, so no repository, handler,
SQL or migration change is needed. The column is REAL in PostgreSQL;
the mapper's float32 case converts it to int, and every stored value
across the 20 country tables is a whole number.

It lands at tabula_data.BasicParameters.BuildingAppearance.n_Apartment.
SFH and TH variants carry 1, MFH and AB carry the archetype's dwelling
count, and the three DK.N.AB.09 variants carry 0 because the workbook
gives no count for them.

Closes #38
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jravani
jravani merged commit cd110b7 into main Sep 9, 2026
6 checks passed
@jravani
jravani deleted the feat/n-apartment-passthrough branch September 9, 2026 19:42
Sign up for free to 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.

Expose n_Apartment on GET /api/v1/data/{code}

2 participants