Last active
October 2, 2021 13:29
-
-
Save oganm/2157e8312f299456ffeb731371949f4f to your computer and use it in GitHub Desktop.
a punchcard of git commits for a given repo
This file contains hidden or 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 is to get data from a single git repository | |
library(dplyr) | |
library(anytime) | |
library(patchwork) | |
library(ggplot2) | |
commits = git2r::commits() | |
commitTime= commits %>% sapply(function(x){x$author$when$time}) %>% anytime | |
days = commitTime %>% weekdays.POSIXt() | |
hours = as.POSIXlt(commitTime)$hour | |
time = data.frame(days = factor(days, levels = c('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')), hours = hours) | |
time %>% group_by(days,hours) %>% summarise(Commits = n()) %>% | |
ggplot(aes(x = days,y = hours,size = Commits)) + geom_point() + | |
theme(axis.text.x = element_text(angle = 90,vjust = 0.5,hjust = 1 ), | |
plot.margin = unit(c(0,0,0,0),'cm')) + | |
xlab('') + | |
ylab('Hour of Day') -> plot1 | |
time %>% group_by(days) %>% summarise(Commits = n()) %>% | |
ggplot(aes(x = days,y = Commits)) + geom_bar(stat ='identity') + | |
theme(axis.text.x = element_blank(), | |
axis.ticks.x = element_blank(), | |
plot.margin = unit(c(0,0,0,0),'cm'))+ | |
xlab('') + ggtitle('Time of commit') -> plot2 | |
plot2/plot1 + plot_layout(ncol = 1, heights = c(3,5)) |
This file contains hidden or 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 compiles data from multiple github repositories and plots a punchcard | |
# note that you can't run this code without replacing the repos list with your own | |
# repositories since it includes private repos accessed through my github token | |
library(dplyr) | |
library(anytime) | |
library(patchwork) | |
library(ggplot2) | |
library(cowplot) | |
library(plotly) | |
library(gh) | |
library(glue) | |
library(git2r) | |
library(wesanderson) | |
repos = list( | |
hobby = c('oganm/import5eChar', | |
'oganm/wizaRd', | |
'oganm/monsteR', | |
'oganm/dndstats', | |
'oganm/dnddata', | |
'oganm/printSheetApp', | |
'oganm/5eInteractiveSheet', | |
'oganm/diceSyntax', | |
'oganm/initTrack', | |
'oganm/house_of_rogan', | |
'oganm/shinyServerAutomation', | |
'oganm/serverAPI', | |
'oganm/RainCheck-pi', | |
'oganm/callMePi', | |
'oganm/pointMoveTrial', | |
'oganm/upassRenew', | |
'oganm/stockfisher', | |
'pridiltal/staplr', | |
'thebombzen/grimoire', | |
'oganm/mybrain', | |
'oganm/oganm.com', | |
'oganm/getTrove', | |
'oganm/swarm'), | |
contracts = c('daattali/sub-C1010-ggplotdata2', | |
'daattali/sub-C1029-miled-report', | |
'oganm/C1014-Neon', | |
'oganm/dean-xls2plot4sportsguy', | |
'oganm/dean-bootlegConferenceGuy'), | |
work = c('PavlidisLab/neuroexpresso', | |
'PavlidisLab/neuroExpressoAnalysis', | |
'PavlidisLab/gemmaAPI.R', | |
'PavlidisLab/ermineR', | |
'PavlidisLab/gemmaMGP', | |
'PavlidisLab/neuroExpressoData', | |
'PavlidisLab/markerGeneProfile', | |
'oganm/neuroseq_fiddling', | |
'oganm/allenBrain', | |
'oganm/MsigDB', | |
'oganm/homologene', | |
'oganm/cmapQuery', | |
'oganm/brainspriteR', | |
'oganm/masterOfCellTypes', | |
'oganm/Rotation-3', | |
'oganm/treeCorrect', | |
'oganm/brainCellTypeSpecificGenes', | |
'oganm/expVisTemplate', | |
'oganm/gemmaScripts', | |
'oganm/toSource', | |
'oganm/regenerationCMap', | |
'oganm/metaNeighborTrial', | |
'PavlidisLab/largeScaleMGP', | |
'hackseq/vasco', | |
'hackseq/tara-cyc-hs18', | |
'oganm/ontologyIndexOgfork', | |
'oganm/neuroexpressoAPI')) | |
# auth is a file with your github token in plain text | |
token = readLines('auth') | |
Sys.setenv(GITHUB_PAT = token) | |
cred = git2r::cred_token() | |
timeFrames = lapply(1:length(repos), function(i){ | |
reponames = repos[[i]] | |
time = data.frame(days = factor(c(),levels = c('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')), | |
hours = c(),source = c()) | |
for (reponame in reponames){ | |
print(reponame) | |
unlink('repo',recursive = TRUE) | |
clone(url = glue('https://github.com/{reponame}.git'),local_path = 'repo',credentials = cred) | |
repo = repository('repo') | |
commits = commits(repo) | |
commitTime= commits %>% sapply(function(x){x$author$when$time}) %>% anytime | |
committer = commits %>% sapply(function(x){x$author$email}) | |
commitTime = commitTime[committer %in% c('[email protected]','[email protected]')] | |
days = commitTime %>% weekdays.POSIXt() | |
hours = as.POSIXlt(commitTime)$hour | |
time = rbind(time, | |
data.frame(days = factor(days, levels = c('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday')), | |
hours = hours,source = names(repos)[i],repo = reponame, date = commitTime)) | |
} | |
return(time) | |
}) | |
time = do.call(rbind,timeFrames) | |
saveRDS(time,'time.rds') | |
palette = wes_palette('Darjeeling1') | |
time %>% ggplot(aes(x = date,fill = source)) + geom_histogram(bins = 10) | |
time %>% ggplot(aes(x = date,fill = source)) + geom_density(alpha = 0.5) | |
# to calcualte commits for day | |
# span = as.integer(max(time$date) - min(time$date))/7 | |
time %>% group_by(days,hours,source) %>% summarise(Commits = n()) %>% | |
ggplot(aes(x = days,y = hours,size = Commits,group = source,color= source)) + | |
geom_point(position = position_dodge(width = 0.5)) + | |
theme_cowplot() + | |
theme(axis.text.x = element_text(angle = 45,vjust = 1,hjust = 1 ), | |
plot.margin = unit(c(0,0,0,0),'cm'), | |
panel.grid.minor.y = element_line(color = 'gray',size = .2), | |
panel.grid.major.y = element_line(color = 'gray',size = .2) | |
) + | |
xlab('') + | |
scale_color_manual(values = palette) + | |
# viridis::scale_colour_viridis(discrete = TRUE) + | |
scale_y_continuous(minor_breaks = 0:24) + | |
ylab('Hour of Day') -> plot1 | |
time %>% group_by(days,source) %>% summarise(Commits = n()) %>% | |
ggplot(aes(x = days,y = Commits,fill = source)) + geom_bar(stat ='identity') + | |
theme_cowplot() + | |
theme(axis.text.x = element_blank(), | |
axis.ticks.x = element_blank(), | |
plot.margin = unit(c(0,0,0,0),'cm'))+ | |
scale_fill_manual(values = palette) + | |
guides(fill=FALSE) + | |
xlab('') + ggtitle("Commits to github") -> plot2 | |
p = plot2/plot1 + plot_layout(ncol = 1, heights = c(2,5)) | |
ggsave(p,filename = glue('combined.png'),height = 8,width = 8) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment