Skip to content

Instantly share code, notes, and snippets.

@secretGeek
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save secretGeek/35734a2cd5e4ac4f7be8 to your computer and use it in GitHub Desktop.
Save secretGeek/35734a2cd5e4ac4f7be8 to your computer and use it in GitHub Desktop.
progress.ps1 (assumes commits are handled by count.ps1) give details about daily word and task counts, and show today's progress as a percent of goal.
# draw a bar (in the console) of a given size, n
function bar($n) {
$co = "green";
if ($n -lt 100) {
$co = "red"; #less than 100%: is RED
} elseif ($n -ge 500) {
$co = "blue"; #greater than 500% is Blue
}
1..([system.math]::min(50,$n/10)) | % { barbit($co);}
}
# writes a part of a bar graph (a bar-bit) in a given color
function barbit($cc) {
#todo... not always red
write-host " " -backgroundcolor $cc -nonewline
}
$target = 200;
write-host ("Daily target: " + $target + " words.") -foregroundcolor white
$hashy = @{}
$current = $null
$previous = $null
$num = 0;
$previous2 = ",:26541";
hg log --template "{date|shortdate},{desc}\n" | % {
$date = $_.split(',')[0]
if ($hashy[$date] -eq $null) {
$hashy[$date] = $_
$num = $num + 1;
$current2 = $previous2;
$previous2 = $_;
if ($current -eq $null) {
$current = $_;
} elseif ($previous -eq $null) {
$previous = $_;
}
if ($num -le 25) {
# only print the last 25 days.
#$_;
$currentWords2 = $current2.split(',')[1].split(':')[1]
$previousWords2 = $previous2.split(',')[1].split(':')[1]
$progress2 = (($currentWords2 - $previousWords2) / $target) * 100
if ($current2 -ne ",:26541") {
bar($progress2);
write-host (" " + $progress2 + "%");
}
#write-host (" " + $progress2 + " ") -nonewline;
write-host ($_ + " ") -nonewline;
}
}
}
write-host ""
$currentWords = $current.split(',')[1].split(':')[1]
$previousWords = $previous.split(',')[1].split(':')[1]
$currentTasks = $current.split(',')[2].split(':')[1].split('/')[0]
$previousTasks = $previous.split(',')[2].split(':')[1].split('/')[0]
# Goal Today... 200 ??
$progress = (($currentWords - $previousWords) / $target) * 100
$result = "" + ($currentWords - $previousWords) + " words today (" + ($progress) + "%), " + ($currentTasks - $previousTasks) + " tasks today"
$col = "white"
if ($progress -ge 100) {
$col = "green";
} elseif ($progress -le 10) {
$col = "red";
}
write-host $result -foregroundcolor $col
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment