Repository navigation
M2E: bounded RCB report member projection and truthful truncation UI #167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #include "MmsEngineeringEvidence.hpp" | ||
| #include "ariec61850/mms/data_codec.hpp" | ||
| #include "ariec61850/mms/reporting.hpp" | ||
|
|
||
| #include <QString> | ||
| #include <QStringList> | ||
| #include <QVariantList> | ||
| #include <QVariantMap> | ||
|
|
||
| #include <algorithm> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <vector> | ||
| #include <utility> | ||
|
|
||
| // Bounded, read-only projection of already-decoded MMS report members. | ||
| // Report runtime keeps full authoritative frame. The GUI only needs a preview. | ||
| namespace arstack::iedsim { | ||
| namespace mms = ar::iec61850::mms; | ||
|
|
||
| struct BrowserReportMemberProjection final { | ||
| QStringList values; | ||
| QVariantList evidence; | ||
| bool rowsTruncated{}; | ||
| bool textTruncated{}; | ||
| bool evidenceTruncated{}; | ||
| }; | ||
|
|
||
| inline constexpr int kBrowserReportVisibleMemberLimit = 256; | ||
| inline constexpr int kBrowserReportTextLimit = 1024; | ||
|
|
||
| [[nodiscard]] inline BrowserReportMemberProjection projectBrowserReportMembers( | ||
| const std::vector<mms::MmsReportValue>& members, | ||
| int& remainingTypedEvidence, | ||
| const int requestedVisibleMembers = kBrowserReportVisibleMemberLimit) { | ||
| BrowserReportMemberProjection projection; | ||
| const int visibleLimit = std::clamp(requestedVisibleMembers, 0, kBrowserReportVisibleMemberLimit); | ||
| const auto visibleCount = std::min(members.size(), static_cast<std::size_t>(visibleLimit)); | ||
| projection.rowsTruncated = members.size() > visibleCount; | ||
| projection.values.reserve(static_cast<qsizetype>(visibleCount)); | ||
|
|
||
| for (std::size_t ordinal = 0; ordinal < visibleCount; ++ordinal) { | ||
| const auto& member = members[ordinal]; | ||
| QString reference = QString::fromStdString(member.data_reference); | ||
| if (reference.isEmpty() && member.member) | ||
| reference = QString::fromStdString(member.member->user_reference); | ||
| if (reference.isEmpty() && member.member) | ||
| reference = QString::fromStdString(member.member->mms_reference); | ||
|
|
||
| QString displayReference = reference; | ||
| if (displayReference.isEmpty()) | ||
| displayReference = QStringLiteral("member[%1]").arg( | ||
| static_cast<qulonglong>(member.data_set_index)); | ||
| QString displayValue = QStringLiteral("<failed>"); | ||
| if (member.value) | ||
| displayValue = QString::fromStdString(mms::MmsDataCodec::to_display_string(*member.value)); | ||
| QString reasons; | ||
| for (const auto& reason : member.reason_for_inclusion.names) { | ||
| if (!reasons.isEmpty()) reasons += QStringLiteral(", "); | ||
| reasons += QString::fromStdString(reason); | ||
| } | ||
| QString text = QStringLiteral("%1 = %2%3").arg( | ||
| displayReference, displayValue, | ||
| reasons.isEmpty() ? QString{} : QStringLiteral(" · ") + reasons); | ||
| if (text.size() > kBrowserReportTextLimit) { | ||
| projection.textTruncated = true; | ||
| text = text.left(kBrowserReportTextLimit) + QStringLiteral(" … [preview truncated]"); | ||
| } | ||
| projection.values.push_back(std::move(text)); | ||
|
|
||
| // Only read successful typed q/t values, and only when the retained | ||
| // presentation row matches the member ordinal (never DataSet position). | ||
| if (!member.value || reference.isEmpty()) continue; | ||
| if (remainingTypedEvidence > 0) { | ||
| const auto decoded = decodeEngineeringEvidence(reference, *member.value); | ||
| if (!decoded.isEmpty()) { | ||
| projection.evidence.push_back(QVariantMap{ | ||
| {QStringLiteral("index"), static_cast<int>(ordinal)}, | ||
| {QStringLiteral("evidence"), decoded}}); | ||
| --remainingTypedEvidence; | ||
| } | ||
| } else { | ||
| // Do not decode (allocate rows) once the shared budget is empty. | ||
| const auto separator = std::max( | ||
| reference.lastIndexOf(QLatin1Char('$')), | ||
| reference.lastIndexOf(QLatin1Char('.'))); | ||
| const QString leaf = reference.mid(separator + 1); | ||
| const auto kind = member.value->kind(); | ||
| if ((leaf == QStringLiteral("q") && kind == mms::MmsDataKind::bit_string) || | ||
| (leaf == QStringLiteral("t") && kind == mms::MmsDataKind::utc_time)) | ||
| projection.evidenceTruncated = true; | ||
| } | ||
| } | ||
| return projection; | ||
| } | ||
| } // namespace arstack::iedsim | ||
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a retained member contains a large string, byte sequence, array, or structure,
to_display_stringfirst materializes the complete recursively formattedstd::string, andfromStdStringthen copies all of it into aQString; the 1,024-character limit is applied only afterward. BecausebuildSubscriptionUirepeats this for up to 128 retained reports on every 100-ms poll, a history of large valid values can still cause substantial allocation churn and delay report refreshes despite the advertised bound. Use a length-aware formatter that stops appending at the preview limit rather than truncating after full conversion.AGENTS.md reference: AGENTS.md:L133-L140
Useful? React with 👍 / 👎.