Skip to content

Instantly share code, notes, and snippets.

@cmdcolin
Last active March 18, 2024 20:47
Show Gist options
  • Save cmdcolin/578f2973524c8e6da8476811b2759d0b to your computer and use it in GitHub Desktop.
Save cmdcolin/578f2973524c8e6da8476811b2759d0b to your computer and use it in GitHub Desktop.
plot lines of code over time from a git repository
#!/usr/bin/env bash
## uses home directory to avoid git clean in repo clearing files
touch ~/lines
## choice 1. for all commits
git log --pretty=format:'%h %as'|sed 's/ /\t/' >! ~/commitlog
## choice 2. for all tags
git for-each-ref --sort=creatordate --format '%(refname) %(creatordate:short)' refs/tags|sed -e 's/refs\/tags\///'|sed 's/ /\t/' >! ~/commitlog
## note: don't have any unsaved work in your repo, this does a HARD clean of all gitignored files, everything, at each iteration
cut -f1 ~/commitlog | while read p; do
echo $p; git checkout $p;
git clean -fdx;
tokei --output json | jq --raw-output '[.TSX.code, .TypeScript.code, .JavaScript.code] | @tsv' >> ~/lines;
done
paste ~/lines ~/commitlog > ~/table.tsv
Rscript ~/plot.R
#!/usr/bin/env Rscript
library(reshape2)
library(ggplot2)
library(lubridate)
library(dplyr)
x <- read.table("table.tsv", sep = "\t")
colnames(x) <- c("ts", "tsx", "js", "commit", "date")
# https://stackoverflow.com/a/61723672/2129219 replace NA with 0
x <- x %>% replace(is.na(.), 0)
x$total <- x$js + x$ts + x$tsx
x$date <- ymd(x$date)
y <- melt(x, id = c("date", "commit"))
ggplot(y, aes(x = date, y = value, group = variable)) +
geom_line(aes(color = variable)) +
ggtitle("Lines of code in JBrowse 2")
ggsave("out.png", width = 15, height = 8)
@cmdcolin
Copy link
Author

example output for jbrowse-components repo

out

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