Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@svonworl
Copy link
Contributor

@svonworl svonworl commented Dec 8, 2025

Description
This PR modifies the UI's time series related code to:

  • Add support for time series with intervals of DAY or MONTH (in addition to the existing WEEK support).
  • Change the small graphs in the versions table to display monthly time series (rather than weekly).
  • Perform some rudimentary unit testing of the time series adjustTimeSeries functionality.

To cleanly implement the support for time series with intervals of DAY or MONTH, we refactor TimeSeriesService so that internally, it performs interval-specific time series operatings by delegating to an instance of IntervalOps, which is an interface that encapsulates methods that manipulate time and generate labels for a particular time series interval. Factory method createIntervalOps creates an instance that implements IntervalOps and is compatible with a particular time series. Supporting an another time series interval should be as easy as creating a corresponding implementation of IntervalOps and adjusting the factory method to use it.

Review Instructions
On qa, navigate to the "Versions" tab of a workflow with metrics, and confirm that there is a "Monthly Runs" column that displays a monthly time series for versions with metrics.

Issue
https://ucsc-cgl.atlassian.net/browse/SEAB-7366

Security
If there are any concerns that require extra attention from the security team, highlight them here.

Please make sure that you've checked the following before submitting your pull request. Thanks!

  • Check that your code compiles by running npm run build
  • Ensure that the PR targets the correct branch. Check the milestone or fix version of the ticket.
  • If this is the first time you're submitting a PR or even if you just need a refresher, consider reviewing our style guide
  • Do not bypass Angular sanitization (bypassSecurityTrustHtml, etc.), or justify why you need to do so
  • If displaying markdown, use the markdown-wrapper component, which does extra sanitization
  • Do not use cookies, although this may change in the future
  • Run npm audit and ensure you are not introducing new vulnerabilities
  • Do due diligence on new 3rd party libraries, checking for CVEs
  • Don't allow user-uploaded images to be served from the Dockstore domain
  • If this PR is for a user-facing feature, create and link a documentation ticket for this feature (usually in the same milestone as the linked issue). Style points if you create a documentation PR directly and link that instead.
  • Check whether this PR disables tests. If it legitimately needs to disable a test, create a new ticket to re-enable it in a specific milestone.

@svonworl svonworl self-assigned this Dec 8, 2025
@svonworl svonworl requested a review from denis-yuen December 8, 2025 04:43
@codecov
Copy link

codecov bot commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 41.92%. Comparing base (aa5d5fb) to head (f9ad772).
⚠️ Report is 3 commits behind head on develop.

Files with missing lines Patch % Lines
src/app/shared/timeseries.service.ts 87.50% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2150      +/-   ##
===========================================
+ Coverage    41.58%   41.92%   +0.34%     
===========================================
  Files          394      394              
  Lines        12495    12521      +26     
  Branches      2979     2981       +2     
===========================================
+ Hits          5196     5250      +54     
+ Misses        4973     4945      -28     
  Partials      2326     2326              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

let intervalCount = Math.max(Math.floor((to - from) / TimeConstants.AVERAGE_MONTH_MILLIS) - 2, 0);
let when = this.addIntervals(from, intervalCount);
// Step 2: Add more intervals, one by one, until we've passed the "to" time.
while (when < to) {
Copy link
Member

Choose a reason for hiding this comment

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

Is the loop just the same as calculating the length of the internal and just dividing by your average month milliseconds?

May be more readable as
dayjs.duration().asMonths();
https://day.js.org/docs/en/durations/months

@svonworl
Copy link
Contributor Author

svonworl commented Dec 8, 2025

I made the Ops -> Operations change, added some comments above some of the sections that Denis mentioned in his review feedback, and made a couple of simplifications/refactors.

Regarding the time computations themselves, yes, it'd be great to make the arithmetic time manipulations more readable and type-safe. For example, to change stuff like:

const lastDay: middle + 3 * TimeConstants.DAY_MILLIS;

to

const lastDay: middle.add(3, 'days');

However, I have not found an existing library that looks robust and well-designed enough to be used confidently. We need to implement the time series adjustments precisely in UTC, without accidentally lapsing to local time or DST, otherwise time series that have been generated at different times may become misaligned with each other or mislabeled when displayed in our UI (which is bad). Such problems can also potentially be huge PITA to debug and remedy, if they only happen occasionally and are buried deep in the library somewhere.

Lots of the existing libraries have mutable date representations, which are an open invitation to future bugs and should be avoided. dayjs looks ok, but I'm not confident in its overall robustness, especially since the utc and duration functionality are bolted on via plugins. Due to its design, it would also be easy to misuse dayjs in ways that seemed superficially correct, or wherein the incorrectness was easy to miss.

So, I strongly recommend staying with the existing arithmetic time computations for now. To help, I've added commented and simplified the ones that might be confusing.

After the new Temporal API https://tc39.es/proposal-temporal/ is finalized and released, we should consider using it (easy to do). It's very similar to the time APIs introduced in Java 8, which are very well designed, and we use to implement similar functionality in the webservice. Also, built-in libraries are also likely to be very-stringently vetted, better documented, and more functionality correct. Using the Temporal API's Instant throughout would be the ticket.

@svonworl svonworl requested a review from denis-yuen December 8, 2025 20:39
@denis-yuen
Copy link
Member

denis-yuen commented Dec 8, 2025

However, I have not found an existing library that looks robust and well-designed enough to be used confidently.

Try taking a look at https://github.com/you-dont-need/You-Dont-Need-Momentjs/blob/master/README.md#brief-comparison and the code examples, I'm not wedded to any of the three. But I do think that a lot of time has been spent by others looking at and working on them and they deserve more time/consideration.

In particular

Lots of the existing libraries have mutable date representations

bolted on via plugin

I think this is intentional to reduce library size and not meant as a comment on quality.
Note the extremely small size of the library in the table comparison.

Also, built-in libraries are also likely to be very-stringently vetted, better documented, and more functionality correct.

I don't necessarily disagree with this, and it may be worth a deeper look since it may have released this year? ( https://computus.org/when-can-i-use-temporal/ ) . The larger point is that if we further pursue the line of thought as to which alternative is better vetted and documented, that doesn't really act as an argument for our own date/time code which we know for sure has few eyes on it.

@denis-yuen
Copy link
Member

Another interesting compromise/possibility https://www.npmjs.com/package/temporal-polyfill

Copy link
Member

@denis-yuen denis-yuen left a comment

Choose a reason for hiding this comment

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

Was here, thanks for looking into Temporal.
Circle ci tests either not passing or stuck, can't tell easily on mobile. Otherwise looking good.

@sonarqubecloud
Copy link

@svonworl
Copy link
Contributor Author

svonworl commented Dec 17, 2025

I changed the "interval operations" code to use @js-temporal/polyfill. Overall, readability/understandability is a wash. There are some lamenesses in the Javascript Temporal API design (like not supporting the addition/subtraction of fractional amounts of duration units) that make the code less understandable than it would be otherwise. Type safety is improved. Given that the previous implementation was simple enough that we could have proved its correctness mathematically, reliability goes down. I am super-skeptical of date-time libraries in general, they are very difficult to implement and they don't always fail immediately (why hello there February 29). Hope this one doesn't cause any problems in the future. Would have been helpful to merge the non-Temporal version as a placeholder implementation, this PR includes some modifications that match the recent webservice TimeSeriesMetric changes that were necessary to get the UI to build. Without those merged, in some other upcoming UI PRs, I had to burn time/energy realizing, reimplementing, and mentally tracking them.

"lib": [
"es2017",
"dom"
"es2021",
Copy link
Contributor Author

@svonworl svonworl Dec 17, 2025

Choose a reason for hiding this comment

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

Includes some definitions needed by the Temporal polyfill.

@svonworl svonworl requested a review from denis-yuen December 17, 2025 23:18
@svonworl svonworl merged commit 53450c6 into develop Dec 18, 2025
17 of 20 checks passed
@svonworl svonworl deleted the feature/seab-7366/change-time-series-graph-in-versions-table branch December 18, 2025 17:48
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.

3 participants