Skip to content

Instantly share code, notes, and snippets.

@icoloma
Last active September 16, 2018 08:29
Show Gist options
  • Save icoloma/7d9f45ccbda162ebf418354c2d7a09ab to your computer and use it in GitHub Desktop.
Save icoloma/7d9f45ccbda162ebf418354c2d7a09ab to your computer and use it in GitHub Desktop.
Snippets around the agenda for Commit Conf
// extract all author names
const authorNames = new Set();
agenda.days.forEach(
d => d.tracks.forEach(
t => t.slots.forEach(
s => {
if (s.contents && s.contents.authors) {
s.contents.authors.forEach(({name}) => authorNames.add(name))
}
}
)
)
)
// sort randomly
// see https://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array
function shuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
const randomlySorted = shuffle(Array.from(authorNames));
// copy to the clipboard
copy(randomlySorted);
// transform agenda into a listo of talk descriptions
var slots = [];
agenda.days.forEach(
d => d.tracks.forEach(
t => t.slots.forEach(
s => {
if (s.contents && s.contents.description) {
slots.push(s.contents);
}
}
)
)
)
// normalize by penalizing talks with few votes (add a rating of 1 to all talks)
function normalize(feedback) {
if (!feedback) return 0;
return (feedback.ratingAverage * feedback.entriesCount + 1) / (feedback.entriesCount + 1)
}
// sort talks by a criteria
slots.sort((s1, s2) => {
var f1 = normalize(s1.feedback);
var f2 = normalize(s2.feedback);
return f1 - f2
})
// print stuff
var output = 'Average,Entries,Title,Twitter Handle\n';
slots.forEach((s) => {
var f = s.feedback? s.feedback : { entriesCount: 0, ratingAverage: 0 };
var handles = s.authors.map(({ twitterAccount }) => twitterAccount);
output += `${normalize(s.feedback)}, ${f.entriesCount}, "${s.title.replace(/"/g, '\\"')}", ${handles.join(',')}\n`
})
console.log(output);
/*
Not yet supported
await navigator.clipboard.writeText(output)
console.log("CSV copied to clipboard")
*/
console.log(talks.map(({ authors }) => authors.filter(({ twitterAccount }) => !!twitterAccount).map(({ twitterAccount }) => `${twitterAccount}\n` ).join('')).join(''))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment