Skip to content

Conversation

@asynclizard
Copy link
Contributor

PR Description

Reason for Change

The TimeSeries component was failing to parse timestamps with inconsistent fractional second precision (e.g., .0, .5, .12) when using D3's utcParse function. This caused parsing failures and prevented proper visualization of time series data.

Problem: D3's time parsing expects consistent decimal precision, but real-world timestamp data often has varying fractional seconds (1, 2, or 3 digits).

Solution: Implement automatic padding of fractional seconds to exactly 3 decimal places before D3 parsing, ensuring consistent format while preserving data integrity.

Screenshots/Evidence

Video demonstration shows the fix in action:

  • Before: Timestamps like 2025-07-06 16:35:17.0 and 2025-07-06 16:35:17.5 fail D3 parsing
  • After: Timestamps are automatically padded to 2025-07-06 16:35:17.000 and 2025-07-06 16:35:17.500 for successful parsing

Rollout Strategy

  • Feature Flag: Uses existing FF_TIMESERIES_SYNC flag
  • Backward Compatible: Existing functionality preserved, only adds padding logic
  • No Database Changes: Pure frontend enhancement
  • Gradual Rollout: Can be toggled via feature flag if needed

Testing

Unit Tests Added:

  • should pad single digit fractional seconds to 3 digits
  • should pad two digit fractional seconds to 3 digits
  • should leave three digit fractional seconds unchanged
  • should handle microseconds and pad remaining digits correctly
  • should handle timestamps without fractional seconds
  • should handle mixed fractional second formats in the same dataset

Test Coverage:

  • Edge cases: 0, 1, 2, 3+ digit fractional seconds
  • Mixed datasets with varying precision
  • Integration with existing microseconds truncation
  • D3 parsing validation with actual timestamp examples

Risks

Low Risk:

  • Performance: Minimal overhead - only processes string timestamps
  • Data Integrity: Padding preserves original values, only affects display format
  • Backward Compatibility: Existing datasets continue to work
  • Security: No new attack vectors introduced

Mitigation:

  • Comprehensive test coverage for edge cases
  • Preserves existing microseconds truncation logic
  • Handles mixed precision within same dataset

Reviewer Notes

Key Implementation Details:

  • Padding logic added to TimeSeries.jsx dataObj getter (lines ~380)
  • Uses regex replacement: /\.(\d{0,3})\b/ to match and pad fractional seconds
  • Template literal used for string concatenation (linter compliance)
  • Mock environment updated in tests to include required messages property

Code Quality:

  • Follows existing patterns in TimeSeries component
  • Maintains separation of concerns (parsing vs. display logic)
  • Comprehensive error handling for malformed timestamps
  • Clean, readable implementation with clear comments

General Notes

Impact:

  • Fixes D3 parsing failures for real-world timestamp data
  • Improves user experience with TimeSeries visualizations
  • Enables proper handling of datasets with inconsistent precision

Technical Details:

  • Works alongside existing microseconds conversion (6→3 digits)
  • Handles edge cases like timestamps without fractional seconds
  • Preserves original data while ensuring D3 compatibility
  • No breaking changes to existing API or data format

The implementation successfully addresses the core issue while maintaining code quality and comprehensive test coverage.

…arsing

TimeSeries component now automatically pads fractional seconds in timestamps
to exactly 3 decimal places to ensure consistent D3 parsing. This prevents
parsing failures when timestamps have inconsistent decimal precision.

Examples:
- "2025-07-06 16:35:17.0" → "2025-07-06 16:35:17.000"
- "2025-07-06 16:35:18.5" → "2025-07-06 16:35:18.500"
- "2025-07-06 16:35:19.12" → "2025-07-06 16:35:19.120"

Changes:
- Add fractional seconds padding logic in TimeSeries dataObj view
- Preserve existing microseconds truncation functionality
- Add comprehensive unit tests covering various timestamp formats
- Fix test environment mock to include required messages property

The padding works alongside existing microseconds conversion and handles
mixed timestamp formats within the same dataset.
@asynclizard asynclizard requested a review from a team as a code owner July 29, 2025 07:17
@netlify
Copy link

netlify bot commented Jul 29, 2025

Deploy Preview for label-studio-docs-new-theme canceled.

Name Link
🔨 Latest commit 63225be
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-docs-new-theme/deploys/6888b53b8922ff00080821f1

@netlify
Copy link

netlify bot commented Jul 29, 2025

Deploy Preview for heartex-docs canceled.

Name Link
🔨 Latest commit 63225be
🔍 Latest deploy log https://app.netlify.com/projects/heartex-docs/deploys/6888b53b86552c00082325a6

@netlify
Copy link

netlify bot commented Jul 29, 2025

Deploy Preview for label-studio-storybook canceled.

Name Link
🔨 Latest commit 63225be
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-storybook/deploys/6888b53bb12d8e000878efeb

@github-actions github-actions bot added the fix label Jul 29, 2025
@netlify
Copy link

netlify bot commented Jul 29, 2025

Deploy Preview for label-studio-playground canceled.

Name Link
🔨 Latest commit 63225be
🔍 Latest deploy log https://app.netlify.com/projects/label-studio-playground/deploys/6888b53b0d53df00083a2a8a

@asynclizard asynclizard requested review from a team and removed request for a team July 29, 2025 07:17
@codecov
Copy link

codecov bot commented Jul 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.89%. Comparing base (cca42cd) to head (63225be).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #8056      +/-   ##
===========================================
- Coverage    70.37%   65.89%   -4.48%     
===========================================
  Files          719      505     -214     
  Lines        51023    33497   -17526     
  Branches      8621     8622       +1     
===========================================
- Hits         35906    22074   -13832     
+ Misses       15114    11420    -3694     
  Partials         3        3              
Flag Coverage Δ
lsf-e2e 59.49% <100.00%> (+<0.01%) ⬆️
lsf-integration 55.64% <100.00%> (+<0.01%) ⬆️
lsf-unit 9.45% <100.00%> (+0.05%) ⬆️
pytests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asynclizard
Copy link
Contributor Author

asynclizard commented Jul 29, 2025

/git merge

Workflow run
Successfully merged: create mode 100644 label_studio/users/tests/test_redis_activity.py

@niklub niklub self-requested a review July 29, 2025 21:12
@niklub niklub merged commit 7269908 into develop Jul 29, 2025
46 checks passed
@robot-ci-heartex robot-ci-heartex deleted the fb-bros-200-timeline branch July 29, 2025 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants