Last active
July 22, 2024 12:10
-
-
Save eweitz/1dd6bff11eab74a525c86454563703af to your computer and use it in GitHub Desktop.
Summarize recent changes in WikiPathways
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This JavaScript code helps summarize recent changes for WikiPathways | |
// See output at e.g. https://github.com/wikipathways/wikipathways-help/discussions/124 | |
// | |
// To run: | |
// - Go to https://classic.wikipathways.org/index.php?title=Special:RecentPathwayChanges&limit=500&offset=0 | |
// - Open Developer Tools in your web browser | |
// - Update the `dates` array below | |
// - Execute code, e.g. by putting cursor at end of last line and pressing Return / Enter | |
// | |
// The output can be pasted into the "Recent changes" section for new Weekly Review Report entries | |
// | |
// Cavaet: The RecentPathwayChanges page seems to only show up to < 600 changes. | |
dates = ['14 July', '15 July', '16 July', '17 July', '18 July', '19 July', '20 July'] | |
// Get all edit summaries ("edits") in "Recent Pathway Changes" page | |
allEdits = Array.from(document.querySelectorAll('ol.special > li')).map(edit => edit.textContent.replace(/[\u200E]/g, '')) | |
// Filter all edits to only those that occurred during dates of interest | |
edits = allEdits.filter(edit => dates.find(date => edit.includes(`: ${date}`))) | |
// Get edit counts by organism, author, and description | |
by = {organism: {}, author: {}, description: {}} | |
authorAndDescriptionRegEx = /: \d+ \w+ \d+ by (\w+) \((.*)\)/; | |
edits.forEach((edit) => { | |
organism = edit.split(':')[0].split('. . ')[1]; | |
(organism in by.organism) ? by.organism[organism]++ : by.organism[organism] = 1 | |
const [_, author, description] = edit.match(authorAndDescriptionRegEx); | |
(author in by.author) ? by.author[author]++ : by.author[author] = 1; | |
(description in by.description) ? by.description[description]++ : by.description[description] = 1; | |
}) | |
// Summarize top entries in each dimension | |
summary = []; | |
['organism', 'author', 'description'].forEach(key => { | |
max = 10 | |
sortedBy = Object.entries(by[key]).sort((a, b) => b[1] - a[1]) | |
lines = sortedBy.slice(0, max).map(e => `* ${e[0]}: ${e[1]}\n`) | |
if (sortedBy.length > max) { | |
lines.push(`* *Others: ${sortedBy.length - max}*`) | |
} | |
summary.push(`\n**By ${key}**\n`) | |
summary = summary.concat(lines) | |
}) | |
console.log.apply(null, summary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment