refactor(scoring): name formula constants and type env vars - #321
Merged
abayomicornelius merged 1 commit intoJul 29, 2026
Merged
Conversation
Replace the magic numbers in computeScores with documented constants (SCORE_MIN/SCORE_MAX, PERCENT_MAX, GREEN_IMPACT_POWER_WEIGHT, GREEN_IMPACT_FOREST_WEIGHT, POWER_RATIO_FALLBACK) so the formula reads as intent. Results are unchanged. Add optional timestamp fields to IotInput so freshness data returned by getSolarData/getSatelliteData survives the type boundary instead of being silently discarded, and document that computeScores ignores them. Document why satellite.ndvi_score stays on the interface: computeScores does not read it, but computeScoresWithFormula weights it via ndvi_weight, so removing it would break the configurable formula engine. Add src/types/env.d.ts declaring every environment variable on NodeJS.ProcessEnv for autocomplete and typo protection. Closes Heliobond#229 Closes Heliobond#230 Closes Heliobond#231 Closes Heliobond#232
|
@Gbemi-programmer Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #230
Closes #232
Closes #231
Closes #229
#230 — Magic numbers → named constants
computeScoresno longer hardcodes 50/100. Constants live at the top ofsrc/lib/scoring.ts, each with a comment explaining its role:SCORE_MIN/SCORE_MAXPERCENT_MAXGREEN_IMPACT_POWER_WEIGHTGREEN_IMPACT_FOREST_WEIGHTPOWER_RATIO_FALLBACKmax_power_kwis 0Arithmetic is unchanged — every existing assertion still passes, plus a new
test that recomputes the expected score from the constants themselves.
#232 — Timestamps on
IotInputsolar.timestampandsatellite.timestampare now declared, optional, so thevalues
getSolarData/getSatelliteDataalready return are no longer dropped atthe type boundary.
computeScoresdeliberately ignores them — scoring stays apure function of the reading's values — and that is documented on the fields so
a future staleness check has an obvious place to hook in. Optional means no
existing caller changes.
#231 —
ndvi_score: documented, not removedThe field is not dead.
computeScoresscores greenery fromforest_density_pctalone, butcomputeScoresWithFormula(
src/lib/scoring-formula.ts:101) weightsndvi_scorethroughndvi_weight,and
/api/scoring-formulasexercises that path. Removing it fromIotInputwould break the configurable formula engine and every route that forwards
satellite data. So the decision is documented in a JSDoc block on the field
rather than the field being dropped.
#229 — Typed environment variables
New
src/types/env.d.tsmerges intoNodeJS.ProcessEnvand declares everyvariable the codebase reads — Stellar/Soroban, HTTP, database, resilience, cron
and IoT, rate limiting, logging and APM — each documented with its expected
format and default. All are
string | undefined, matching reality: the processenvironment is untyped strings and any variable may be absent, so callers still
parse and default. The doc block points readers at
src/config.tsas thepreferred access path; this declaration makes the remaining direct
process.envreads safe and autocompleting.Note on one unrelated line
src/__tests__/scoring.test.tshad a stray extra});onmainthat made thewhole suite fail to parse — no test in the file was running. I removed that
single brace so the tests here can execute; nothing else in the existing tests
was touched.
Verification
npx jest src/__tests__/scoring.test.ts— 26 passednpx tsc --noEmit— cleannpx eslint+npx prettier --checkon changed files — clean