Skip to content

Counts next to every filter dropdown, region-scoped or nationwide #165

Closed

Description

@prayaslashkari

This was generated by AI during triage.

Follow-up 2 from #70 (listed in the 2026-10-26 comment, never filed).

Request

Show counts next to dropdown options, the same way everywhere: region-scoped when a region is applied, nationwide when none is.

Dropdown Counts today
Substance Region-scoped and nationwide
Material type Region-scoped and nationwide
Industry (NAICS) Only once a state is picked; needs a nationwide fallback
Feature Type (Surface Water) None
Well Source None
Aquifer Type None

Nationwide counts should not run every time an analysis question opens.

For reference, Feature Type records on hydrologykg as of 2026-10-26: Stream / River 353,003, Artificial Path 69,801, Lake / Pond 60,083, Swamp / Marsh 12,015, Canal / Ditch 7,821, Connector 3,786, Reservoir 886, Pipeline 90.

Open for triage

  • Whether nationwide counts are live queries cached for a long time, or stored values (see Idea - Optimize the Probing Queries #125 for the same idea applied to count steps)
  • The cost of each count query, measured live, before choosing

Activity

  1. prayaslashkari commented on Nov 17, 2026

    @prayaslashkari
    CollaboratorAuthor

    This was generated by AI during triage.

    Agent Brief

    Category: enhancement
    Summary: Show counts next to every filter dropdown option: for the selected region when one is picked, nationwide when none is. Counts come from live queries cached for the session, not stored values.

    Decision (maintainer, 2026-11-17): counts are live SPARQL queries cached for the session (React Query, staleTime: Infinity). Do not store or precompute them (no CSV, no constants with counts, no server cache). Measured cost made this safe: every count query below ran in 1.2s or less on its first run.

    Current behavior:

    • Substance and Material type: counts for the region and nationwide. These are the model to follow (useSubstances, useMaterialTypes: region key in the query key, staleTime: Infinity, fallback constant as placeholder).
    • Industry (NAICS): counts only once a state is picked (useIndustryCounts is disabled with no state). No nationwide counts.
    • Well classification (Illinois purpose, Maine type, Maine use): has counts (useWellClassifications), but always for the whole of IL or ME, never the picked state or county.
    • Feature Type (Surface Water: water bodies and flowlines): options are static FTYPE constants, no counts.
    • Aquifer Type (sand & gravel, bedrock): static options, no counts.

    Desired behavior:

    1. Every dropdown above shows a count next to each option: for the selected region (state or counties) when a region is applied, nationwide when none is.
    2. A region count uses the same region check as the query that option feeds, i.e. the entity type's own cell bind plus its regionCheck (wells and aquifers check the subdivision link, Region filter on wells lets in wells from outside the region #96 and Region filter on aquifers: check the subdivision link, like wells #144; facilities check anyRegionLinkCheck, Facilities: show those with no industry code, and check the region on the facility #145). Otherwise the dropdown and the result disagree. Measured for Hancock County ME wells (2026-11-17): 11,644 by subdivision link only, 7,428 by S2 cell only, 7,296 by both, which is what the pipeline returns. The dropdown must show the 7,296-style number.
    3. Each count query runs at most once per region per session, and only when its filter panel mounts (as Substance does today). Opening an analysis question must not fire nationwide counts for dropdowns that are not shown.
    4. Industry nationwide counts run on federation. The same query on fiokg took 26.9s on a cold first run (0.86s on federation).
    5. Feature Type is a tree (HierarchicalSelect): pass leaf counts and let the existing rollup sum the parents ("Surface Water Bodies", "Streams and Flowlines"). FTYPE values partition each parent, so the rollup is sound.
    6. Aquifer Type has two options, each mapped to several raw values through AQUIFER_TYPE_VALUES. An option's count is the number of distinct aquifers over all its raw values.
    7. If a count query fails, the dropdown still works and shows no numbers (as Industry does today). No error banner.

    Live reference numbers (2026-11-17), for checking the result:

    Option Nationwide Maine (23) Hancock (23009) Illinois (17)
    Lake / Pond 60,083 4,412 348 7,803
    Swamp / Marsh 12,015 2,191 170 212
    Reservoir 886 9 0 213
    Stream / River 353,003 18,922 1,425 52,385
    Artificial Path 69,801 10,396 688 7,478
    Canal / Ditch 7,821 48 0 1,444
    Connector 3,786 310 27 609
    Pipeline 90 1 1 11
    Aquifer: sand & gravel 8,427 4,972 181 3,455
    Aquifer: bedrock 14 0 0 14

    Region numbers for water bodies and flowlines above are distinct features in S2 Level 13 cells connected to the region; aquifers by subdivision link. The agent should re-measure with the final query shape (cell check plus region check where the type has one) and record what it gets.

    Measured timings (first run, 200 OK): nationwide FTYPE 0.22s and 0.37s, aquifers 0.14s, wells 0.89s, NAICS 0.86s; region (ME, Hancock, IL, federation) all between 0.26s and 0.89s. Wells with both checks in Hancock: 2.1s.

    Key interfaces:

    • The discovery query builders (alongside buildIndustryCountsQuery, buildDiscoverSubstancesQuery): add count builders for Feature Type (water bodies, flowlines), Aquifer Type and well classifications that take an optional { stateCode, countyCodes? } region. Build the region part from the entity modules (bindInCell, regionCheck) rather than re-writing it, so a later change to a type's region check moves its count with it.
    • useIndustryCounts(region): no longer disabled without a state; nationwide variant on federation.
    • useWellClassifications(): takes the region; region in the query key.
    • New hooks for Feature Type and Aquifer Type counts, keyed [name, regionKey] like useSubstances.
    • HierarchicalSelect already takes counts?: Record<string, number>. FlatSelect has no count prop; follow the existing withCount() label pattern rather than adding a third select component.

    Acceptance criteria:

    • With no region applied, Industry, Feature Type, Aquifer Type and Well classification show nationwide counts.
    • With Maine or Hancock applied, each shows region counts that match a fresh run of the pipeline for that option (e.g. Hancock wells total 7,296 as of 2026-11-17, not 11,644).
    • Changing region refetches once; returning to a region already seen in the session does not refetch (check the network tab or a hook test).
    • Opening a question whose blocks have no filter panels open fires no new count queries.
    • Feature Type parents show the sum of their children.
    • A failed count query leaves the dropdown usable with no numbers.
    • Offline Vitest tests: a golden or unit test of each new count query's text for no region, a state, and counties; a test that each count query's region part is the same as the entity type's region check (the rule that is silent when wrong).
    • docs/wiki/ updated in the same PR: Industry Counts page (no longer "no region, no counts"), the Feature Type and Aquifer sections, and the stale "Well Source" entry in the dropdown index replaced with Well classification and its counts.
    • npm run build, npm test, npm run lint (no new errors) pass; report the output.

    Out of scope:

  2. added
    ready-for-agentFully specified, ready for an AFK agent
    and removed
    needs-triageMaintainer needs to evaluate this issue
    on Nov 17, 2026
  3. prayaslashkari commented on Nov 17, 2026

    @prayaslashkari
    CollaboratorAuthor

    This was generated by AI during triage.

    Shipped in #168, merged to development 2026-11-17. Industry, Feature Type, Aquifer Type and Well classification show counts for the selected region, or nationwide with none, from live queries cached for the session. Reaches production with the next development to main merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions