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

fix(user): new function to compute unique days within hours. #16077

Merged

Conversation

kennethlumalicay
Copy link
Contributor

@kennethlumalicay kennethlumalicay commented Nov 3, 2017

Pre-Submission Checklist

  • Your pull request targets the staging branch of freeCodeCamp.
  • Branch starts with either fix/, feature/, or translate/ (e.g. fix/signin-issue)
  • You have only one commit (if not, squash them into one commit).
  • All new and existing tests pass the command npm test. Use git commit --amend to amend any fixes.

Type of Change

  • Small bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds new functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Add new translation (feature adding new translations)

Checklist:

  • Tested changes locally.
  • Addressed currently open issue (replace XXXXX with an issue no in next line)

Closes #7925

Description

Made a new function to prep unique days based on hours from the previous data instead of startOf day.

Then

  • Everything is turned into startOf('day') and then .uniq() to avoid duplicates. This method turns all timestamp's hours into 12am(?) of that day thus difference in days within timestamps can only be integers.

Now

  • Timestamps are sorted then reduced. If the data is over hoursDay(24) of the previous data it is pushed into the accumulator. This method keeps the hours of the timestamps.

  • Calculations uses hoursBetween(24) instead of daysBetween(1.5).

  • Calculations are done by taking 12am of the latest day and checks if the previous timestamp is within 24 hours.

  • Also changed default to EST.

Findings

heatmapfix

hoursBetween 24 is more accurate but despite being accurate it still has a leeway between timestamps as the timestamp's difference is calculated using the previous timestamp's 12am and the time of current timestamp and checks if it's within 24 hours.
e.g.
2017-11-02T23:00:00.000 and 2017-11-01T08:00:00.000 would still count as a streak despite being 39 hours apart because we check using 2017-11-02T00:00:00.000 and see if 2017-11-01T08:00:00.000 is still within 24 hours.

@QuincyLarson

PS: I didn't delete prepUniqueDays although it's not being used anymore. Also haven't made unit tests.

@camperbot
Copy link
Contributor

@kennethlumalicay updated the pull request.

@QuincyLarson
Copy link
Contributor

@kennethlumalicay Awesome! Thanks for making this pull request and documenting your reasoning behind these changes.

@BerkeleyTrue could you QA this and if it's ready, merge it?

@BerkeleyTrue
Copy link
Contributor

@kennethlumalicay this section is already well tested. Can you add tests for the new function you added in user-stats?

@BerkeleyTrue BerkeleyTrue self-requested a review November 7, 2017 21:32
@BerkeleyTrue BerkeleyTrue self-assigned this Nov 7, 2017
@BerkeleyTrue
Copy link
Contributor

BerkeleyTrue commented Nov 7, 2017

Also changed default to EST.

What is the bases of this change?

I didn't delete prepUniqueDays although it's not being used anymore. Also haven't made unit tests.

If it isn't being used please remove it and the associated tests

@kennethlumalicay
Copy link
Contributor Author

kennethlumalicay commented Nov 11, 2017

Hi, I'll work on this again when I get the time I've been quite busy with stuff so this would be on hold for now. :) If anyone wants to grab/remake the code and make a PR that's fine too. Thanks for understanding.

PS: The EST change was based on quincy saying we could just normalize the time to EST but I didn't do that so I just used it as default.

@QuincyLarson
Copy link
Contributor

@kennethlumalicay OK - this has been an open issue for some time and it feels like this is the closest anyone has come to fixing it. How soon would you have time to finish this PR up?

@kennethlumalicay
Copy link
Contributor Author

I should be able to work on this after thanksgiving.

@BerkeleyTrue
Copy link
Contributor

@kennethlumalicay thanks for the update. Let me know if you get stuck

@QuincyLarson
Copy link
Contributor

@kennethlumalicay Thanks for your continued help with this. We're excited to get this live, so let us know when it's ready for QA :)

@camperbot
Copy link
Contributor

@kennethlumalicay updated the pull request.

@kennethlumalicay kennethlumalicay force-pushed the fix/user-streak branch 2 times, most recently from d53ccea to 434f6ed Compare November 29, 2017 04:40
@camperbot
Copy link
Contributor

@kennethlumalicay updated the pull request.

@kennethlumalicay
Copy link
Contributor Author

@BerkeleyTrue Hi. I updated the PR and I'm getting conflicting files. Idk what it means or how to solve it. Thanks!

@QuincyLarson I just wanted to give back to the community and I chose the oldest issue with help wanted. Hope this works without any issue. :)

@BerkeleyTrue
Copy link
Contributor

@kennethlumalicay The lodash chaining is removed upstream of your commit so that babel-plugin-eslint can be used. You'll need to rewrite your function so that it does not use lodash chaining

see: https://medium.com/making-internets/why-using-chain-is-a-mistake-9bc1f80d51ba for some examples of this.

@camperbot
Copy link
Contributor

@kennethlumalicay updated the pull request.

@QuincyLarson
Copy link
Contributor

@kennethlumalicay Thanks for updating your PR. It looks like there are still merge conflicts. Could you resolve these, then let @BerkeleyTrue know when you're ready for him to take another look at your pull request?

@kennethlumalicay
Copy link
Contributor Author

@QuincyLarson what actions do I need to take to resolve the conflicting files? Seems like the user-stats.js changed since I forked the code, should I do pull --rebase on upstream or will I lose my commit if I do that?

I have already removed lodash chaining as @BerkeleyTrue said.

@BerkeleyTrue
Copy link
Contributor

@kennethlumalicay Yes you'll need to do a rebase.

Although daunting at first, being able to pull off a successful rebase will make you a much more powerful dev wizard.

First you'll need to check that your local copy of the staging branch is up to date
git checkout staging; git pull upstream staging

Once this is accomplished checkout this branch branch again (the branch with your changes) and then enter the rebase command:
git rebase staging

This will replay your commit on top of the lastest commits in staging. You should see a message stating that there are conflicts that must be resolved in order to complete the rebase. Open the file with the conflicts in your editor of choice. Edit the file and save. Add your new changes to staging (i.e. git add filename.ext) (Important! don't commit here!).

Once your are satisfied with your changes and have added them to staging enter the command git rebase --cont. This will amend your commit. After this you will need to force push up. That should resolve the conflicts on this PR.

@camperbot
Copy link
Contributor

@kennethlumalicay updated the pull request.

@kennethlumalicay
Copy link
Contributor Author

@BerkeleyTrue done. Thanks for the very detailed instruction! 👍

@BerkeleyTrue BerkeleyTrue merged commit 03f85af into freeCodeCamp:staging Dec 6, 2017
@BerkeleyTrue
Copy link
Contributor

✨ Nice work!!

@QuincyLarson
Copy link
Contributor

@kennethlumalicay I'm a bit late to the party, but I wanted to congratulate you as well. This should significantly reduce the corner cases where a campers' streak seems off. Thank you for helping improve this logic!

@kennethlumalicay
Copy link
Contributor Author

@QuincyLarson no problem, I'll check out more issues when I get the time. 👍

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

4 participants