9

How can I check the longest (not current) personal consecutive days streak?

I remember there was such a possibility, but I can't find it now.

1
  • As below (in case of post deletion): Nah, I know this counter exists but I'm looking for the longest streak. I remember somewhere on the site, I accidentally came across an information about my last lost many days after I'd lost it.
    – maciejwww
    Commented Mar 24, 2021 at 2:35

2 Answers 2

14

Sorry, I misunderstood your request at first. The necessary information can be retrieved from a URL like this: https://meta.stackexchange.com/users/daily-site-access/295232 where the last number is your user ID (found in the URL of your profile). That page looks empty, but if you check the source, you'll see that it defines a variable 'visited' which contains all dates you visited the site (the first level keys are 'year', next 'month', finally 'day'):

enter image description here

You could use that to write a script iterating over the object to tell you what your longest streak is and when it was. @ShadowWizard did it in the other answer; for other solutions, check upcoming answers to my first Code Golf challenge.

6
  • 3
    how did you even find that!? Commented Mar 24, 2021 at 7:28
  • 1
    @mindstormsboi Firefox developer tools (but other browsers have it too), Network tab
    – Glorfindel Mod
    Commented Mar 24, 2021 at 7:29
  • @Glorfindel New inforamtion to me, Is there any help or faq about the "/daily-site-access" URL?
    – Arulkumar
    Commented Mar 24, 2021 at 8:21
  • 2
    @Arulkumar it's likely just an internal API, there's no information: meta.stackexchange.com/search?q=url%3A%22daily-site-access%22
    – Glorfindel Mod
    Commented Mar 24, 2021 at 8:24
  • @Glorfindel Oh, got it. Thanks for sharing.
    – Arulkumar
    Commented Mar 24, 2021 at 8:25
  • Not a golfer, but that was a fair exercise for my rusty plain JS skills. ;-) Commented Mar 24, 2021 at 12:44
8

Following the advice in this answer, I've written a script that parse the results and showing the top one, i.e. the longest consecutive day streak. Just copy and paste the below script into the browser's console and run it, while in any page on SE site.

var showAll = false; //change to true in order to log the full list to console
function consecutiveData() {
    this.add = function(date) {
        this.consecutiveDaysCount++;
        if (this.firstDay == null) {
            this.firstDay = new Date(date);
        }
        this.lastDay = new Date(date);
    };
    this.toString = function() {
        return this.consecutiveDaysCount + " consecutive days between " + this.firstDay + " and " + this.lastDay;
    };
    this.consecutiveDaysCount = 0;
    this.firstDay = null;
    this.lastDay = null;
}
var userId = $(".my-profile").attr("href").split("/")[2];
var url = "/users/daily-site-access/" + userId;
console.log("Fetching daily site access for user " + userId + "...");
$.get(url, function(resp) {
    var lookFor = "var visited = ";
    var index1 = resp.indexOf(lookFor);
    var index2 = resp.indexOf("\n", index1);
    if (index1 < 0 || index2 < 0) {
        console.log("Failed to get proper data please visit " + url + " and check what went wrong.");
        return;
    }
    var rawJSON = resp.substr(index1 + lookFor.length, index2 - (index1 + lookFor.length + 1));
    var tmp = rawJSON.split(":");
    tmp.forEach((t, i) => {
        if (t.indexOf(",") >= 0 || t.indexOf("{") >= 0) {
            tmp[i] = t.replace(',', ',"').replace('{', '{"') + '"';
        }
    });
    var jsonWithQuotes = tmp.join(":").replace(";", "");
    var visited = JSON.parse(jsonWithQuotes);
    var firstYear = Object.keys(visited)[0];
    var firstMonth = Object.keys(visited[firstYear])[0];
    var firstDay = Object.keys(visited[firstYear][firstMonth])[0];
    var date = new Date(firstYear, firstMonth - 1, firstDay);
    console.log("Success! Checking activity since " + date);
    var now = new Date();
    var consecutiveDaysList = [];
    var consecutiveDaysBuffer = null;
    while (date < now) {
        var year = date.getFullYear();
        var month = date.getMonth();
        var day = date.getDate();
        if (visited[year] && visited[year][month + 1] && visited[year][month + 1][day]) {
            if (consecutiveDaysBuffer == null)
                consecutiveDaysBuffer = new consecutiveData();
            consecutiveDaysBuffer.add(date);
        } else {
            if (consecutiveDaysBuffer != null)
                consecutiveDaysList.push(consecutiveDaysBuffer);
            consecutiveDaysBuffer = null;
        }
        date.setDate(date.getDate() + 1);
    }
    if (consecutiveDaysBuffer != null)
        consecutiveDaysList.push(consecutiveDaysBuffer);
    consecutiveDaysList.sort((cd1, cd2) => cd2.consecutiveDaysCount - cd1.consecutiveDaysCount);
    var topResult = consecutiveDaysList[0];
    console.log("Top result: " + topResult.toString());
    if (showAll) {
        console.log("Full list of consecutive days:");
        console.log(consecutiveDaysList);
    }
});
16
  • JavaScript? What context does it run in? Greasemonkey? Commented Mar 24, 2021 at 14:34
  • @P.Mort.-forgotClayShirky_q no the context is the current page you're viewing in the browser, assuming you're using the browser's developer console. This can be made into userscript, I'm just not there yet. Commented Mar 24, 2021 at 14:57
  • 1
    I just used it and the result was... as expected: Top result: 4321 consecutive days between Thu May 28 2009 00:00:00 GMT+0200 (Central European Summer Time) and Fri Mar 26 2021 00:00:00 GMT+0100 (Central European Standard Time)
    – VonC
    Commented Mar 26, 2021 at 21:12
  • @VonC that's... very impressive. Well done! :) Commented Mar 27, 2021 at 11:44
  • Doesn't work for me. :/ Outputs "43 days", while the user profile says "1450 days". Commented Apr 4, 2021 at 19:50
  • @HolyBlackCat weird. Can you please change the first line to var showAll = true; and check where the glitch is? You can also copy and paste here the results and I'll have a look. Commented Apr 5, 2021 at 6:08
  • Not sure what's going on. Here's the log: pastebin.com/ahJLcz9G Commented Apr 5, 2021 at 7:33
  • 1
    @HolyBlackCat interesting, I'll take a closer look when having some time to debug. :) Commented Apr 5, 2021 at 7:41
  • @HolyBlackCat OK, think I figured it. The 1450 days you see is the total amount of days you visited, not consecutive. The consecutive count is shown later, e.g. for me it says "Visited 3597 days, 45 consecutive". You don't see any consecutive count because you don't have it yet, it doesn't show one day as being consecutive, so it's just saying the total amount of days. Commented Apr 5, 2021 at 8:06
  • 🤦 I didn't realize the count is per site, not global. 1450 days are on SO, not MSE. Tried to run the same script from a SO tab, go this: pastebin.com/C5uqB63T Commented Apr 5, 2021 at 8:12
  • @HolyBlackCat ohh... lol. So all good now? Commented Apr 5, 2021 at 8:15
  • @ShadowTheVaccinatedWizard Only that it errors out when ran on SO. Is it supposed to work on MSE only, or any SE site I have open when running it? Commented Apr 5, 2021 at 8:17
  • 1
    @HolyBlackCat oh wait... think you found a bug, when you didn't visit for whole month it will crash. Reproduced on small site I don't visit often, I'll fix and edit the answer. Thanks! Commented Apr 5, 2021 at 8:19
  • 1
    @HolyBlackCat bug fixed, try now. :) Commented Apr 5, 2021 at 8:28
  • 2
    @HolyBlackCat thank you, for being a loyal beta tester... ;) Commented Apr 5, 2021 at 8:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .