UltronoArena TV
https://ultronoarena.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.0 KiB
150 lines
3.0 KiB
#!/usr/bin/awk |
|
# provide summary and sorting for awk_extract |
|
|
|
BEGIN { |
|
RS="\n\n+" # set multiline records |
|
gc=0 # set game count |
|
|
|
# awk_extract generates 42 fields |
|
# awk_total receives 2 additional prefacing fields |
|
tf=44 # total number of fields |
|
i=15 # initial field player 1 |
|
j=30 # initial field player 2 |
|
} |
|
|
|
# ignore incomplete records |
|
NF==tf { |
|
# the complete array |
|
com[NR]=$0"\n" |
|
gc++ |
|
|
|
# remove % |
|
{ gsub(/%/,"") } |
|
|
|
# the points arrays; each field generated by awk_extract |
|
for (k=0; k<(j-i); k++) |
|
pnt[NR,k]=$(i+k)+$(j+k) |
|
|
|
# add score differential; stored as point array 1 |
|
abs=$i-$j |
|
pnt[NR,1]=abs < 0 ? -abs: abs |
|
|
|
# creating victory margin array |
|
if (pnt[NR,1]>3) vm[4]++ |
|
else vm[pnt[NR,1]]++ |
|
|
|
# the player name array |
|
pn[$(i+1)] |
|
pn[$(j+1)] |
|
for (k in pn) { |
|
# if player matches field |
|
# add to player point array |
|
# increment player game count array |
|
# maybe increment player win array |
|
if (k==$(i+1)) { |
|
pp[k]+=$i |
|
pgc[k]++ |
|
if ($i>$j) pw[k]++ |
|
} else if (k==$(j+1)) { |
|
pp[k]+=$j |
|
pgc[k]++ |
|
if ($i<$j) pw[k]++ |
|
} |
|
} |
|
} END { |
|
# if we have a game |
|
if (gc) { |
|
# for all players |
|
for (i in pn) { |
|
# zero empty player points and wins |
|
# set player winrate |
|
if (!pp[i]) pp[i]=0 |
|
if (!pw[i]) { |
|
pw[i]=0 |
|
pwr[i]=0 |
|
} else pwr[i]=100*(pw[i]/pgc[i]) |
|
|
|
# print points, wins, winrate |
|
printf "%s\n",i |
|
printf "%s\t","points:" |
|
printf "%-*s",11,pp[i] |
|
printf "%s\t","wins:" |
|
printf "%s\t",pw[i] |
|
printf "%-s","winrate: %" |
|
printf "%3.0f\t\n\n",pwr[i] |
|
} |
|
|
|
# zero empty victory margins |
|
for (i=0;i<5;i++) |
|
!vm[i] && vm[i]=0 |
|
|
|
# victory margin column headers |
|
printf "%-*s",9,"" |
|
printf "%*s",6,"zero" |
|
printf "%*s",6,"one" |
|
printf "%*s",6,"two" |
|
printf "%*s",6,"three" |
|
printf "%*s\n",6,"four+" |
|
|
|
# print victory margins and game count |
|
printf "%-*s",9,"margins:" |
|
for (i=0;i<5;i++) |
|
printf "%*s",6,vm[i] |
|
printf "\n" |
|
printf "%-*s",9,"games:" |
|
printf "%*s\n",6,gc |
|
printf "\n" |
|
|
|
# sort and print according to what? |
|
# each field generated by awk_extract has been summed into a points array |
|
# send a field to the insertion sort function |
|
# always print the complete array |
|
|
|
# if sorting by points differential, forward print |
|
# else if some other sort, reverse print |
|
# else forward print |
|
|
|
if (s==1) { |
|
isort(s) |
|
fprint() |
|
} else if (s) { |
|
# points total is points array 0 |
|
s ~ /pt/ && s=0 |
|
isort(s) |
|
rprint() |
|
} else fprint() |
|
} |
|
|
|
} |
|
#reverse print |
|
function rprint (i) { |
|
for(i=NR;i>=0;i--) |
|
if (com[i]) |
|
print com[i] |
|
} |
|
#forward print |
|
function fprint (i) { |
|
for (i=0;i<=NR;i++) |
|
if (com[i]) |
|
print com[i] |
|
} |
|
|
|
# isort of one points array reorders the complete array |
|
function isort(s, i, j, hold0, hold1) { |
|
# for each record |
|
for (i=0;i<=NR;i++) { |
|
# hold both arrays at current record |
|
hold0 = pnt[j=i,s] |
|
hold1 = com[j=i] |
|
# while point array at previous record is greater than its hold |
|
while ( pnt[j-1,s] > hold0 ) { |
|
# set next record of both arrays |
|
j-- |
|
pnt[j+1,s]=pnt[j,s] |
|
com[j+1]=com[j] |
|
} |
|
# reset holds |
|
pnt[j,s] = hold0 |
|
com[j] = hold1 |
|
} |
|
}
|
|
|