Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save elenst/bad49219ebb3dd90a9d0f2b91fa36b03 to your computer and use it in GitHub Desktop.
Save elenst/bad49219ebb3dd90a9d0f2b91fa36b03 to your computer and use it in GitHub Desktop.
fuzzy_formula='
rounded = 0;
if (fuzzy_var <= 10 ) {
rounded = 1;
}
factor = 1;
while ( rounded == 0 ) {
if ( fuzzy_var <= 50 * factor ) {
fuzzy_var = sprintf("%.0f", fuzzy_var / (5 * factor)) * 5 * factor;
rounded = 1;
}
else if ( fuzzy_var <= 100 * factor) {
fuzzy_var = sprintf("%.0f", fuzzy_var / (10 * factor)) * 10 * factor;
rounded = 1;
}
else if ( fuzzy_var <= 250 * factor) {
fuzzy_var = sprintf("%.0f", fuzzy_var / (25 * factor)) * 25 * factor;
rounded = 1;
}
factor = factor * 10;
}'
.....
cut -c1-80 "$file" \
| awk "
\$1 == \"${param}:\" {
p = substr(\$0, index(\$0, \":\") + 2);
if ( index(p, \":\") > 0 ) {
p = substr(p, 1, index(p, \":\") - 1);
}
if ( length(p) > 30 ) {
p = substr(p, 1, 30);
}
}
\$1 == \"Time:\" {
t = \$2;
}
\$1 == \"Command:\" {
c = \$2;
}
\$1 == \"Info:\" {
count[p]++;
if ( c == \"Sleep\" ) {
sleep[p]++;
}
if ( \"${param}\" == \"Command\" || c != \"Sleep\" ) {
time[p] += t;
if ( t > mtime[p] ) { mtime[p] = t; }
}
}
END {
for ( p in count ) {
fuzzy_var=count[p]-sleep[p]; ${fuzzy_formula} fuzzy_work=fuzzy_var;
fuzzy_var=count[p]; ${fuzzy_formula} fuzzy_count=fuzzy_var;
fuzzy_var=time[p]; ${fuzzy_formula} fuzzy_time=fuzzy_var;
fuzzy_var=mtime[p]; ${fuzzy_formula} fuzzy_mtime=fuzzy_var;
printf \" %-30s %8d %7d %9d %9d\n\", p, fuzzy_count, fuzzy_work, fuzzy_time, fuzzy_mtime;
}
}
" | sort
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment