Skip to content

Instantly share code, notes, and snippets.

@danieluhm2004
Created February 25, 2020 16:14
Show Gist options
  • Save danieluhm2004/9f71b447bcc9964d66b6dc221cbc851c to your computer and use it in GitHub Desktop.
Save danieluhm2004/9f71b447bcc9964d66b6dc221cbc851c to your computer and use it in GitHub Desktop.
github-contributions-ranking
console.time();
// data is example source.
const data = {
data: {
'2019': {
'2': { '24': 0, '25': 1, '26': 0, '27': 0, '28': 0 },
'3': {
'1': 0,
'2': 0,
'3': 1,
'4': 0,
'5': 0,
'6': 0,
'7': 0,
'8': 0,
'9': 5,
'10': 6,
'11': 0,
'12': 7,
'13': 0,
'14': 0,
'15': 0,
'16': 0,
'17': 2,
'18': 0,
'19': 0,
'20': 0,
'21': 0,
'22': 0,
'23': 0,
'24': 0,
'25': 0,
'26': 0,
'27': 1,
'28': 5,
'29': 4,
'30': 10,
'31': 1,
},
'4': {
'1': 4,
'2': 0,
'3': 6,
'4': 7,
'5': 0,
'6': 0,
'7': 0,
'8': 0,
'9': 0,
'10': 1,
'11': 1,
'12': 0,
'13': 0,
'14': 3,
'15': 0,
'16': 1,
'17': 4,
'18': 0,
'19': 2,
'20': 0,
'21': 0,
'22': 0,
'23': 0,
'24': 0,
'25': 0,
'26': 0,
'27': 0,
'28': 0,
'29': 0,
'30': 0,
},
'5': {
'1': 0,
'2': 0,
'3': 1,
'4': 2,
'5': 1,
'6': 0,
'7': 0,
'8': 5,
'9': 3,
'10': 3,
'11': 3,
'12': 0,
'13': 0,
'14': 0,
'15': 0,
'16': 0,
'17': 0,
'18': 9,
'19': 39,
'20': 13,
'21': 0,
'22': 0,
'23': 0,
'24': 0,
'25': 4,
'26': 3,
'27': 6,
'28': 2,
'29': 0,
'30': 0,
'31': 0,
},
'6': {
'1': 0,
'2': 0,
'3': 0,
'4': 1,
'5': 0,
'6': 1,
'7': 0,
'8': 5,
'9': 6,
'10': 0,
'11': 0,
'12': 0,
'13': 0,
'14': 1,
'15': 2,
'16': 7,
'17': 0,
'18': 0,
'19': 0,
'20': 0,
'21': 0,
'22': 0,
'23': 0,
'24': 1,
'25': 0,
'26': 1,
'27': 2,
'28': 1,
'29': 3,
'30': 12,
},
'7': {
'1': 0,
'2': 0,
'3': 3,
'4': 0,
'5': 3,
'6': 2,
'7': 0,
'8': 0,
'9': 2,
'10': 0,
'11': 0,
'12': 0,
'13': 0,
'14': 2,
'15': 2,
'16': 2,
'17': 5,
'18': 0,
'19': 0,
'20': 0,
'21': 0,
'22': 1,
'23': 0,
'24': 0,
'25': 3,
'26': 3,
'27': 0,
'28': 0,
'29': 6,
'30': 0,
'31': 14,
},
'8': {
'1': 0,
'2': 0,
'3': 0,
'4': 6,
'5': 1,
'6': 4,
'7': 2,
'8': 2,
'9': 9,
'10': 10,
'11': 1,
'12': 1,
'13': 0,
'14': 0,
'15': 0,
'16': 2,
'17': 0,
'18': 0,
'19': 0,
'20': 7,
'21': 4,
'22': 0,
'23': 0,
'24': 0,
'25': 0,
'26': 0,
'27': 0,
'28': 5,
'29': 12,
'30': 6,
'31': 0,
},
'9': {
'1': 0,
'2': 1,
'3': 0,
'4': 0,
'5': 5,
'6': 0,
'7': 1,
'8': 3,
'9': 0,
'10': 0,
'11': 0,
'12': 1,
'13': 5,
'14': 1,
'15': 1,
'16': 1,
'17': 0,
'18': 2,
'19': 0,
'20': 1,
'21': 0,
'22': 1,
'23': 0,
'24': 2,
'25': 13,
'26': 20,
'27': 0,
'28': 5,
'29': 0,
'30': 0,
},
'10': {
'1': 0,
'2': 3,
'3': 0,
'4': 0,
'5': 1,
'6': 0,
'7': 0,
'8': 0,
'9': 0,
'10': 0,
'11': 0,
'12': 0,
'13': 0,
'14': 0,
'15': 0,
'16': 0,
'17': 0,
'18': 0,
'19': 0,
'20': 0,
'21': 0,
'22': 0,
'23': 0,
'24': 0,
'25': 0,
'26': 0,
'27': 0,
'28': 4,
'29': 0,
'30': 0,
'31': 0,
},
'11': {
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0,
'6': 0,
'7': 0,
'8': 0,
'9': 0,
'10': 3,
'11': 4,
'12': 2,
'13': 0,
'14': 0,
'15': 10,
'16': 0,
'17': 0,
'18': 0,
'19': 0,
'20': 3,
'21': 0,
'22': 7,
'23': 1,
'24': 0,
'25': 0,
'26': 0,
'27': 1,
'28': 2,
'29': 0,
'30': 0,
},
'12': {
'1': 1,
'2': 0,
'3': 0,
'4': 0,
'5': 1,
'6': 3,
'7': 11,
'8': 1,
'9': 0,
'10': 1,
'11': 12,
'12': 1,
'13': 0,
'14': 0,
'15': 1,
'16': 0,
'17': 0,
'18': 3,
'19': 0,
'20': 1,
'21': 2,
'22': 1,
'23': 0,
'24': 0,
'25': 0,
'26': 0,
'27': 2,
'28': 0,
'29': 0,
'30': 0,
'31': 1,
},
},
'2020': {
'1': {
'1': 3,
'2': 5,
'3': 1,
'4': 2,
'5': 4,
'6': 5,
'7': 1,
'8': 2,
'9': 7,
'10': 2,
'11': 0,
'12': 1,
'13': 1,
'14': 9,
'15': 3,
'16': 2,
'17': 1,
'18': 4,
'19': 2,
'20': 2,
'21': 1,
'22': 1,
'23': 1,
'24': 8,
'25': 18,
'26': 2,
'27': 2,
'28': 4,
'29': 1,
'30': 1,
'31': 3,
},
'2': {
'1': 3,
'2': 1,
'3': 1,
'4': 3,
'5': 1,
'6': 2,
'7': 1,
'8': 1,
'9': 2,
'10': 2,
'11': 1,
'12': 1,
'13': 2,
'14': 1,
'15': 2,
'16': 4,
'17': 0,
'18': 0,
'19': 2,
'20': 1,
'21': 1,
'22': 0,
'23': 0,
'24': 1,
'25': 0,
},
},
},
};
const ranking = [];
let tmpCount = 0;
let tmpStart = null;
for (const y of Object.keys(data.data)) {
const year = data.data[y];
for (const m of Object.keys(year)) {
const month = year[m];
for (const d of Object.keys(month)) {
const day = month[d];
const display = `${y}/${m}/${d}`;
if (day > 0) {
if (tmpCount++ === 0) {
tmpStart = display;
}
} else {
if (tmpCount > 0) {
ranking.push({
count: tmpCount,
start: tmpStart,
end: display,
});
tmpCount = 0;
tmpStart = null;
}
}
}
}
}
ranking.sort((a, b) => b.count - a.count);
console.timeEnd();
console.log(ranking);
@danieluhm2004
Copy link
Author

Example Result:

default: 1.116ms
[
  { count: 36, start: '2020/1/12', end: '2020/2/17' },
  { count: 11, start: '2019/12/31', end: '2020/1/11' },
  { count: 9, start: '2019/8/4', end: '2019/8/13' },
  { count: 6, start: '2019/3/27', end: '2019/4/2' },
  { count: 5, start: '2019/6/26', end: '2019/7/1' },
  { count: 5, start: '2019/9/12', end: '2019/9/17' },
  { count: 4, start: '2019/5/8', end: '2019/5/12' },
  { count: 4, start: '2019/5/25', end: '2019/5/29' },
  { count: 4, start: '2019/7/14', end: '2019/7/18' },
  { count: 4, start: '2019/12/5', end: '2019/12/9' },
  { count: 3, start: '2019/5/3', end: '2019/5/6' },
  { count: 3, start: '2019/5/18', end: '2019/5/21' },
  { count: 3, start: '2019/6/14', end: '2019/6/17' },
  { count: 3, start: '2019/8/28', end: '2019/8/31' },
  { count: 3, start: '2019/9/24', end: '2019/9/27' },
  { count: 3, start: '2019/11/10', end: '2019/11/13' },
  { count: 3, start: '2019/12/10', end: '2019/12/13' },
  { count: 3, start: '2019/12/20', end: '2019/12/23' },
  { count: 3, start: '2020/2/19', end: '2020/2/22' },
  { count: 2, start: '2019/3/9', end: '2019/3/11' },
  { count: 2, start: '2019/4/3', end: '2019/4/5' },
  { count: 2, start: '2019/4/10', end: '2019/4/12' },
  { count: 2, start: '2019/4/16', end: '2019/4/18' },
  { count: 2, start: '2019/6/8', end: '2019/6/10' },
  { count: 2, start: '2019/7/5', end: '2019/7/7' },
  { count: 2, start: '2019/7/25', end: '2019/7/27' },
  { count: 2, start: '2019/8/20', end: '2019/8/22' },
  { count: 2, start: '2019/9/7', end: '2019/9/9' },
  { count: 2, start: '2019/11/22', end: '2019/11/24' },
  { count: 2, start: '2019/11/27', end: '2019/11/29' },
  { count: 1, start: '2019/2/25', end: '2019/2/26' },
  { count: 1, start: '2019/3/3', end: '2019/3/4' },
  { count: 1, start: '2019/3/12', end: '2019/3/13' },
  { count: 1, start: '2019/3/17', end: '2019/3/18' },
  { count: 1, start: '2019/4/14', end: '2019/4/15' },
  { count: 1, start: '2019/4/19', end: '2019/4/20' },
  { count: 1, start: '2019/6/4', end: '2019/6/5' },
  { count: 1, start: '2019/6/6', end: '2019/6/7' },
  { count: 1, start: '2019/6/24', end: '2019/6/25' },
  { count: 1, start: '2019/7/3', end: '2019/7/4' },
  { count: 1, start: '2019/7/9', end: '2019/7/10' },
  { count: 1, start: '2019/7/22', end: '2019/7/23' },
  { count: 1, start: '2019/7/29', end: '2019/7/30' },
  { count: 1, start: '2019/7/31', end: '2019/8/1' },
  { count: 1, start: '2019/8/16', end: '2019/8/17' },
  { count: 1, start: '2019/9/2', end: '2019/9/3' },
  { count: 1, start: '2019/9/5', end: '2019/9/6' },
  { count: 1, start: '2019/9/18', end: '2019/9/19' },
  { count: 1, start: '2019/9/20', end: '2019/9/21' },
  { count: 1, start: '2019/9/22', end: '2019/9/23' },
  { count: 1, start: '2019/9/28', end: '2019/9/29' },
  { count: 1, start: '2019/10/2', end: '2019/10/3' },
  { count: 1, start: '2019/10/5', end: '2019/10/6' },
  { count: 1, start: '2019/10/28', end: '2019/10/29' },
  { count: 1, start: '2019/11/15', end: '2019/11/16' },
  { count: 1, start: '2019/11/20', end: '2019/11/21' },
  { count: 1, start: '2019/12/1', end: '2019/12/2' },
  { count: 1, start: '2019/12/15', end: '2019/12/16' },
  { count: 1, start: '2019/12/18', end: '2019/12/19' },
  { count: 1, start: '2019/12/27', end: '2019/12/28' },
  { count: 1, start: '2020/2/24', end: '2020/2/25' }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment