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

Subtract idle time from time spent #43018

Merged
merged 7 commits into from
Oct 25, 2021

Conversation

maureensturgeon
Copy link
Contributor

@maureensturgeon maureensturgeon commented Oct 15, 2021

Added react-idle-timer component to StudioAppWrapper to be included on Studio Apps. The timer will track time spent idle, idle time will start tracking after 2 minutes of the user being idle. Idle time will then be set to studioAppActivity redux where it can be read by StudioApp.js. In StudioApp.js when time spent is recorded, we will subtract the idle time since the last milestone has posted.

Links

Testing story

I tested locally that the time spent idle is being recorded correctly and that the time_spent set on the user_level seemed right. I also added some unit tests. If anyone has ideas for additional tests, I'm open to ideas.

PR Checklist:

  • Tests provide adequate coverage
  • Privacy and Security impacts have been assessed
  • Code is well-commented
  • New features are translatable or updates will not break translations
  • Relevant documentation has been added or updated
  • User impact is well-understood and desirable
  • Pull Request is labeled appropriately
  • Follow-up work items (including potential tech debt) are tracked and linked

@maureensturgeon maureensturgeon marked this pull request as ready for review October 16, 2021 00:15
@maureensturgeon maureensturgeon requested a review from a team October 16, 2021 00:15
Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

Nice improvement, I think this will really help with the quality of our time spent data.

@@ -183,6 +183,13 @@ class StudioApp extends EventEmitter {
*/
this.milestoneStartTime = undefined;

/**
* The amount of idle time when the last milestone was recorded. Used for
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe indicate the units here?

@@ -0,0 +1,20 @@
const SET_IDLE_TIME = 'instructions/SET_IDLE_TIME';
Copy link
Contributor

Choose a reason for hiding this comment

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

What does instructions here refer to? (Also on lines 3 and 7 below.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a copy-pasta error, thanks for catching that!

if (this.state.idleStart) {
const now = new Date().getTime();
const timeSpentIdle = now - this.state.idleStart;
this.props.setIdleTime(this.props.totalIdleTime + timeSpentIdle);
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if a user goes back and forth between idle and active several times within a session? Should we reset this.state.idleStart here?

Copy link
Contributor

Choose a reason for hiding this comment

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

(minor) I wonder if it would be a bit clearer if the redux action was addIdleTime? If that's the case, I don't think this component needs to know about totalIdleTime at all.

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 was going back and forth about how much of this should live in redux. I think that'd be a good way to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For your first question, idleStart is set in onIdle

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see. I might still reset this.state.idleStart here as a defensive measure but up to you.

timeout={IDLE_AFTER}
onIdle={this.onIdle}
onActive={this.onActive}
debounce={250}
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we didn't pass an onAction callback, do we need to pass a debounce value?

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 misread the docs and thought this was for onActive, good catch.

this.setState({idleStart: new Date().getTime()});
};

onActive = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we only record idle time when we return to being active. Do we need to worry about a scenario where onActive() isn't called / gets called too late?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. I think I decided this was unlikely. The user will hit run for a milestone to be posted and the click action triggers onActive. This may be an issue if the user hovers over run and then is idle and then a while later clicks. Or is it possible that we'll record milestones on idle after some period of time (maybe on a channel-backed level)?

I can play around with some scenarios a bit more and see if there's an issue.

@@ -1738,6 +1752,8 @@ StudioApp.prototype.report = function(options) {
// otherwise if we don't leave the page we are compounding the total time
this.milestoneStartTime = currentTime;

this.milestoneStartTotalIdleTime = totalIdleTime;
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor) Wondering if it's easier to dispatch an action here that resets idleTimeMs and not have to track idleTimeSinceLastMilestone. Up to you.

Copy link
Contributor Author

@maureensturgeon maureensturgeon left a comment

Choose a reason for hiding this comment

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

@jamescodeorg I've made some changes to move all of the idle calculations into redux and just expose the amount of idle time since the last report. Let me know if this is more clear

Copy link
Contributor

@jamescodeorg jamescodeorg left a comment

Choose a reason for hiding this comment

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

I think this is clearer, thanks!

@maureensturgeon maureensturgeon merged commit 06289f2 into staging Oct 25, 2021
@maureensturgeon maureensturgeon deleted the maureen/LP-1954-time-spent-idle branch October 25, 2021 22:34
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.

None yet

2 participants