Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!ucbvax!tut.cis.ohio-state.edu!cica!iuvax!sahayman
From: sahayman@iuvax.cs.indiana.edu (Steve Hayman)
Newsgroups: alt.sources
Subject: A shell script to measure your typing speed
Message-ID: <26670@iuvax.cs.indiana.edu>
Date: 27 Sep 89 04:00:30 GMT
Distribution: alt
Organization: Computer Science Department, Indiana University
Lines: 215

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh 'README' <<'END_OF_FILE'
XHere is a mindless script to take a stab at measuring your typing
Xspeed.  It runs /usr/games/fortune to come up with a paragraph or so of
Xmeaningful text and displays that; you type it, you hit return twice to
Xindicate that you're done and the script tries to figure out your
Xtyping speed.
X
XI took one typing class in the tenth grade many years ago, so I might
Xhave forgotten the exact rules for measuring typing speed, but I seem
Xto recall that it's something like
X
X	- five characters (including spaces) equals a word
X	- ten words off for every error
X
XIf this is wrong, someone please tell me and I'll fix the script.
X
XI like running this when I'm bored.  It isn't exactly scientific but I
Xfind it fun, especially when I manage to get an absurdly high score on
Xa short fortune.  My best so far is about 120 wpm.
X
XNo Makefile - it's just a shell script.  "chmod +x type" and run it.
XI hope it's portable enough.  It works on Ultrix 3.0 here and I made
Xa token effort to avoid anything non-portable.  Let me know if
Xyou find something that needs to be fixed.
X
XSteve Hayman
Xsahayman@iuvax.cs.indiana.edu
XTue Sep 26 22:55:19 EST 1989
END_OF_FILE
if test 1131 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'type' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'type'\"
else
echo shar: Extracting \"'type'\" \(3838 characters\)
sed "s/^X//" >'type' <<'END_OF_FILE'
X#!/bin/sh
X# typing test
X# usage:
X#	type [-f input-file]
X#	type [fortune options]
X# or just
X#	type
X#
X# Displays the input file (or creates one via "fortune"), asks you to type it,
X# times you and attempts to count errors and compute a words-per-minute score.
X#
X# Assumptions: 5 chars is a word, 10 WPM penalty for error.
X# Whitespace is ignored when computing the score (well, there
X# must be some whitespace between the words) so you can
X# break lines wherever you want.   You can also use the normal line-editing
X# characters.
X#
X# TODO:
X#   Show you exactly what your errors are.
X#   -- maybe use "patch" to apply the diff, but cleverly insert
X#      some highlighting?
X# 
X# Steve Hayman, Indiana U
X# sahayman@iuvax.cs.indiana.edu
X# 88/08/16
X
XPATH=/bin:/usr/bin:/usr/ucb export PATH
XUsage="${0}: Usage: $0 [-f input-file]  or $0 [fortune options]"
X
Xstmp=/tmp/t-s.$$
Xitmp=/tmp/t-i.$$
Xdiff=/tmp/t-d.$$
Xin=/tmp/t-in.$$
Xsource=/tmp/t-source.$$
Xtrap exit 1 2 3 15
Xtrap 'rm -f $in $itmp $stmp $source $diff' 0
X
X# A source of pithy sayings.
Xfortune=/usr/games/fortune
Xif test ! -f $fortune; then
X	echo "${0}: Cannot find $fortune - cannot generate examples."
X	echo "${0}: Try  $0 -f some-input-file"
X	exit 1
Xfi
X
Xchars_per_word=5
Xpenalty_per_error=10
X
X
X# Default is a fortune.
X
Xcase "$1" in
X"-f")	# Input file supplied.
X	shift
X	cat ${1?$Usage}
X	;;
X*)	
X	# Pick up a fortune.  Use the supplied command line options,
X	# so the user can choose short, long, obscene, whatever.
X	
X	$fortune ${1+"$@"}
X	;;
Xesac | sed '/^$/d' >$source		# No blank lines, please.
X
Xclear
Xcat $source
X
Xcat <&1 1>$in  or < or -, we're
X# only interested in the counts ( 1a2, 3,4c5,6, those things.)
X# We just count up the line numbers - that makes the basic
X# (and imperfect) assumption that there can be no more than one error per word.
X
Xtr -s ' \011' '\012' <$in >$itmp
Xtr -s ' \011' '\012' <$source >$stmp
Xdiff $itmp $stmp >$diff
Xeval ` sed -e '/^[<->]/d' -e 's/[adc]/ & /' <$diff | awk '
X	{
X		nleft = split( $1, left, "," )
X		nright = split ( $3, right, "," )
X		if ( nleft == 1 )
X			left[2] = left[1]
X		if ( nright == 1 )
X			right[2] = right[1]
X
X		if ( $2 == "a" )
X			missing += right[2] - right[1] + 1
X		else if ( $2 == "d" )
X			extra += left[2] - left[1] + 1
X		else if ( $2 == "c" )
X			wrong += right[2] - right[1] + 1
X	}
X	END {	
X		printf "missing=%d\n", missing
X		printf "extra=%d\n", extra
X		printf "wrong=%d\n", wrong
X		printf "total=%d\n", missing + extra + wrong
X	}
X	' `
Xecho "Missing: $missing   Extra: $extra  Wrong: $wrong  Total errors: $total"
X
X
Xawpm=` echo "scale=2; ($words - ($total * $penalty_per_error)) * 60 / $seconds" | bc`
X
X
Xecho "Adjusted WPM: $awpm"
END_OF_FILE
echo shar: 2 control characters may be missing from \"'type'\"
if test 3838 -ne `wc -c <'type'`; then
    echo shar: \"'type'\" unpacked with wrong size!
fi
chmod +x 'type'
# end of 'type'
fi
echo shar: End of shell archive.
exit 0