Skip to content

Fix broken filters - #167

Merged
clackner-gpa merged 2 commits into
masterfrom
fix-broken-filters
Sep 21, 2026
Merged

clackner-gpa merged 2 commits into
masterfrom
fix-broken-filters

Conversation

@StephenCWills

@StephenCWills StephenCWills commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Logic was written like so...

Meter.ID IN (MeterList) AND
Meter.LocationID IN (LocationList)
Meter.ID IN (AssetGroupMeters) AND
Asset.ID IN (AssetList) AND
Asset.ID IN (AssetGroupAssets)

But the correct logic should look more like this...

Meter.ID IN (MeterList) AND
Asset.ID IN (AssetList) AND
(
    Meter.LocationID IN (LocationList) OR
    AssetLocation.LocationID IN (LocationList)
) AND
(
    Meter.ID IN (AssetGroupMeters) OR
    Asset.ID IN (AssetGroupAssets)
)

There are additional complications due to the possibility that there may not be any filter defined for location or asset group, but this is the basic idea.


As for disturbance filters, the filter query looks something like this...

SELECT DISTINCT Disturbance.*
INTO #disturbanceFilter
FROM
    (
        SELECT TOP 100 EventID
        FROM Event JOIN Disturbance
        WHERE <filters>
        ORDER BY <ordering>
     ) JOIN Disturbance

The inner query ensures we get at least as many event IDs as we need to return at least 100 results. Because of the trick we use for the ORDER BY clause, we must forget about the disturbances we joined into the inner query and rejoin them to the filtered event list. However, that means we need to apply all the same filters to the outer query as we did the inner query so we don't return results that were filtered out of the inner query. Therefore, the idea is to simply add WHERE <filters> to the end of the query.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Correct the invalid MeterAssetGroup.ID references and preserve unlocated meters when no location filter is supplied.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)
What changed in this PR

Fixes Event Search filtering for location, asset-group, disturbance, and fault queries.

Changes:

  • Adds temporary meter and asset filter tables.
  • Applies OR-based location and asset-group matching.
  • Reapplies disturbance filters after rejoining results.
File Summary
PQBrowser/​Controllers/​OpenXDAController.cs Updates event, disturbance, and fault filtering logic; contains a critical invalid-column issue and a moderate NULL-location filtering issue.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread PQBrowser/Controllers/OpenXDAController.cs
@clackner-gpa
clackner-gpa merged commit 6bd89f8 into master Sep 21, 2026
3 checks passed
@clackner-gpa
clackner-gpa deleted the fix-broken-filters branch September 21, 2026 19:03
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.

4 participants