On Sunday, December 3, 2017, 9:48:17 PM CST, Jon LaBadie <jonfu@jgcomp.com> wrote:


Antonio,

Do you have control over the contents (format) of the data?
Here that would be "Soccer.dat".

If yes I'd suggest a format change.  Separate the goals with
dashes (-) or commas (,) or whatever, just no something that
makes you think of them as numbers but as strings to be
converted to numbers later.

Assuming you used dashes teams 2 and 8 would be:

    Team2 1 1-2
    Team8 2-0-1 2-0-3

Your code could then use split(...) to put the goal counts into
an array.  For example.

    split($2, GF, "-")
    split($3, GA, "-")

You would now have two arrays GF (Goals For) with up to 3 elements.
The first would be regulation, second overtime, third penalty kicks.
And of course the same for GA.

This would also eliminate a potential, but very rare problem,
Some team scores 10 goals in overtime.  Your scheme would make
it look like 1 goal and 0 penalty kicks.

Jon

On Sun, Dec 03, 2017 at 12:46:16PM +0000, Antonio Olivares wrote:
> 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@lists.fedoraproject.org
> To unsubscribe send an email to users-leave@lists.fedoraproject.org

>>> End of included message <<<

--
Jon H. LaBadie                  jonfu@jgcomp.com


Dear Sir,

I do have control of the data.  I just wanted to have a solution running from a shell script.  I have an opendocument(*.odt) and excel spreadsheet that uses the decimal point and converts the decimal numbers to goals except in the hundredths place which is when we have to shoot penalty kicks(PK) to decide the game, but this is for my fellow coaches, they have to manually input the scores and put a * at the score indicating OT, PKS etc.  Some may not understand it :( 

My questing regarding the data is that in one case, I had in Team2
Team2 1.0 1.2 
which should give 1 3 but it output 1 2 :(
I had to change to 0.1 and 0.3 and it correctly put the goals at 1 3 and awarded 1 pt for going into OT. 

How do I fix the script to account for the new changes/examples?  At the end of the running the script should tally up the GF  and GA except in PKS those do not count in the DIF.  So my soccer.dat would become as follows:

Soccer.dat
-------------------------------
@Team1 1 2
Team2 1-0 1-2
Team3 2 4
Team4 3 0
@Team5 4 0
Team1 3 1
@Team2 1 3
@Team3 4 3
@Team4 3-0 3-1
Team5 3 0

At the end of each line, the GF and GA will be adjusted and at the very end of the data, the script should report a running total of all GF and all GA and the PTS. 

Thank you very much for your help!


Best Regards,


Antonio