56 lines
1.5 KiB
Plaintext
56 lines
1.5 KiB
Plaintext
function ties(sequence scores)
|
|
sequence t = {}, -- {start,num} pairs
|
|
tdx = repeat(0,length(scores))
|
|
integer last = -1
|
|
for i=1 to length(scores) do
|
|
integer this = scores[i][1]
|
|
if this=last then
|
|
t[$][2] += 1
|
|
else
|
|
t = append(t,{i,1})
|
|
end if
|
|
tdx[i] = length(t)
|
|
last = this
|
|
end for
|
|
-- eg {{{1,1},{2,2},{4,3},{7,1}},
|
|
-- {1,2,2,3,3,3,4}}
|
|
return {t,tdx}
|
|
end function
|
|
|
|
enum STANDARD, -- eg {1,2,2,4,4,4,7}
|
|
MODIFIED, -- eg {1,3,3,6,6,6,7}
|
|
DENSE, -- (==tdx)
|
|
ORDINAL, -- eg {1,2,3,4,5,6,7}
|
|
FRACTION, -- {1,2.5,2.5,5,5,5,7}
|
|
METHODS = $
|
|
|
|
function rank(integer i, method, sequence t, tdx)
|
|
integer idx = tdx[i],
|
|
{tx,tn} = t[idx]
|
|
switch method
|
|
case STANDARD: return tx
|
|
case MODIFIED: return tx+tn-1
|
|
case DENSE : return idx
|
|
case ORDINAL : return i
|
|
case FRACTION: return tx+(tn-1)/2
|
|
end switch
|
|
end function
|
|
|
|
constant scores = {{44, "Solomon"},
|
|
{42, "Jason"},
|
|
{42, "Errol"},
|
|
{41, "Garry"},
|
|
{41, "Bernard"},
|
|
{41, "Barry"},
|
|
{39, "Stephen"}}
|
|
|
|
sequence {t,tdx} = ties(scores)
|
|
printf(1," score name standard modified dense ordinal fractional\n")
|
|
for i=1 to length(scores) do
|
|
sequence ranks = repeat(0,METHODS)
|
|
for method=1 to METHODS do
|
|
ranks[method] = rank(i,method,t,tdx)
|
|
end for
|
|
printf(1,"%5d %-7s %6g %8g %6g %6g %9g\n",scores[i]&ranks)
|
|
end for
|