fix: remove timestamp normalization instead of gating it by max_count

Review feedback (Vitor): gating the batch-max normalization behind
max_count == 1 just hid the same collapsing behavior for the single-point
case, where it's redundant anyway (aggregation/export don't need it) while
still being the wrong fix conceptually. Removed the normalization block
entirely so every record always keeps its own real timestamp from the PI
Web API, regardless of max_count.

Updated unit tests accordingly and confirmed no e2e scenario needs
adjustment: aggregate_data groups by (tag, name) and always collapses to
one output row per tag per execution, independent of per-record timestamp
values, so pi_web_api_scouter_multiple_tags' aggregated-value assertions
are unaffected.

SIENTIAPDE-1993

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Eduardo Rios
2026-09-11 16:05:37 -03:00
parent fc3660433f
commit f79d51336f
3 changed files with 13 additions and 28 deletions

View File

@@ -86,13 +86,8 @@ class API(SientiaMonitoring):
for a set of configured tags. It returns the data as a list of dictionaries
suitable for further processing in the workflow.
Timestamps are converted to string format. When max_count is 1 (one point per
tag), timestamps are additionally normalized to the maximum timestamp value
(lexicographically) found in the dataset, to align minor sampling differences
across tags. When max_count > 1 (multiple historical points per tag), each
record's real timestamp is preserved instead, since collapsing them would make
distinct historical points collide on the (model_id, timestamp, variable)
unique constraint downstream.
Timestamps are converted to string format and each record keeps its own real
timestamp as returned by the PI Web API.
Args:
input_data (dict[str, Any]): Activity input parameters.
@@ -106,8 +101,7 @@ class API(SientiaMonitoring):
Returns:
list[dict]: List of data records, each containing:
- timestamp: Timestamp string (normalized to a shared value only when
max_count is 1; otherwise each record's real timestamp)
- timestamp: Each record's real timestamp string
- name: Tag name
- value: Numeric value
- tag: WebId
@@ -152,15 +146,6 @@ class API(SientiaMonitoring):
self.debug(f'Latest values: {latest_values.to_string()}', metadata=metadata)
if max_count == 1:
# Normalize the package timestamp - only meaningful when a single point per tag
# is retrieved, to align minor sampling differences across tags. With
# max_count > 1 each historical point's real timestamp must be preserved,
# otherwise distinct records collide on the (model_id, timestamp, variable)
# unique constraint and are silently dropped downstream.
valid_timestamp_values = latest_values['timestamp'].dropna()
latest_values['timestamp'] = valid_timestamp_values.max()
self.info(f'Gathered {len(latest_values)} tag values', metadata=metadata)
return latest_values.to_dict(orient='records')