Arithmetic error or function setup incorrectly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear Fedora users,

I have a question regarding a set of data and an awk script that performs some actions, it calculates a GF(goals in favor) GA(goals against), and PTS for each game.  Suppose the data is as follows:

Soccer.dat
Team. GF GA 
Team1 1 2
Team2 1 1.2
Team3 2 4
Team4 3 0
Team5 4 0
Team6 3 2
Team7 1 3
Team8 2.01 2.03
Team9 3.03 3.04
Team10 0 7
Team11 0.1 0.3 

In district play, if a team wins in regulation they earn 3 pts, if you lose 0 pts, if both teams tie in regulation, they play overtime, if they are still tied then penalty kicks decide the outcome of the game.  The winners in OT/PKS get 2 pts, the loser get 1 pt.  

In Team2 we tied at 1 in regulation, but in OT, the other team scored 2 goals and beat us 3 to 1.  The awk script attached inline calculates this, but outputs 1 2 when it should output 1 3.  If there is another number in the hundredths place is we shot penalty kicks.  I cannot copy the awk script.  I will have to attach it.  I would like to improve it by tallying a running total per column of GF GA PTS .  Ideas are appreciated.  

The awk script creates a new integer from the decimal number given.  The integer part and the fractional part are used to create the new numbers that end up in GF and GA.  

In one case when I put 1 1.2 the output should be 1 3 but it gives me 1 2.  This is one of my questions.  On the other hand if I put 0.1 and 0.3 it outputs 1 to 3 correctly.  Do I have a mistake in my function?  I use int($1) to get integer part and ($1-int($1)) to get fractional part.  


Best Regards,


Antonio
#!bin/sh

# Check for arguments
if [ $# -eq 0 ]; then
    echo "Usage: $(basename $0) filename"
    exit 1
fi

if [ ! -f $1 ]; then
    echo "File "$1" doesn't exist!"
    exit 0
fi

awk '

NR == 1 {
      f[1]=-14; f[2] = f[3] = f[4] = f[5] = 3
        printf "%-14s %-3s %-3s %-3s %-3s\n",
        "OPPONENT", "GF", "GA", "DIF", "PTS"
}

NR >= 1 {
F=$2+10*($2-int($2))-($2-int($2));
A=$3+10*($3-int($3))-($3-int($3));
tdif=F-A;
dif=$2-$3
difb=int($2)-int($3);
if (dif >= 1 && int(dif) >= 1) 
    pts=3;
else if (dif > 0 && int(difb) >= 0)
    pts=2;
else if (dif > -1 && int(difb) >= -1)
    pts=1;
else 
    pts=0;  
        printf "%-14s %-3d %-3d %-3d %-3d \n",
        $1, F, A, tdif, pts }' $1
_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux