Skip to content
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

Stats: Pull minute data for Real-time Stats chart #99419

Open
wants to merge 10 commits into
base: trunk
Choose a base branch
from

Conversation

dognose24
Copy link
Contributor

@dognose24 dognose24 commented Feb 6, 2025

Related to https://github.com/Automattic/red-team/issues/335

Proposed Changes

  • Add RealtimeChart component to query hourly data and process views difference by minute for the line chart.

Why are these changes being made?

  • Pull real data for the Real-time Stats prototype.

Testing Instructions

截圖 2025-02-07 凌晨3 32 33
  • Spin this change up with the Calypso Live branch.
  • Navigate to Stats > Realtime tab with the feature flag stats/real-time-tab for a high-traffic site.
  • Ensure the real-time page views chart is displayed with at most five data series and update every five seconds.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@dognose24 dognose24 requested a review from kangzj February 6, 2025 16:19
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 6, 2025
@dognose24 dognose24 requested a review from a team February 6, 2025 16:19
@dognose24 dognose24 self-assigned this Feb 6, 2025
@dognose24 dognose24 added the [Feature] Stats Everything related to our analytics product at /stats/ label Feb 6, 2025
@matticbot
Copy link
Contributor

matticbot commented Feb 6, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug updat/stats_realtime_pull_minute_data on your sandbox.

@matticbot
Copy link
Contributor

matticbot commented Feb 6, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Async-loaded Components (~298 bytes added 📈 [gzipped])

name                                                     parsed_size            gzip_size
async-load-calypso-my-sites-stats-pages-realtime             +1073 B  (+11.2%)     +467 B  (+14.9%)
async-load-calypso-my-sites-stats-components-line-chart       -333 B   (-0.1%)     -169 B   (-0.2%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@dognose24 dognose24 marked this pull request as ready for review February 6, 2025 20:03
useEffect( () => {
const intervalId = setInterval( () => {
// Index the chart data by YYYY-MM-DD HH:mm:00.
const adjustedDatetime = moment().utcOffset( gmtOffset ).format( 'YYYY-MM-DD HH:mm:00' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we able to reuse momentSiteZone here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried it, but the current hour might not be accurate inside the setInterval callback. I will test again if this approach works for minutes across the hour.

<div>
<AsyncLoad
require="calypso/my-sites/stats/components/line-chart"
height={ 425 }
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to the PR - the height is a little too much on mobile, so maybe we should do responsive for mobiles? 🤔

require="calypso/my-sites/stats/components/line-chart"
height={ 425 }
placeholder={ PageLoading }
chartData={ [ { label: 'Views', options: { stroke: '#069e08' }, data: chartData } ] }
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to the PR - Let's not forget Odyssey has a different set of colors.

}
// TODO: Change to 60 for production.
const UPDATE_INTERVAL_IN_SECONDS = 5;
// TODO: Change to 30 after resolving the date format issue on the X-axis.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please share more about the issue?

Copy link
Contributor Author

@dognose24 dognose24 Feb 7, 2025

Choose a reason for hiding this comment

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

The series data passed to the line chart requires a date attribute, which only accepts date objects. In this case, the tickFormat callback would also need to support simple strings, such as -10m.

Another issue is that I assumed the chart's X-axis automatically combines labels from single minutes to about the unexpected 5 or 10 minutes if they are too crowded. However, this feature seems reasonable and might be addressed if the one above is supported.

截圖 2025-02-07 上午11 09 13

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the annotation to a626e61.

return () => clearInterval( intervalId );
}, [ siteId, gmtOffset ] );

let chartData = Object.keys( viewsData ).map( ( eachMinute ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably memo this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 2c0fff9.

Copy link
Contributor

@kangzj kangzj left a comment

Choose a reason for hiding this comment

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

Looks great to me! Left a couple of comments but no blocker.

It'll be great to have @annacmc to take a look as well 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Stats Everything related to our analytics product at /stats/ [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants