Skip to content

Instantly share code, notes, and snippets.

@lukekarrys
Created October 5, 2017 19:27
Show Gist options
  • Save lukekarrys/1d2000b679115631ae9a5b72586d287d to your computer and use it in GitHub Desktop.
Save lukekarrys/1d2000b679115631ae9a5b72586d287d to your computer and use it in GitHub Desktop.
Get percentage of each day of the week with commits from graph.
javascript:(()=>{const e=["Sun","Mon","Tues","Wed","Thur","Fri","Sat"],r=[...document.querySelectorAll(".js-calendar-graph-svg > g > g")].reduce((e,r)=>[...r.querySelectorAll("rect.day")].reduce((e,r,t)=>(e[t][0]+="0"===r.getAttribute("data-count")?0:1,e[t][1]+=1,e),e),e.map(()=>[0,0])).reduce((r,t,c)=>(r[e[c]]=+(t[0]/t[1]*100).toFixed(3),r),{});console.log(r)})();
(() => {
const days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thur', 'Fri', 'Sat']
const res = [...document.querySelectorAll('.js-calendar-graph-svg > g > g')].reduce((acc, week) => {
return [...week.querySelectorAll('rect.day')].reduce((acc, day, index) => {
acc[index][0] += day.getAttribute('data-count') === "0" ? 0 : 1;
acc[index][1] += 1;
return acc
}, acc)
}, days.map(() => [0, 0])).reduce((acc, day, index) => {
acc[days[index]] = +((day[0] / day[1] * 100).toFixed(3))
return acc
}, {})
console.log(res)
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment