7

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 Mar 24 at 2:35
12

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
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? – P.Mort. - forgot Clay Shirky_q Mar 24 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. – Shadow Wizard Wearing Mask V2 Mar 24 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 Mar 26 at 21:12
  • @VonC that's... very impressive. Well done! :) – Shadow Wizard Wearing Mask V2 Mar 27 at 11:44
  • Doesn't work for me. :/ Outputs "43 days", while the user profile says "1450 days". – HolyBlackCat Apr 4 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. – Shadow Wizard Wearing Mask V2 Apr 5 at 6:08
  • Not sure what's going on. Here's the log: pastebin.com/ahJLcz9G – HolyBlackCat Apr 5 at 7:33
  • 1
    @HolyBlackCat interesting, I'll take a closer look when having some time to debug. :) – Shadow Wizard Wearing Mask V2 Apr 5 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. – Shadow Wizard Wearing Mask V2 Apr 5 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 – HolyBlackCat Apr 5 at 8:12
  • @HolyBlackCat ohh... lol. So all good now? – Shadow Wizard Wearing Mask V2 Apr 5 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? – HolyBlackCat Apr 5 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! – Shadow Wizard Wearing Mask V2 Apr 5 at 8:19
  • 1
    @HolyBlackCat bug fixed, try now. :) – Shadow Wizard Wearing Mask V2 Apr 5 at 8:28
  • 2
    @HolyBlackCat thank you, for being a loyal beta tester... ;) – Shadow Wizard Wearing Mask V2 Apr 5 at 8:46

You must log in to answer this question.

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