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

Streak is still inaccurate for many campers #7925

Closed
QuincyLarson opened this issue Apr 6, 2016 · 39 comments
Closed

Streak is still inaccurate for many campers #7925

QuincyLarson opened this issue Apr 6, 2016 · 39 comments
Labels
help wanted Open for all. You do not need permission to work on these. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.

Comments

@QuincyLarson
Copy link
Contributor

One of the most common complaints I get (as person in charge of support emails) is that the streak isn't accurate. This may be due to timezones.

We probably need to go ahead and write some test cases and really tighten up this code. Any volunteers?

@QuincyLarson QuincyLarson added the help wanted Open for all. You do not need permission to work on these. label Apr 6, 2016
@Andychochocho
Copy link

My first time with open source contributions, but I'd love to see if I'm up for the task.

@QuincyLarson
Copy link
Contributor Author

This is still an issue that we get a lot of complaints about.

@sorlovsky
Copy link

@QuincyLarson I am interested in helping out

@QuincyLarson
Copy link
Contributor Author

@sorlovsky Awesome! We're interested in your help! See whether you can write some tests around this that cover various edge cases. It seems to work 99.9% of the time, but there are some situations where it doesn't and I'm not quite sure why.

@donofriov
Copy link
Contributor

I looked into this a bit and it may possibly caused by the fact that it is counting current streaks of Challenges and not the other activities (Projects or Algorithms). It's also possible that it's timezones as stated above. I'm going to look into the issue and see if I can PR if no one else get's to it.

@donofriov
Copy link
Contributor

donofriov commented Feb 22, 2017

Can someone please let me know if I'm missing something here.

const daysBetween = 1.5; can be updated to const daysBetween = 2; because the logic in the following functions always says less than daysBetween and not less than or equal to daysBetween. This means there will be coverage from 12:00:00AM one day all the way to 11:59:59PM the next. The timezone logic should all stay the same as well.

Changing daysBetween to 2 means that two tests break, which can be fixed but I'd have to learn a little bit how the tests work first.

The alternative option would be to set daysBetween to 1.99 so all tests pass, but you would have a possibility of missing the streak by 7 mins and 12 seconds.

@sorlovsky
Copy link

@donofriov please go for it I was not able to figure why it didn't work

@raisedadead
Copy link
Member

@donofriov thanks a lot for the analysis, and great to hear that you are interested to look into this. Here is another related issue #7468 (has to do with log in state of the user)

If you need any assistance hit us up on the chat room.

I'd have to learn a little bit how the tests work first.

The tests are at
https://github.com/freeCodeCamp/freeCodeCamp/blob/staging/server/utils/user-stats.test.js

Well this is a bit complicated structuring than usual. I'll be around if you need figuring out things.

Happy fixing!

@QuincyLarson
Copy link
Contributor Author

@donofriov Yes - if you think that will fix it, great. Bump daysBetween to 2 and update the tests so they will pass.

If you're able to, please see if you can add some additional test coverage to make sure this is addressing the various corner cases that have cropped up (there are several issues related to streaks).

Thank you for your time and attention to this. This has been a major issue for months and is a source of many complaints, so fixing this will be huge :)

@Motardo
Copy link

Motardo commented Sep 2, 2017

The problem is that the calculation of a streak is dependent on the timezone. In one timezone, say my three submissions are [Aug 5, Aug 6, Aug 7]. In another timezone, those same submissions might be on [Aug 5, Aug 5, Aug 6]. The calendar heatmap is likewise dependent on the timezone, and the heatmap always uses the timezone of the client viewing the page in the browser. So if we want the streaks to match the heatmap, we need to use the client's timezone in the calculation. That is basically what @LenaBarinova did when this issue was fixed back in January 2016 with #6333. The solution was to have the browser send the user's timezone whenever a challenge was submitted. The server would store the timezone and use it to calculate the streaks. But then in January 2017, there was a big refactoring that changed how challenges are submitted, and the fix got removed. The server side logic is still there, it's just the browser isn't sending the timezone anymore.

@QuincyLarson QuincyLarson reopened this Sep 2, 2017
@QuincyLarson QuincyLarson added the status: on the roadmap Long term plans and features. label Sep 2, 2017
@QuincyLarson
Copy link
Contributor Author

@Motardo Thanks for investigating this. Would you be interested in and fixing this to get @LenaBarinova's fix working again?

@Motardo
Copy link

Motardo commented Sep 2, 2017

@QuincyLarson After having another look and sleeping on it, here are my thoughts:

Plan A
I think that the old solution was not ideal. It required a user to be logged in to view their own profile correctly and would still show inconsistencies when viewing other users profiles in other timezones.

Plan B (simple and straightforward, good temporary fix)
I believe that a simpler and more robust solution is to send the clients timezone with any request to view any user's profile, and the server could calculate the streaks based on that timezone. Then it wouldn't matter if the client was logged in, or whose profile was viewed. The streaks and the calendar would always be in sync.

Plan C (complicated refactor, possible future roadmap)
Probably the best solution would be to not calculate streaks on the server at all. The server should send the raw timestamps to the client and let the client decide which day each timestamp belongs to and how long the streaks are based on the local timezone. This is exactly what we do with the calendar heatmap data so it would always be consistent.

I am completely new to react and rxjs, and I think Plan C is out of my depth, but I would be happy to make a patch for Plan B, and I would love to hear other ideas and suggestions.

@QuincyLarson
Copy link
Contributor Author

@Motardo I definitely agree that Plan C makes the most sense.

Given that it's been 15 days since you posted this, have you improved much with React and RXJS? This might be a good challenge to push the limits of your client side scripting abilities to the next level 😉

@kennethlumalicay
Copy link
Contributor

kennethlumalicay commented Nov 1, 2017

Hi. I just submitted a PR with possible fix. #16071

What I did:
I first changed the streak calculation to use 24 hoursBetween instead of 1.5 daysBetween. Then I took the difference in hours of startOf('day') of the previous timestamp and current timestamp and compared it to hoursBetween to account for works that has been done the past 24 hours instead of the past day. (Sounds the same but probably worth a try)

Probably a better fix would be is if you allow the user to set their own timezone in settings and everything is calculated/set using that timezone.

Edit: Does anyone know how to use/produce dummy accounts in localhost that has different sets of streaks?

Edit: Nevermind all these.

@ApeCogs
Copy link

ApeCogs commented Jan 22, 2018

Hi, I'm writing because I saw @QuincyLarson comment on this post.

I'm a new camper and I have a "5 day streak" going on with activities recognized on:
Jan18 - 5 items
Jan19 - 24 items
Jan20 - 16 items
Jan21 - 2 items
Jan22 - 7 items
fcc

I see from reading above there is an expectation the "calendar completed" dates to be offset, but my streak shows only 1 day.

===
Side note - thanks for the awesome work. This is my 5th attempt at learning to code but I think this program is the one that will get me through the hump !

@QuincyLarson
Copy link
Contributor Author

@kennethlumalicay Please take a look at this. Any idea what might be causing @ApeCogs's issue?

@kennethlumalicay
Copy link
Contributor

@ApeCogs do you know the time you did each challenge on jan 21 and 22?(even rough estimates) What is your timezone? Also do you use VPN?

@ApeCogs
Copy link

ApeCogs commented Jan 23, 2018

@kennethlumalicay - Jan 21st would have been around 22:30 - 23:30 EST. Jan 22nd would have been 09:00 - 10:00 EST. I do use a VPN sometimes but it's for work and the region don't change (eastern).

@mriel
Copy link

mriel commented Jan 25, 2018

I'm having the problem. It usually happens when I do a challenge around 22:00 CST - 24:00 CST. Though I have lost my streak when I have done it on Sunday around 19:00 CST - 20:00 CST. This would also usually happen when I am around a 7 -8 day streak. Not using a VPN. If there is anything I can do more to help please let me know.

screenshot-2018-1-24 learn to code with free online courses programming projects and interview preparation for developer

@kennethlumalicay
Copy link
Contributor

kennethlumalicay commented Jan 25, 2018

@ApeCogs I used some dummy data but I can't seem to reproduce it.

timestamps:

Wed Jan 24 2018 22:30:00 GMT-0500 (Eastern Standard Time)
Wed Jan 24 2018 23:30:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:05:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:12:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:20:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:30:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:39:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:40:00 GMT-0500 (Eastern Standard Time)
Thu Jan 25 2018 09:43:00 GMT-0500 (Eastern Standard Time)

I used 24 and 25 instead of 21 and 22 to recreate your "today" and "yesterday".

result:

ape

@mriel you lost your current streak too? Could you provide a larger screenshot containing the heatmap and streaks?

@raisedadead
Copy link
Member

Re-opening, because of ongoing discussion

@raisedadead raisedadead reopened this Jan 25, 2018
@mriel
Copy link

mriel commented Jan 25, 2018

@kennethlumalicay here is a my screenshot:

screenshot-2018-1-25 learn to code with free online courses programming projects and interview preparation for developer

Most of the time my previous streaks have been 7-8 days. The next day I will do one lesson at night between 18:00 CST - 22:00 CST. The day after it will say my current streak is 1 day.

I have started to keep a log of current streak, day, time, and what challenge.

@kennethlumalicay
Copy link
Contributor

kennethlumalicay commented Jan 25, 2018

In here it says you did something on 20.
mriel

But in here there's nothing on 20.
mriel-2

So I'm assuming your timestamps are being displayed with the wrong timezone.

    // timezone of signed-in account
    // to show all date related components
    // using signed-in account's timezone
    // not of the profile she is viewing
    const timezone = user && user.timezone ?
      user.timezone :
      'EST';

So if you're not signed in, user would be null and timezone would be 'EST'.
Even if you're signed in I'm not really sure if user.timezone actually exist because it doesn't exist on the dummy data on my local db. Idk if fcc's db is different but since you're still getting the wrong timezone then you're still probably getting 'EST'.
I'm assuming this always goes to 'EST' by default.

So I submitted a possible fix by changing 'EST' to moment.tz.guess().

@mriel
Copy link

mriel commented Jan 26, 2018

I just did a challenge. This is what my status is:
01/25/2018 20:41 PM CST Reverse Arrays with .reverse
screen shot 2018-01-25 at 8 46 08 pm
screen shot 2018-01-25 at 8 44 21 pm

@sgrayme
Copy link

sgrayme commented Jan 30, 2018

I observed how challenges are recorded during the last week and basically saw challenge dates and streak are going by UTC and the heatmap is using EST. This means I and other people in CST need to do challenges before 6pm to be counted for the same day on all the parts. And if I do challenges in the morning one day and in the evening on the next, goodbye streak.

Just a thought, the language learning programs I use have an hours left countdown visible next to the streak information. Having a note saying "complete lessons by... to maintain streak." would be just as useful. I'd call getting consistent times the first priority for the streak problem, but letting people know their deadline for the day would be more useful than worrying about adjusting TZ for travel or allowing grace hours (as nice as those things sound).

@raisedadead raisedadead added type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc. and removed status: on the roadmap Long term plans and features. labels Jan 30, 2018
@dardandemiri
Copy link

A bug that makes the amazing 100DaysOfCode Challange useless

Here is my profile: https://www.freecodecamp.org/dardandmr

My 69 Days of Streak is broken for no reason

@QuincyLarson please bro, what is this, and can we reverse this?!
I have submitted the work two hours after 24:00, I don't think that it is a Time zone error, even if it is how is it possible that so many people here in FCC have not fixed this error?
image

I am really disappointed, I was so motivated with this 100DaysOfCode Challange, and I have finished all the Front-End Projects and everything else, I have only 4 Advanced Algorithms to solve to claim my Front End Certificate, stayed so many hours without sleep just to keep the streak going...

Screenshot

image
image

@JohnnyCheung1989
Copy link

JohnnyCheung1989 commented Apr 16, 2018

100DaysOfCode Challange , if such bug persists , it would just ruin us in morale.

@dardandemiri
Copy link

@JohnnyCheung1989 look at my progress since the bug ruined my streak :(
image

@nathan005
Copy link

It seems the video challenges are not counted toward streaks either, but are counted in heat map.

@dverdin83
Copy link

dverdin83 commented May 19, 2018

I'm a beginner especially with production code. Do not know if this algo would create too much overhead... But since heatmap seems to be working fine why can't the algo for streak just check the heatmap for days colored green or go the other way and check for grey gaps and return a value like check if element is '#cccc' etc.. if yes break streak
Remove all the current streak logic timezone and math all together and just check the heatmap in some way for color in element...
If ! grey streak++ if grey stop streak then check if streak longer than longest streak?

Forgive me if this has been brought up before.

I've never seen the heatmap inaccurate but my streaks are well... not so much.

Or someway put a flag in the heatmap code and streak outputs cant check it and update?

@nathan005
Copy link

@dverdin83
I just briefly looked at the code. Heatmap is a plugin, so editing the heatmap code should not be done as it will break if updated. As for counting the green, it seems the plugin builds the color on the fly, so you would need to add a callback to delay the calculating.

It would be better to check the same thing as the heatmap does, that is what was suggested by Motardo (see his comment on Sep 2, 2017 - Plan C).

@QuincyLarson
Copy link
Contributor Author

Closing this issue in favor of #17299

@drecali
Copy link
Contributor

drecali commented Dec 7, 2018

Does anyone know which timezone is used by the streak counter and the heatmap? I just lost a 74 day streak even though I finished a challenge by 15:45PM KST (UTC +0900). The streak shows only 1 day but today's square on the heatmap is colored green, and on the timeline the challenge is recorded as being completed today as well. It seems like the streak counter is using one timezone, while the heatmap and timeline are using a second timezone. Can someone please confirm? It's really demoralizing as I was taking pride in watching the number grow every day and being able to share it with friends, family, and potential employers.

I understand that it may not be a high priority to fix, so at least knowing the rules of the streak would really help me understand and adjust my coding accordingly.

Quoted from @sgrayme #7925 (comment)

I observed how challenges are recorded during the last week and basically saw challenge dates and streak are going by UTC and the heatmap is using EST...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Open for all. You do not need permission to work on these. type: bug Issues that need priority attention. Platform, Curriculum tests (if broken completely), etc.
Projects
None yet
Development

No branches or pull requests