-
-
Save livibetter/5733726 to your computer and use it in GitHub Desktop.
ASCII 'punchcard' graph for git log or list of Unix timestamp
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
#!/usr/bin/awk -f | |
# | |
# punchcard.awk - ASCII 'punchcard' graph for git log or list of Unix timestamp | |
# | |
# Written in September 2011 by Andreas Jaggi <[email protected]> | |
# https://gist.github.com/x-way/1225770 | |
# | |
# Modified by Yu-Jie Lin | |
# https://gist.github.com/livibetter/5733726 | |
# | |
# usage:$ git log | punchcard.awk | |
# +------------------------------------------------------------------------+ | |
# Mon | . . . . . . . . o O O . . o 0 | | |
# Tue | . . o . . o O O 0 O | | |
# Wed | . . . . 0 O o | | |
# Thu | . . o O . . o o . . . | | |
# Fri | . . . . O o o | | |
# Sat | . . O . | | |
# Sun | . O o . o o o o o . . | | |
# +------------------------------------------------------------------------+ | |
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
# | |
BEGIN { | |
PROCINFO["sorted_in"] = "@ind_num_asc"; | |
split("Mon Tue Wed Thu Fri Sat Sun",days," "); | |
# having extra "0" for max/max case | |
split(" .oO00",chrs,""); | |
l_chrs = length(chrs)-1; | |
for (d in days) { | |
for ( h = 0; h < 24; h++ ) { | |
data[days[d],h] = 0; | |
} | |
} | |
max = 0; | |
} | |
/^(Date:|#?[0-9]+$)/{ | |
if ($0 ~ "Date") { | |
split($5,m,":"); | |
} else { | |
ts = ($0 ~ "^#") ? substr($0, 2) : $0; | |
$2 = strftime("%a", ts); | |
m[1] = strftime("%H", ts); | |
} | |
data[$2,(1*m[1])] = data[$2,(1*m[1])]+1; | |
if ( data[$2,(1*m[1])] > max ) { | |
max = data[$2,(1*m[1])]; | |
} | |
} | |
END { | |
print gensub(/0/, "-", "g", sprintf("%5s%0*d+", "+", 24*3, "")) | |
# ensure no division by zero | |
max = max ? max : 1; | |
for (d in days) { | |
printf("%s |", days[d]); | |
for ( h = 0; h < 24; h++ ) { | |
i = int(l_chrs*data[days[d],h]/max); | |
printf(" %s ", chrs[i+1]); | |
} | |
printf("|\n") | |
} | |
print gensub(/0/, "-", "g", sprintf("%5s%0*d+", "+", 24*3, "")) | |
printf(" "); | |
for ( h = 0; h < 24; h++ ) { | |
printf("%3d", h); | |
} | |
printf("\n"); | |
} |
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
The MIT License (MIT) | |
Copyright (c) 2013 Yu-Jie Lin | |
Copyright (c) 2011 Andreas Jaggi <[email protected]> | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My blog post about this: https://yjlv.blogspot.com/2013/06/punchcardawk-for-ascii.html