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.
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.
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'):
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.
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);
}
});
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